The (R) program I’m writing is at one point able to write C source code files containing OpenMP instructions in order to speed up the resulting program (these files mainly contain a set of differential equations whose results are written to an array – as these steps can be executed independently, I thought it to be a good idea to parallelize them using omp sections). As the files generated this way are supposed to be used in another part of my program I also use R to compile them using system(R CMD SHLIB...) at runtime, as this approach seemed to have the advantage that, using R CMD SHLIB, no specific compiler would need to be imposed on the user.
The problem I’m now facing is that I can’t pass the -fopenmp (or -openmp) compiler directive to R CMD SHLIB and it is not possible to use a Makevars file providing additional compiler flags (or ideally $SHLIB_OPENMP_CFLAGS) when not building an R package – which I’m not doing in this case, so R CMD SHLIB compiles the file I give it. Without OpenMP paralellization, however, as I see no way how to pass the according flags to SHLIB in this situation.
Is there any possibility to use R CMD SHLIB for this task anyway or will I have to sacrifice portability by internally specifying a compiler for OpenMP compilation?
If you must use
R CMD SHLIBas opposed to a Makefile or package, I think you want to modify an environment variable such asPKG_CPPFLAGSorPKG_CXXFLAGS, which you can from inside R viaSys.setenv().R itself now uses OpenMP and the compiler option you desire is available on recent R systems:
That’s from a standard R 2.15.1 on a Debian / Ubuntu system.