[GRASS-SVN] r59298 - in grass-addons/grass6/raster: . r.patch.many

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 23 18:07:29 PDT 2014


Author: hamish
Date: 2014-03-23 18:07:29 -0700 (Sun, 23 Mar 2014)
New Revision: 59298

Added:
   grass-addons/grass6/raster/r.patch.many/
   grass-addons/grass6/raster/r.patch.many/Makefile
   grass-addons/grass6/raster/r.patch.many/description.html
   grass-addons/grass6/raster/r.patch.many/r.patch.many
Log:
script to run r.patch in parallel for cases of many input maps. the same approach could easily be used for 'r.series max=', etc.

Copied: grass-addons/grass6/raster/r.patch.many/Makefile (from rev 57519, grass-addons/grass6/raster/r.game_of_life/Makefile)
===================================================================
--- grass-addons/grass6/raster/r.patch.many/Makefile	                        (rev 0)
+++ grass-addons/grass6/raster/r.patch.many/Makefile	2014-03-24 01:07:29 UTC (rev 59298)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.patch.many
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Copied: grass-addons/grass6/raster/r.patch.many/description.html (from rev 57519, grass-addons/grass6/raster/r.surf.volcano/description.html)
===================================================================
--- grass-addons/grass6/raster/r.patch.many/description.html	                        (rev 0)
+++ grass-addons/grass6/raster/r.patch.many/description.html	2014-03-24 01:07:29 UTC (rev 59298)
@@ -0,0 +1,32 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.patch.many</em> works in the same way as <em>r.patch</em>, but
+it divides the input maps up into smaller groups to that the process
+can take advantage of multi-core CPUs. In a second pass it patches together
+the intermediate patch maps into the final output map.
+<p>
+It is useful for situations where the number of input maps is very large.
+
+<h2>NOTES</h2>
+
+Set the <b>workers</b> parameter to match the number of CPUs available.
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="g.mlist.html">g.mlist</a><br>
+<a href="r.patch.html">r.patch</a><br>
+<a href="r.series.html">r.series</a><br>
+</em>
+
+
+<h2>AUTHOR</h2>
+
+Hamish Bowman<br>
+<i>Geology Dept.<br>
+University of Otago<br>
+Dunedin, New Zealand</i>
+
+<p>
+<i>Last changed: $Date$</i>

Added: grass-addons/grass6/raster/r.patch.many/r.patch.many
===================================================================
--- grass-addons/grass6/raster/r.patch.many/r.patch.many	                        (rev 0)
+++ grass-addons/grass6/raster/r.patch.many/r.patch.many	2014-03-24 01:07:29 UTC (rev 59298)
@@ -0,0 +1,144 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       r.patch.many
+# AUTHOR(S):    Hamish Bowman, Dunedin, New Zealand
+# PURPOSE:      Parallelized version of r.patch. Output should be the same.
+#
+# COPYRIGHT:    (C) 2014 Hamish Bowman, and the GRASS Development Team
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+############################################################################
+
+#
+# Note: If regions are not overlapping you'll want to group nearby maps together.
+#       It would be easy to do the same for 'r.series max=' etc.
+# Todo: 'WIND_OVERRIDE + g.region zoom=(per core maps)' for each split
+#
+
+#%Module
+#% label: Creates a composite raster map by using known category values from many map layers to fill in areas of "no data" in another map layer.
+#% description: This script is a parallelized wrapper around r.patch.
+#% keywords: raster, geometry
+#%End
+#%Flag
+#% key: z
+#% description: Use zero (0) for transparency instead of NULL
+#%End
+#%Option
+#% key: input
+#% type: string
+#% required: yes
+#% multiple: yes
+#% key_desc: name
+#% description: Name of raster maps to be patched together
+#% gisprompt: old,cell,raster
+#%End
+#%Option
+#% key: output
+#% type: string
+#% required: yes
+#% multiple: no
+#% key_desc: name
+#% description: Name for resultant raster map
+#% gisprompt: new,cell,raster
+#%End
+#%Option
+#% key: workers
+#% type: integer
+#% multiple: no
+#% key_desc: value
+#% description: Number of parallel sessions
+#% options: 1-2048
+#% answer: 4
+#%End
+
+if [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+fi
+
+
+#### check if we have awk
+if [ ! -x "`which awk`" ] ; then
+    g.message -e "awk required, please install awk or gawk first"
+    exit 1
+fi
+
+#### check if we have seq
+if [ ! -x "`which seq`" ] ; then
+    g.message -e "seq required, please install it first"
+    exit 1
+fi
+
+#### trap ctrl-c so that we can clean up tmp
+cleanup()
+{
+   ALL_IN=`g.mlist type=rast pattern=tmp.rpatchmany.$$.[1-9]* sep=,`
+   g.mremove -f "$ALL_IN" --quiet
+}
+trap 'cleanup' 2 3 15
+
+
+
+# set environment so that awk works properly in all languages
+unset LC_ALL
+LC_NUMERIC=C
+export LC_NUMERIC
+
+
+IN="$GIS_OPT_INPUT"
+OUT="$GIS_OPT_OUTPUT"
+WORKERS="$GIS_OPT_WORKERS"
+
+if [ "$GIS_FLAG_Z" -eq 1 ] ; then
+   Z_FLAG="-z"
+else
+   Z_FLAG=""
+fi
+
+
+NUM_MAPS=`echo "$IN" | tr ',' '\n' | wc -l`
+
+MAPS_PER_CORE=`echo "$NUM_MAPS $WORKERS" | awk '
+   function ceil(val) {
+      return (val == int(val)) ? val : int(val)+1
+   }
+   {
+      print ceil($1 / $2)
+   }'`
+
+
+ALL_IN=""
+for CORE in `seq $WORKERS` ; do
+   LO=`echo "$CORE $MAPS_PER_CORE" | awk '{print 1 + ($1 -1) * $2}'`
+   HI=`echo "$CORE $MAPS_PER_CORE" | awk '{print $1 * $2}'`
+
+   MAPS=`echo "$IN" | tr ',' '\n' | head -n "$HI" | tail -n "$MAPS_PER_CORE" | tr '\n' ',' | sed -e 's/,$//'`
+   PATCH="tmp.rpatchmany.$$.$CORE"
+   ALL_IN="$ALL_IN,$PATCH"
+
+   r.patch $Z_FLAG input="$MAPS" output="$PATCH" &
+done
+wait
+
+
+### final patch
+ALL_IN=`echo $ALL_IN | sed -e 's/^,//'`
+r.patch $Z_FLAG input="$ALL_IN" output="$OUT"
+
+# remove temporary maps
+cleanup


Property changes on: grass-addons/grass6/raster/r.patch.many/r.patch.many
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-sh
Added: svn:eol-style
   + native



More information about the grass-commit mailing list