我有一个for循环,它是这样的:
for (i=1:150000) {
tempMatrix = {}
tempMatrix = functionThatDoesSomething() #calling a function
finalMatrix = cbind(finalMatrix, tempMatrix)
}
Run Code Online (Sandbox Code Playgroud)
你能告诉我如何让它平行吗?
我在网上尝试了这个例子,但我不确定语法是否正确.它也没有太多提高速度.
finalMatrix = foreach(i=1:150000, .combine=cbind) %dopar% {
tempMatrix = {}
tempMatrix = functionThatDoesSomething() #calling a function
cbind(finalMatrix, tempMatrix)
}
Run Code Online (Sandbox Code Playgroud)