Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - foreach loops with verbose=TRUE

Tags:

foreach

r

I am using the doSMP R-package along with foreach loops.

I have specified verbose=TRUE as an optional argument of foreach which is reported to be very useful for trouble shooting. I guess this is true: it is very useful... if we understand what it means.

Can you please explain me the following message which is returned after an iteration.

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

EDIT

Following Xu Wang's requirement, here is a minimum working example.

library(doSMP)

w <- startWorkers(2)
registerDoSMP(w)

root <- foreach(i=1:2, .verbose=TRUE) %dopar%
{
  sqrt(i)
}

stopWorkers(w)
like image 712
Marco Avatar asked Nov 03 '11 13:11

Marco


1 Answers

The message after each iteration is produced by the 'foreach' package. I analyzed package code (mostly the file "foreach.R") and made a slightly modified demonstration in which I use %do% instead of %dopar%. Read the description of the output after the log.

--- log start ---

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" is the number of tasks launched.
"numResults" is the number of results received.
"stopped: FALSE" (or "TRUE") simply means whether foreach has completed all the iterations.
"returning status FALSE" (or "TRUE") displays the output from an internal (to 'foreach' package) function "complete()", which checks whether all work has been done. Depending on the backend, the message "returning status TRUE" may be displayed or skipped (doParallel backend did not and doRedis backend did print the 'TRUE' message in my particular situations).

like image 84
cloudcell Avatar answered Sep 22 '22 03:09

cloudcell