title: Is it allowed/possible to call an R function or fortran code within a pragma openmp parallel for loop in Rcpp?
body: <p>In an Rcpp project I would like to be able to either <a href="http://gallery.rcpp.org/articles/r-function-from-c++/" rel="nofollow noreferrer">call an R function</a> (the <a href="https://github.com/cran/cobs/blob/master/R/scobs.R" rel="nofollow noreferrer">cobs</a> function from the <code>cobs</code> package to do a concave spline fit) or <a href="https://stackoverflow.com/questions/31396802/integrate-fortran-c-with-r?rq=1">call the fortran code</a> that it relies on (the <code>cobs</code> function uses <code>quantreg</code>'s <a href="https://github.com/cran/quantreg/blob/master/R/sfn.R" rel="nofollow noreferrer">rq.fit.sfnc</a> function to fit the constrained spline model, which in turn relies on the fortran coded <a href="https://github.com/cran/quantreg/blob/master/src/srqfnc.f" rel="nofollow noreferrer">srqfnc</a> function in the <code>quantreg</code> package) within a <a href="http://gallery.rcpp.org/articles/dmvnorm_arma/" rel="nofollow noreferrer">pragma openmp parallel for loop</a> (the rest of my code mainly requires some simple linear algebra, so that would be no problem, but sadly each inner loop iteration also requires me to do a concave spline fit). I was wondering if this would be allowed or possible though, as I presume such calls would not be thread safe? Would there be an easy fix for this, like to surround those calls by a <code>#pragma omp critical</code> ? Would anyone have any examples of this? Or would the only way in this case involve doing a full <code>Rcpp</code> port of the <code>cobs</code> &amp; <code>rq.fit.sfnc</code> functions first using thread-safe Armadillo classes?</p>