<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi list,<br>
<br>
sorry for bombarding the list with questions. <br>
I'm trying to use Rcpp via the inline package and to use parallel
computing at the same time. But I get this error:
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<span class="Apple-style-span" style="border-collapse: separate;
color: rgb(0, 0, 0); font-family: Arial; font-style: normal;
font-variant: normal; font-weight: normal; letter-spacing: normal;
line-height: normal; orphans: 2; text-align: auto; text-indent:
0px; text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
-webkit-text-decorations-in-effect: none;
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;
font-size: medium; "><span class="Apple-style-span"
style="font-family: 'Lucida Console'; font-size: 13px;
line-height: 15px; text-align: -webkit-left; white-space:
pre-wrap; ">
<pre tabindex="0" class="GJWPQFQDK4" style="font-family: 'Lucida Console'; font-size: 10pt !important; outline-style: none; outline-width: initial; outline-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; white-space: pre-wrap !important; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 1.2; "><span class="GJWPQFQDF4">first error: NULL value passed as symbol address
I've read a few posts (not related to parallel computing) discussing this error but I couldn't link it back to my specific problem.
Here is an example:
library(inline)
library(parallel)
# A silly Rcpp function
sillyscr <- '
int x = as<int>(i);
double y = 5.6;
NumericVector j(1);
j[0] = x + y;
return j;
'
silly <- cxxfunction(signature(i = "int"), body = sillyscr, plugin = "Rcpp")
silly(1) # Works!
# Equivalent function in R to make sure the problem is not the parallel computing
silly_notcpp <- function(i){
j <- i +5.6
return(j)
}
silly_notcpp(1) # Works !
M <- detectCores()
cl <- makeCluster(M)
clusterExport(cl, varlist=list("silly","silly_notcpp"))
res1 <- parSapply(cl, 1:10,silly_notcpp) # Works!
res1
res2 <- parSapply(cl, 1:10,silly) # Does not work !
res2
stopCluster(cl)
Many thanks!
Marie
</span></pre>
</span></span>
</body>
</html>