[GRASS-user] Vegetation index with OpenMP

Markus Metz markus.metz.giswork at googlemail.com
Wed Mar 28 07:47:03 EDT 2012


On Tue, Mar 27, 2012 at 1:17 PM, Ripsime Khachatryan <kuli13 at mail.ru> wrote:
> Hi all
>
>
> I would like to asks if anybody calculated the vegetation index using OpenMP, and can anybody give me detailed information how to do that.
> I performed the same operation using MPI, so I am familiar with calculation.
>
Below is a patch for i.vi (GRASS 7). On a quad-core system, there is
no real speedup, only (combined) CPU time increases...

Markus M

start of patch -->

Index: imagery/i.vi/Makefile
===================================================================
--- imagery/i.vi/Makefile	(revision 51167)
+++ imagery/i.vi/Makefile	(working copy)
@@ -5,6 +5,9 @@
 LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB)
 DEPENDENCIES = $(RASTERDEP) $(GISDEP)

+EXTRA_LIBS = $(OMPLIB)
+EXTRA_CFLAGS = $(OMPCFLAGS)
+
 include $(MODULE_TOPDIR)/include/Make/Module.make


Index: imagery/i.vi/main.c
===================================================================
--- imagery/i.vi/main.c	(revision 51167)
+++ imagery/i.vi/main.c	(working copy)
@@ -252,6 +252,10 @@
                 || !(input6->answer) || !(input7->answer)) )
 	G_fatal_error(_("gvi index requires blue, green, red, nir, chan5 and
chan7 maps"));

+    /* init variables */
+    infd_redchan = infd_nirchan = infd_greenchan = -1;
+    infd_bluechan = infd_chan5chan = infd_chan7chan = -1;
+
     infd_redchan = Rast_open_old(redchan, "");
     data_type_redchan = Rast_map_type(redchan, "");
     inrast_redchan = Rast_allocate_buf(data_type_redchan);
@@ -296,13 +300,6 @@
     /* Process pixels */
     for (row = 0; row < nrows; row++)
     {
-	DCELL d_bluechan;
-	DCELL d_greenchan;
-	DCELL d_redchan;
-	DCELL d_nirchan;
-	DCELL d_chan5chan;
-	DCELL d_chan7chan;
-
 	G_percent(row, nrows, 2);

 	/* read input maps */
@@ -322,9 +319,18 @@
 	if (chan7chan) {
 	    Rast_get_row(infd_chan7chan,inrast_chan7chan,row,data_type_chan7chan);
 	}
+
 	/* process the data */
+	#pragma omp parallel for schedule (static)
 	for (col = 0; col < ncols; col++)
 	{
+	    DCELL d_bluechan;
+	    DCELL d_greenchan;
+	    DCELL d_redchan;
+	    DCELL d_nirchan;
+	    DCELL d_chan5chan;
+	    DCELL d_chan7chan;
+
 	    switch(data_type_redchan){
 		    case CELL_TYPE:
 			d_redchan   = (double) ((CELL *) inrast_redchan)[col];


<-- end of patch

>
>
> Thanks in advance for any help.
>
> Regards,
> Ripsime
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
>


More information about the grass-user mailing list