[GRASS-SVN] r56730 - grass/branches/develbranch_6/raster/r.li/r.li.daemon
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jun 16 03:39:55 PDT 2013
Author: hamish
Date: 2013-06-16 03:39:55 -0700 (Sun, 16 Jun 2013)
New Revision: 56730
Modified:
grass/branches/develbranch_6/raster/r.li/r.li.daemon/daemon.c
grass/branches/develbranch_6/raster/r.li/r.li.daemon/daemon.h
grass/branches/develbranch_6/raster/r.li/r.li.daemon/description.html
Log:
respect the WORKERS enviro var to control number of fork()s (#722)
Modified: grass/branches/develbranch_6/raster/r.li/r.li.daemon/daemon.c
===================================================================
--- grass/branches/develbranch_6/raster/r.li/r.li.daemon/daemon.c 2013-06-16 08:39:24 UTC (rev 56729)
+++ grass/branches/develbranch_6/raster/r.li/r.li.daemon/daemon.c 2013-06-16 10:39:55 UTC (rev 56730)
@@ -45,9 +45,17 @@
g_areas g;
int receiveChannel;
int res;
- wd child[WORKERS];
int i, mypid, doneDir, withoutJob, mv_fd, random_access;
+ int num_workers;
+ /* check if environment variable override was set */
+ const char *p = getenv("WORKERS");
+ num_workers = p ? atoi(p) : DEFAULT_WORKERS;
+ if ((num_workers <= 0) || (num_workers > 1e6))
+ G_fatal_error(_("Invalid number of workers: [%s]"), p);
+
+ wd child[num_workers];
+
/*int mv_rows, mv_cols; */
list l;
msg m, doneJob;
@@ -73,7 +81,7 @@
############################################### */
i = 0;
- while (i < WORKERS) {
+ while (i < num_workers) {
int childpid;
/*creating pipe */
@@ -126,7 +134,7 @@
if (parsed == MVWIN) {
/* struct Cell_head cellhd_r, cellhd_new;
char *mapset; */
- /*creating new raster file */
+ /* create new raster file */
mv_fd = G_open_raster_new(output, DCELL_TYPE);
if (mv_fd < 0)
G_fatal_error(_("Unable to create raster map <%s>"), output);
@@ -156,20 +164,20 @@
/*#######################################################
------------------analysis loop----------------------
####################################################### */
- /*first job scheduling */
- while ((i < WORKERS) && next_Area(parsed, l, g, &m) != 0) {
+ /* first job scheduling */
+ while ((i < num_workers) && next_Area(parsed, l, g, &m) != 0) {
send(child[i].channel, &m);
i++;
}
- /*body */
+ /* body */
while (next_Area(parsed, l, g, &m) != 0) {
int j = 0, donePid;
receive(receiveChannel, &doneJob);
- /*perc++; */
- /*G_percent (perc, WORKERS, 1); */
+ /* perc++; */
+ /* G_percent (perc, num_workers, 1); */
if (doneJob.type == DONE) {
double result;
@@ -180,7 +188,7 @@
print_Output(res, doneJob);
}
else {
- /*raster output */
+ /* raster output */
raster_Output(random_access, doneJob.f.f_d.aid, g,
doneJob.f.f_d.res);
}
@@ -191,19 +199,20 @@
error_Output(res, doneJob);
}
else {
- /*printf("todo ");fflush(stdout); *//* TODO scrivere su raster NULL ??? */
+ /* printf("todo"); fflush(stdout); */
+ /* TODO scrivere su raster NULL ??? */
}
}
j = 0;
- while (j < WORKERS && donePid != child[j].pid)
+ while (j < num_workers && donePid != child[j].pid)
j++;
send(child[j].channel, &m);
}
- /*kill childs */
+ /* kill childs */
withoutJob = i;
while (i > 0) {
int j = 0, donePid, status;
@@ -229,13 +238,14 @@
error_Output(res, doneJob);
}
else {
- /*printf("todo2 ");fflush(stdout); *//*TODO scrivere su raster */
+ /* printf("todo2 "); fflush(stdout); */
+ /* TODO scrivere su raster */
}
}
i--;
- while (j < WORKERS && donePid != child[j].pid)
+ while (j < num_workers && donePid != child[j].pid)
j++;
m.type = TERM;
@@ -258,7 +268,7 @@
}
/* kill children without Job */
- for (i = withoutJob; i < WORKERS; i++) {
+ for (i = withoutJob; i < num_workers; i++) {
int status;
m.type = TERM;
Modified: grass/branches/develbranch_6/raster/r.li/r.li.daemon/daemon.h
===================================================================
--- grass/branches/develbranch_6/raster/r.li/r.li.daemon/daemon.h 2013-06-16 08:39:24 UTC (rev 56729)
+++ grass/branches/develbranch_6/raster/r.li/r.li.daemon/daemon.h 2013-06-16 10:39:55 UTC (rev 56730)
@@ -24,7 +24,7 @@
/**
* \brief number of r.li.workers to use
*/
-#define WORKERS 10
+#define DEFAULT_WORKERS 10
#define NORMAL 1
#define MVWIN 2
#define GEN 3
Modified: grass/branches/develbranch_6/raster/r.li/r.li.daemon/description.html
===================================================================
--- grass/branches/develbranch_6/raster/r.li/r.li.daemon/description.html 2013-06-16 08:39:24 UTC (rev 56729)
+++ grass/branches/develbranch_6/raster/r.li/r.li.daemon/description.html 2013-06-16 10:39:55 UTC (rev 56730)
@@ -9,9 +9,12 @@
<img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade>
+
<H2>NAME</H2>
+
<EM><B>libgrass_rli</B></EM> - r.li landscape index support library
+
<H2>DESCRIPTION</H2>
<EM>r.li.daemon</EM> provides support for landscape index calculations on raster
@@ -56,7 +59,9 @@
</ol>
Compile it using a changed Makefile based on the file for <em>r.li.patchdensity</em>.
+
<H2>NOTES</H2>
+
Using GRASS library function to access raster rows can slow down moving windows
execution. It is recommended to use
<br><div class="code"><pre>
@@ -66,6 +71,9 @@
</pre></div><br>
to use an ad hoc build memory management developed to speed up the system.
The documentation is in doxygen files.
+<p>
+The <tt>WORKERS</tt> environment variable can be set to the number of
+concurrent processes desired. If not set, the default is 10 concurrent jobs.
<H2>SEE ALSO</H2>
@@ -75,7 +83,9 @@
<EM><A HREF="r.li.patchdensity.html">r.li.patchdensity</A></EM>,
<EM><A HREF="r.li.setup.html">r.li.setup</A></EM>
+
<H2>AUTHORS</H2>
+
Claudio Porta and Lucio Davide Spano, students of Computer Science
University of Pisa (Italy).<br>
Commission from Faunalia Pontedera (PI)<br>
@@ -87,6 +97,8 @@
<i>Last changed: $Date$</i>
<HR>
-<P><a href="index.html">Main index</a> - <a href="raster.html">raster index</a> - <a href="full_index.html">Full index</a>
+<P><a href="index.html">Main index</a>
+ - <a href="raster.html">raster index</a>
+ - <a href="full_index.html">Full index</a>
</body>
</html>
More information about the grass-commit
mailing list