0

I want to calculate the entrywise exponential of a large matrix X and store the resule in another matrix Y using omp parallelization in Rcpp (or maybe RcppArmadillo).

Using regular omp parallelization method such as the following Rcpp code:

double X[row][col], Y[row][col];
#pragma omp parallel for shared(X,Y)
for(i=0; i<row; i++){    
    for(j=0; j<col; j++){        
        X[i][j] = 0.0;        
        Y[i][j] = exp(X[i][j]);    
    } 
}

will fail since google searching tells me that exp() function is not thread safe. Is there any way to fix it?

  • That is not Rcpp code. We have matrix classes (in helper packages). You use `double[row][col]`. That is not the same thing. But if you study the documentation of package `RcppParallel` you should be on your way. – Dirk Eddelbuettel May 05 '23 at 00:56

0 Answers0