<div dir="ltr">Thank you so much, Jeff. The part that I do not understand is the "and make that package available in your worker environment" part. Could you please let me know how I can make the package available for each worker. <br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 14, 2021 at 1:44 PM Jeff Newmiller <<a href="mailto:jdnewmil@dcn.davis.ca.us">jdnewmil@dcn.davis.ca.us</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">clusterExport works just fine if you put your Rcpp code into your own package and make that package available in your worker environment. Given the need for compilation in possibly a variety of computing environments for parallel processing this is definitely recommended.<br>
<br>
On May 14, 2021 10:35:25 AM PDT, Naeem Khoshnevis <<a href="mailto:khoshnevis.naeem@gmail.com" target="_blank">khoshnevis.naeem@gmail.com</a>> wrote:<br>
>Hi Michael,<br>
><br>
><br>
>Thank you so much for your response. That is correct. One method for<br>
>exporting required variables/functions is using the clusterExport<br>
>function,<br>
> which does not work for Rcpp-based functions. Another option is using<br>
>clusterEvalQ (as mentioned in the shared post); however, I am not sure<br>
>if<br>
>CRAN likes to see the library(package name) inside the codebase. What<br>
>are<br>
>your thoughts?<br>
><br>
>Best regards,<br>
>Naeem<br>
><br>
>On Fri, May 14, 2021 at 11:57 AM Michael Weylandt <<br>
><a href="mailto:michael.weylandt@gmail.com" target="_blank">michael.weylandt@gmail.com</a>> wrote:<br>
><br>
>> Hi Naeem,<br>
>><br>
>> My (very quick) guess is that this isn't an Rcpp problem per se, but<br>
>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>
>><br>
>><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<br>
>and<br>
>> works as expected; however, it is not available for praLapply<br>
>workers. A<br>
>> temporary fix is just using Rcpp::cppFunction inside the function<br>
>that<br>
>> parLapply workers call and copy the entire function over there.<br>
>However,<br>
>> 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<br>
>better<br>
>> long-term solution. Here is the package and three functions that you<br>
>might<br>
>> want to take a look at.<br>
>> ><br>
>> > Original cpp function:<br>
>> ><br>
>><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>
>> ><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<br>
>c++<br>
>> code:<br>
>> ><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>
>> ><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>
>><br>
<br>
-- <br>
Sent from my phone. Please excuse my brevity.<br>
</blockquote></div>