0
我通過sfLapply
打了一個多線程調用,我在sfLapply
中調用的函數打印了一些信息,如果單次調用,它會打印信息到屏幕,但是可以不在sfLapply
,我該怎麼辦?如何打印'sfLapply`的輸出調用R
> library(snow)
> library(snowfall)
>
> sfInit(parallel=T,cpus=3)
snowfall 1.84-6 initialized (using snow 0.3-13): parallel execution on 3 CPUs.
>
> test <-function(i)
+ {
+ sum = 0
+ for(n in 1:i)
+ {
+ sum = n+sum
+ print(sum)
+ }
+ print(sum)
+ }
>
> df = c(1,2,3)
>
> test(2) #can print some output needed
[1] 1
[1] 3
[1] 3
> k = sfLapply(df,test) #print nothing
>
我寫了使用的MULT線程循環C++函數。但是當兩個線程將輸出發送給R時程序崩潰了。因爲R不支持它。我不知道這個問題是否仍然存在。 – user1436187