[Proj] PROJ.4 and OpenMP

Even Rouault even.rouault at spatialys.com
Thu Jul 2 10:34:11 EST 2015

Le jeudi 02 juillet 2015 16:25:50, José Luis García Pallero a écrit :
> Hello:
> Since version 4.8.0, PROJ.4 has some thread safety facilities
> (https://trac.osgeo.org/proj/wiki/ThreadSafety) and also the source
> code contains an example program in which Posix Threads are used. But
> I'm a bit confused about how to use this thread safety with OpenMP.
> Could someone, please, upload a code example of using PROJ with
> OpenMP? Such example could be also added to the distributed source
> code


I don't have a working example to propose nor I am an OpenMP expert, but based 
on https://en.wikipedia.org/wiki/OpenMP, I guess you must use a thread-private 
identifier to select projPJ objects specific to each thread.

The global workflow could be :

- initialization :

projCtxt* tabProjCtx;
projPJ* tabProjSrc;
projPJ* tabProjDst;
int nThreads;
#pragma omp parallel
    #pragma omp single
    nThreads =  omp_get_num_threads()
    /* TODO: allocate tabProjCtx, tabProjSrc and tabProjDst to be nThreads 
large */
    /* TODO: loop over nThreads and initialize each tabProjCtx[i], 
tabProjSrc[i] and tabProjDst[i] */

- and then use something like :

int th_id;
#pragma omp parallel for private(th_id)
     th_id = omp_get_thread_num();
     pj_transform(tabProjSrc[th_id], tabProjDst[th_id], ...)

Completely untested of course...

If you manage to get a working example, please contribute it.


Spatialys - Geospatial professional services

More information about the Proj mailing list