我在
Windows 7和
Linux(SUSE Server 11(x86_64))上都使用R 3.0.1.以下示例代码在Windows上产生错误,但在Linux上不产生错误.列出的所有工具箱在两台机器中都是最新的.
Windows错误是:
Error in { : task 1 failed - "NULL value passed as symbol address"
如果我将%dopar%更改为%do%,则Windows代码运行时不会出现任何错误.我最初的猜测是,这与Windows中的一些配置问题有关,我尝试重新安装Rcpp和R,但这没有帮助.该错误似乎与作用域有关 – 如果我在f1中定义并编译函数cFunc,那么%dopar%可以工作,但是,正如预期的那样,它非常慢,因为我们为每个任务调用一次编译器.
有没有人对错误发生的原因或如何解决它的建议有一些见解?
library(inline)
sigFunc
code
for(int k = 0; k < INTEGER(size_x)[0]; k++){
tot += REAL(x)[k];
};
return ScalarReal(tot);
'
cFunc
f1
x
a
return(a)
}
library(foreach)
library(doParallel)
registerDoParallel()
# this produces an error in Windows but not in Linux
res
# this works for both Windows and Linux
res
# The following is not a practical solution, but I can compile cFunc inside f1 and then this works in Windows but it is very slow
f1
library(inline)
sigFunc
code
for(int k = 0; k < INTEGER(size_x)[0]; k++){
tot += REAL(x)[k];
};
return ScalarReal(tot);
'
cFunc
x
a
return(a)
}
# this now works in Windows but is very slow
res
谢谢!
古斯塔沃