<div dir="ltr">Hi Michael, <div><br></div><div><br>Thank you so much for your response. That is correct. One method for exporting required variables/functions is using the clusterExport function,  which does not work for Rcpp-based functions. Another option is using clusterEvalQ (as mentioned in the shared post); however, I am not sure if CRAN likes to see the library(package name) inside the codebase. What are your thoughts?<br><br>Best regards,<br>Naeem<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 14, 2021 at 11:57 AM Michael Weylandt <<a href="mailto:michael.weylandt@gmail.com">michael.weylandt@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Naeem,<br>
<br>
My (very quick) guess is that this isn't an Rcpp problem per se, but a<br>
parLapply problem. You need to explicitly load your package on each<br>
worker so that functions from it are available.<br>
<br>
See, e.g., the brief discussion here:<br>
<a href="https://stackoverflow.com/questions/18357788/parallel-parlapply-setup#18358875" rel="noreferrer" target="_blank">https://stackoverflow.com/questions/18357788/parallel-parlapply-setup#18358875</a><br>
<br>
The "parallel" packages do not exactly replicate your environment on<br>
each worker node (to avoid expensive set-up / communication costs) so<br>
you need to do a bit more set-up.<br>
<br>
Best,<br>
Michael<br>
<br>
On Fri, May 14, 2021 at 11:49 AM Naeem Khoshnevis<br>
<<a href="mailto:khoshnevis.naeem@gmail.com" target="_blank">khoshnevis.naeem@gmail.com</a>> wrote:<br>
><br>
> Dear Rcpp developers:<br>
><br>
> Thanks for developing and maintaining the Rcpp package.<br>
> I wrote a function in Rcpp. It is available throughout the package and works as expected; however, it is not available for praLapply workers. A temporary fix is just using Rcpp::cppFunction inside the function that parLapply workers call and copy the entire function over there. However, this does not seem right for bigger and more complicated functions.<br>
> I would be grateful if you could let me know whether there is a better long-term solution. Here is the package and three functions that you might want to take a look at.<br>
><br>
> Original cpp function:<br>
> <a href="https://github.com/fasrc/CausalGPS/blob/master/src/compute_closest_wgps_helper.cpp" rel="noreferrer" target="_blank">https://github.com/fasrc/CausalGPS/blob/master/src/compute_closest_wgps_helper.cpp</a><br>
><br>
> Wrapper function that calls this function + temporal fix:<br>
> <a href="https://github.com/fasrc/CausalGPS/blob/master/R/compute_closest_wgps.R" rel="noreferrer" target="_blank">https://github.com/fasrc/CausalGPS/blob/master/R/compute_closest_wgps.R</a><br>
><br>
> The function that uses parLapply (please see line 63-89) to run the c++ code:<br>
> <a href="https://github.com/fasrc/CausalGPS/blob/master/R/compute_closest_wgps.R" rel="noreferrer" target="_blank">https://github.com/fasrc/CausalGPS/blob/master/R/compute_closest_wgps.R</a><br>
><br>
> Best regards,<br>
> Naeem<br>
> _______________________________________________<br>
> Rcpp-devel mailing list<br>
> <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</blockquote></div>