Is there way to track progress on a mclapply?

前端 未结 6 1131
忘了有多久
忘了有多久 2020-12-23 11:11

I love the setting .progress = \'text\' in plyr\'s llply. However, it causes my much anxiety to not know how far along an mclapp

6条回答
  •  猫巷女王i
    2020-12-23 11:47

    You can use your systems echo function to write from your workers, so simply add the following line to your function:

    myfun <- function(x){
    if(x %% 5 == 0) system(paste("echo 'now processing:",x,"'"))
    dosomething(mydata[x])
    }
    
    result <- mclapply(1:10,myfun,mc.cores=5)
    > now processing: 5 
    > now processing: 10 
    

    This will work if you pass an index e.g., so rather than passing a list of data, pass the index and extract the data in the worker function.

提交回复
热议问题