The Art of R Programming

(WallPaper) #1

16.5 Debugging Parallel R Code..................................................


Parallel R packages such asRmpi,snow,foreach, and so on do not set up a ter-
minal window for each process, thus making it impossible to use R’s debug-
ger on the workers. (MyRdsmpackage, which adds a threads capability to R,
is an exception to this.)
What then can you do to debug apps for those packages? Let’s consider
snowfor a concrete example.
First, you should debug the underlying single-worker function, such
asmtl()in Section 16.2. Here, we would set up some artificial values of the
arguments and then use R’s ordinary debugging facilities.
Debugging the underlying function may be sufficient. However, the bug
may be in the arguments themselves or in the way we set them up. Then
things get more difficult.
It’s even hard to print out trace information, such as values of variables,
sinceprint()won’t work in the worker processes. Themessage()function
may work for some of these packages; if not, you may need to resort to
usingcat()to write to a file.

Parallel R 351
Free download pdf