omp causing R to crash

Viewed 115

The following portion of the function rl_compute compiles fine but causes R to crash when I run it. Not sure why. It works with 1 thread.

// [[Rcpp::export]]
void rl_compute(NumericVector covparms, 
        NumericMatrix locs, 
        NumericMatrix NNarray,
        NumericVector& y, 
        NumericMatrix X)
{
    
    int n = y.length();
    int m = NNarray.ncol();
    int p = X.ncol();
    int nparms = covparms.length();
    int dim = locs.ncol();

#pragma omp parallel num_threads(2)\
    {
    int id = omp_get_thread_num();
    for(int i=id; i<n; i= i+2 ){

    int bsize = std::min(i+1,m);

    NumericMatrix locsub(bsize, dim);
    arma::mat X0( bsize, p );
    arma::vec ysub;
    NumericVector idx = na_omit(NNarray.row(i));
    ...}
    }

}
0 Answers
Related