Hamish wrote:
Markus Metz wrote:
Actually I wanted to apply the changes of the r.watershed version in
grass-7 to r.watershed2, especially naming of options without points
and uppercase, but didn't get yet to it.

done.  ('svn merge' did 99% of the work after devbr6 was solved)
Change option names also for r.watershed.ram and r.watershed.seg? There are some options in uppercase.
see the man page for an example of making a nicely colored accum map
based on standard deviations.

if visual= is to be removed, that should only happen in grass 7.
Why not setting colors for accum in the module?
in my tests r.watershed(2) is >80 times faster than r.watershed(1). nice!
(35min -> 25sec for RAM mode to complete; new SEG mode took 4.5min)
all maps appear the same as old r.watershed.
The speed increase is not static, the new version will be faster the larger the region (more cells). For somewhat larger regions, the new module is >1000 times faster.
#spearfish
g.region rast=elevation.10m

time r.watershed -m mem=800 elev=elevation.10m threshold=3000 \
  accum=rw2_elev10m.acc \
  drain=rw2_elev10m.drain \
  basin=rw2_elev10m.basin \
  str=rw2_elev10m.stream \
  half.b=rw2_elev10m.halfb \
  vis=rw2_elev10m.viz \
  length.sl=rw2_elev10m.ls \
  slope.st=rw2_elev10m.sls



One thing with -m (seg mode).. without -m (ram mode) it takes 166mb RAM.
With -m it took just under what I set memory= to. If I set mem=950 it
used 911mb RAM. Does it not know it only needs ~166mb instead of full
alloc?
It should, but I made a mistake in adjusting the number of open segments. Please apply the diff attached.
Also, if I set -m memory=1200 the r.watershed.seg exits with an error (11):
[same elevation.10m which takes 166mb in RAM mode]
====
SECTION 1 beginning: Initiating Variables. 6 sections total.
D1/1: segs MB: 1200
D1/1: seg cols: 200
D1/1: seg rows: 200
D1/1:    row segments:  7
D1/1: column segments:  10
D1/1:  total segments:  70
D1/1:   open segments:  419
D1/1:   open segments after adjusting:  419
open segments after adjusting should be 70, fixed with diff.

SECTION 1b (of 6): Determining Offmap Flow.
 100%
 100%
WARNING: category information for [...] missing
[...]
====
G63> echo $?
11

top reported 1150mb allocated, and I have 2gb so plenty still to spare
and not Linux tearing down a runaway proc AFAICT..
so why the early exit?
That may be related to the number of open segments exceeding the number of existing segments. After the changes as in the diff I could not reproduce that error. Top now reports about 110 MB allocated for segmented mode, no matter what I specified with memory.

There was also another error in init_vars.c, no memory allocated to char *mb_opt which could cause a segfault, fixed with diff.

I wonder how many more bugs will surface after more testing...

Markus Metz

--- r.watershed2.orig/seg/init_vars.c	2008-11-29 11:45:15.000000000 +0100
+++ r.watershed2/seg/init_vars.c	2008-12-01 16:06:16.000000000 +0100
@@ -11,7 +11,6 @@
     int fd, num_cseg_total, num_open_segs;
     int seg_rows, seg_cols;
     double segs_mb;
-    char *mb_opt;
 
     /* int page_block, num_cseg; */
     int max_bytes;
@@ -30,6 +29,7 @@
     /* dep_slope = 0.0; */
     max_bytes = 0;
     sides = 8;
+    segs_mb = 300;
     for (r = 1; r < argc; r++) {
 	if (sscanf(argv[r], "el=%[^\n]", ele_name) == 1)
 	    ele_flag++;
@@ -61,11 +61,7 @@
 	    ls_flag++;
 	else if (sscanf(argv[r], "ob=%[^\n]", ob_name) == 1)
 	    ob_flag++;
-	else if (sscanf(argv[r], "mb=%[^\n]", mb_opt) == 1) {
-	    if (sscanf(mb_opt, "%lf", &segs_mb) == 0) {
-		segs_mb = 300;
-	    }
-	}
+	else if (sscanf(argv[r], "mb=%lf", &segs_mb) == 1) ;
 	else if (sscanf(argv[r], "r=%[^\n]", ril_name) == 1) {
 	    if (sscanf(ril_name, "%lf", &ril_value) == 0) {
 		ril_value = -1.0;
@@ -155,8 +151,10 @@
     num_open_segs = segs_mb / 2.86;
 
     G_debug(1, "segs MB: %.0f", segs_mb);
-    G_debug(1, "seg cols: %d", seg_cols);
+    G_debug(1, "region rows: %d", nrows);
     G_debug(1, "seg rows: %d", seg_rows);
+    G_debug(1, "region cols: %d", ncols);
+    G_debug(1, "seg cols: %d", seg_cols);
 
     num_cseg_total = nrows / SROW + 1;
     G_debug(1, "   row segments:\t%d", num_cseg_total);
@@ -169,8 +167,8 @@
     G_debug(1, "  open segments:\t%d", num_open_segs);
 
     /* nonsense to have more segments open than exist */
-    if (num_open_segs > nrows)
-	num_open_segs = nrows;
+    if (num_open_segs > num_cseg_total)
+	num_open_segs = num_cseg_total;
     G_debug(1, "  open segments after adjusting:\t%d", num_open_segs);
 
     cseg_open(&alt, seg_rows, seg_cols, num_open_segs);
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to