R - foreach loops with verbose = TRUE

I use the doSMP R package along with foreach loops .

I pointed out verbose=TRUE as an optional foreach argument, which is reportedly very useful for troubleshooting. I think this is true: it is very useful ... if we understand what it means.

Could you explain to me the following message that comes back after iteration.

 got chunk of 1 result(s) starting at # 1 numValues: 2, numResults: 1, stopped: TRUE returning status FALSE 

EDIT

Following the requirement of Xu Wang, here is a minimal working example.

 library(doSMP) w <- startWorkers(2) registerDoSMP(w) root <- foreach(i=1:2, .verbose=TRUE) %dopar% { sqrt(i) } stopWorkers(w) 
+6
source share
1 answer

A message after each iteration is generated by the foreach package. I analyzed the package code (basically the β€œforeach.R” file) and made a slightly modified demo in which I use% do% instead of% dopar%. Read the description of the output after the log.

--- beginning of the magazine ---

 foreach(i=1:2, .verbose=TRUE) %do% { sqrt(i) } evaluation # 1: $i [1] 1 result of evaluating expression: [1] 1 got results for task 1 numValues: 1, numResults: 1, stopped: FALSE returning status FALSE evaluation # 2: $i [1] 2 result of evaluating expression: [1] 1.414214 got results for task 2 numValues: 2, numResults: 2, stopped: FALSE returning status FALSE numValues: 2, numResults: 2, stopped: TRUE calling combine function evaluating call object to combine results: fun(accum, result.1, result.2) [[1]] [1] 1 [[2]] [1] 1.414214 

--- log end ---

"numValues" - the number of running tasks.
"numResults" - the number of results.
"stopped: FALSE" (or "TRUE" ) simply means that foreach has completed all iterations.
"FALSE status return" (or "TRUE" ) displays the output from the internal (in the "foreach" package) function "complete ()", which checks whether everything worked was done. Depending on the backend, the message "returning the status TRUE" may be displayed or skipped (doParallel backend did not, and the doRedis backend printed the message "TRUE" in my specific situations).

+3
source

Source: https://habr.com/ru/post/900695/


All Articles