OpenMP

From GRASS-Wiki
Revision as of 19:13, 19 June 2009 by ⚠️HamishBowman (talk | contribs) (→‎See also: +ML thread)
Jump to navigation Jump to search

Multithreaded jobs in GRASS

OpenMP is an implementation of multithreading, a method of parallelization whereby the master "thread" (a series of instructions executed consecutively) "forks" a specified number of slave "threads" and a task is divided among them (from wikipedia). The job is distributed over the available processor cores (2-core, 4-core, ...).

The (yet) only parallelized library in GRASS >=6.3 is GRASS Partial Differential Equations Library (GPDE). The library design is thread safe and supports threaded parallelism with OpenMP. The code is not yet widely used in GRASS. See here for details.

How to activate it with GCC >= 4.2 (compiler flag '-fopenmp' as well as library '-lgomp' are needed):

# GPDE with openMP support:

cd lib/gpde/
vim Makefile
# uncomment the EXTRA_CFLAGS row and switch the two existing EXTRA_LIBS rows


General code structure

Example cited from "openMP tutorial" (see below):

   #include <omp.h>
  
   int main ()  {
       int var1, var2, var3;
   
       Some serial code 
       ...
  
       /* Beginning of parallel section. Fork a team of threads. */
       /* Specify variable scoping */
  
      #pragma omp parallel private(var1, var2) shared(var3)
      {
  
       /* Parallel section executed by all threads */
       ...
  
       /* All threads join master thread and disband */
      }  /* end pragma */
  
      /* Resume serial code */
      ...
  
   }

And in the Makefile, add something like this:

  #openMP support
  EXTRA_CFLAGS=-fopenmp
  EXTRA_LIBS=$(GISLIB) -lgomp $(MATHLIB)

See also