0

I try to call OpenMP codes in my R package. The OpenMP region in a fun.c file under the src directory is like:

    static void mp_func(double *x, double *a, double *b,
                           double *den, int *P) {
        #pragma omp parallel for num_threads(P[0]) default(none)          \
            firstprivate(length, q, a, b, isLog, lowTail, cdf, R_NaN) private(i) \
                reduction(||:naflag)
                for (i = 0; i < length; i++){
                    ...
                    if(some condition) den[i] = R_NaN;
                    ...
                    if(some condition) den[i] = R_NegInf;
                }
    }

However, when I run R CMD CHECK, `it gives error message that:

 enclosing parallel;

and

R_NaN not specified in enclosing parallel;

I don't think including R_NaN and R_NegInf in the private clause is possible, so how can I solve it? Should I wrap all operation part into a function and call this function in the OpenMP region?

Bs He
  • 717
  • 1
  • 10
  • 22
  • You should learn how to use OpenMP first with C before you try to use it with R. You should also provide a complete code example (e.g. where to you define the iterator `i`). I think you should also show how you would like to call this function from R. Also, I don't see how R is going to know about `mp_func` since you made it static. Improve your question and I will upvote it. – Z boson Mar 16 '17 at 09:14

1 Answers1

0

Well, the problem is solved by add R_NaN and such in firstprivate clause. The reason to do so is that R_NaN and R_NegInf are global variables called via external declarations from the included header file R.h.

Bs He
  • 717
  • 1
  • 10
  • 22