[GRASS-dev] GRASS_BATCH_JOB and GISRCRC

Glynn Clements glynn at gclements.plus.com
Wed Aug 27 13:48:28 EDT 2008


Markus Neteler wrote:

> I would like to submit the following change to facilitate the use
> of GRASS on clusters/in parallel jobs:
> 
> 
> Index: lib/init/init.sh
> ===================================================================
> --- lib/init/init.sh    (revision 33097)
> +++ lib/init/init.sh    (working copy)
> @@ -159,7 +159,11 @@
>  export GIS_LOCK
> 
>  # Set the global grassrc file
> -GISRCRC="$HOME/.grassrc6"
> +if [ -n "$GRASS_BATCH_JOB" ] ; then
> +       GISRCRC="$HOME/.grassrc6.`uname -n`"
> +else
> +       GISRCRC="$HOME/.grassrc6"
> +fi
> 
>  # Set the session grassrc file
>  if [ "$MINGW" ] ; then
> 
> 
> This change will render GISRCRC individual if running GRASS
> in parallel on a series of machines.
> For a "normal" user the behavior is as before.
> 
> Any objections?

It needs a fallback to use the normal ~/.grassrc6 if a host-specific
version doesn't exist.

Actually, I really think that any "advanced" use (and I think that
includes running batch jobs on a cluster) should just bypass Init.sh
altogether and set the environment variables itself.

Contrary to what might be assumed from the insane complexity of
Init.sh, manually configuring the GRASS environment can be done with
as little as:

	export GISBASE=/opt/grass-7.0.svn
	export GRASS_GNUPLOT='gnuplot -persist'
	export GRASS_WIDTH=640
	export GRASS_HEIGHT=480
	export GRASS_HTML_BROWSER=firefox
	export GRASS_PAGER=cat
	export GRASS_WISH=wish
	export GRASS_PYTHON=python
	export GRASS_MESSAGE_FORMAT=silent
	export GRASS_TRUECOLOR=TRUE
	export GRASS_TRANSPARENT=TRUE
	export GRASS_PNG_AUTO_WRITE=TRUE
	
	export PATH="$GISBASE/bin:$GISBASE/scripts:$PATH"
	export LD_LIBRARY_PATH="$GISBASE/lib"
	export GRASS_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
	export PYTHONPATH="$GISBASE/etc/python:$PYTHONPATH"
	
	export GIS_LOCK=$$
	export GRASS_VERSION="7.0.svn"
	
	tmp=/tmp/grass6-"`whoami`"-$GIS_LOCK
	export GISRC="$tmp/gisrc"
	mkdir "$tmp"
	cp ~/.grassrc6 "$GISRC"

[That is in a script sourced from my ~/.bash_profile; the only time
Init.sh ever gets run here is if I'm testing changes to Init.sh.]

And much of that is unnecessary.

These are only needed for display commands:

	export GRASS_WIDTH=640
	export GRASS_HEIGHT=480
	export GRASS_TRUECOLOR=TRUE
	export GRASS_TRANSPARENT=TRUE
	export GRASS_PNG_AUTO_WRITE=TRUE

The first three are now the default, and GRASS_PNG_AUTO_WRITE isn't
really useful for direct rendering.

GRASS_WISH and GRASS_HTML_BROWSER are only necessary for GUI
applications (not relevant to batch jobs).

GRASS_PYTHON is only used by Init.sh to run gis_set.py (g.gui just
uses "python", while scripts use "#!/usr/bin/env python"). 

GRASS_GNUPLOT is only used by i.spectral.

GRASS_PAGER is hardly used, and then mostly by programs which would
only be used interactively.

GRASS_MESSAGE_FORMAT is mostly used when writing to a TTY.

GRASS_VERSION is only used by GEM, AFAICT (g.version reports the
version information from config.h, recorded at compile-time).

GRASS_LD_LIBRARY_PATH is only needed for running commands via an
xterm, so not applicable to batch jobs or 7.x.

So, for batch jobs, you shouldn't need anything beyond e.g.:

	export GISBASE=/opt/grass-7.0.svn
	
	export PATH="$GISBASE/bin:$GISBASE/scripts:$PATH"
	export LD_LIBRARY_PATH="$GISBASE/lib"
	export PYTHONPATH="$GISBASE/etc/python:$PYTHONPATH"
	
	export GIS_LOCK=$$
	
	tmp=/tmp/grass6-"`whoami`"-$GIS_LOCK
	export GISRC="$tmp/gisrc"
	mkdir "$tmp"
	cp ~/.grassrc6 "$GISRC"

If it wasn't for supporting multiple sessions, you could just put the
various environment settings into the global /etc/profile, along with:

	GISRC=$HOME/.grassrc7

And GRASS commands can then be used like any other command (i.e. not
restricted to a GRASS session).

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list