<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Thanks Dirk and Thell,<br>
    <br>
    I tried something similar to Thell's option before, but without the
    clusterEvalQ and the explicit function in parSapply, and it didn't
    work. Your version however works!<br>
    Making a package also looks like it's working!<br>
    <br>
    Marie<br>
    <br>
    On 22/04/2012 11:15 PM, Thell Fowler wrote:
    <blockquote
cite="mid:CAAJPTXiM6PAHUdnzPZZvrCTfGYjECBDYvjxDAGmroV1cLn0Ecw@mail.gmail.com"
      type="cite">I had similar needs and found the simplest thing to do
      was to make the function on each worker node...<br>
      <br>
      library(inline)<br>
      library(parallel)<br>
      <br>
      # A silly Rcpp function<br>
      silly.src <- '<br>
        int x = as<int>(i);<br>
        double y = 5.6;<br>
        NumericVector j(1);<br>
        j[0] =  x + y;<br>
        return j;<br>
      '<br>
      <br>
      M <- detectCores()<br>
      cl <- makeCluster( M )<br>
      <br>
      # Load up Rcpp in each node.<br>
      clusterEvalQ( cl, require( inline ) )<br>
      <br>
      # Pass over the source.<br>
      clusterExport( cl, 'silly.src', .GlobalEnv )<br>
      <br>
      # Build it and keep the output for troubleshooting.<br>
      captured <- clusterEvalQ( cl, capture.output(<br>
        silly <- cxxfunction( signature( i = "int" ),<br>
                              body = silly.src,<br>
                              plugin = "Rcpp",<br>
                              verbose= TRUE ) ) )<br>
      <br>
      # Use an explicit 'function' in the 'par' commands.<br>
      res <- parSapply(cl, 1:10, function(x) { silly(x) } )<br>
      <br>
      cat( unlist( captured ), sep='\n' )<br>
      print( res )<br>
      <br>
      stopCluster(cl)<br>
      rm(cl)<br>
      <br>
      rm( captured )<br>
      rm( res )<br>
      <br clear="all">
      <br>
      -- <br>
      Sincerely,<br>
      Thell<br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Rcpp-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a>
<a class="moz-txt-link-freetext" href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></pre>
    </blockquote>
    <br>
  </body>
</html>