I have a function with the following form :
#include <cmath>
#include <RcppArmadillo.h>
#include <Rcpp.h>
// [[Rcpp::plugins(openmp)]]
#include <omp.h>
// [[Rcpp::depends(RcppParallel)]]
#include <RcppParallel.h>
using namespace Rcpp;
using namespace std;
NumericVector parallel_Calculation(Function &FUN,
const NumericVector ¶m)
{
...
#pragma omp parallel for
for(int k = 0; k < nb_Param; k++)
{
/* Using the FUN function to perform calculations */
}
...
}
I would like to use an arbitrary function defined in R in a parallel Rcpp code. First, is the variable FUN thread-safe? If not, is there a way to make it thread safe?