0

I am using the parallel package to have each core perform the same function on a chunk of data.

For debugging purposes I would like to be able to print variable contents to a file for each core, or anything similar that might help me locate and correct a coding mistake...

I tried to include cat(variable,filepath,append=TRUE) at the level of the function that would be executed by each worker. However, the variable's contents do not appear in the file once execution is finished.

Imlerith
  • 479
  • 1
  • 7
  • 15
  • This may help http://stackoverflow.com/questions/16717461/how-can-i-print-or-cat-when-using-parallel – Pierre L Aug 03 '16 at 18:43
  • @PierreLafortune thank you... Perhaps I should delete this post ? – Imlerith Aug 03 '16 at 18:47
  • This definitely works (I’m using the same code), the error must be elsewhere. – Konrad Rudolph Aug 03 '16 at 18:47
  • No need, the duplicate system will create a link for others doing a similar search as yours. – Pierre L Aug 03 '16 at 18:48
  • @PierreLafortune I don’t think that’s a duplicate — the other question is about printing to the standard output, whereas OP is asking about writing to a file (and the solution to the other question is: “write to a file”). – Konrad Rudolph Aug 03 '16 at 18:49
  • @KonradRudolph The link is for both redirecting to the console and a file as the OP asks – Pierre L Aug 03 '16 at 18:54
  • @PierreLafortune I must be blind: the question is definitely only about printing to the console. The answers mention printing to files, but they do so specifically *as the solution to OP’s problem*, and nowhere is the code in the current question mentioned, which definitely works out of the box without `makeCluster`. – Konrad Rudolph Aug 03 '16 at 18:56
  • The OP in the linked question asked about printing to the console. It is not directly possible, the answer points to the solution by showing the workaround--by printing to file, or in Linux to add `""` as the outfile. The user of this question is asking about printing to file, the answer is the same as the user commented themselves. Would you like to discuss this more? – Pierre L Aug 03 '16 at 19:01
  • @PierreLafortune My point is: OP’s code already works. Nothing more is needed. The linked/duplicate answers *add nothing* to help the OP. They’re simply completely and utterly orthogonal. – Konrad Rudolph Aug 03 '16 at 19:05
  • I have tried to do this exact thing. The process blocking printing to console is the same that prevents printing to file. The batch nature of parallel does not allow it as far as I know. I have tried to do this exact thing with both console and file before. But I will try again with OP's code in light of your comment instead of asking you to believe it. – Pierre L Aug 03 '16 at 19:08
  • @PierreLafortune “The process blocking printing to console is the same that prevents printing to file” — that may of course depend on the operating system … but in general: no: there is no such blocking. You may get issues if you print to a *connection* but not if each process opens its own connections. Here’s some code that should definitely work, regardless of system even: https://gist.github.com/klmr/bbe6adb47d551397cab0a056b9b4c028 – Konrad Rudolph Aug 03 '16 at 19:12
  • @KonradRudolph Just as predicted the OP's code did not work. The solution in the link did however. – Pierre L Aug 03 '16 at 19:29

0 Answers0