how to write out log during parallel computation? how to debug parallel computation?

后端 未结 1 872
暗喜
暗喜 2021-01-21 13:59

I found if there are more than one print function during the parallel computation, only the last on will display on the console. So I set outfile option and hope I can get the r

相关标签:
1条回答
  • 2021-01-21 14:37

    It looks like you're only getting the output from one worker in log.txt. I've often wondered if that could happen, because when you specify outfile="log.txt", each of the workers will open log.txt for appending and then call sink. Here is the code that is executed by the worker processes when outfile is not an empty string:

    ## all the workers log to the same file.
    outcon <- file(outfile, open = "a")
    sink(outcon)
    sink(outcon, type = "message")
    

    This makes me nervous because I'm not certain what might happen with all of the workers opening the same file for appending at the same time. It may be OS or file system dependent, and it might explain why you're only getting the output from one worker.

    For this reason, I tend to use outfile="", in which case this code isn't executed, allowing the output operations to happen normally without redirecting them with the sink function. However, on Windows, you won't see the output if you're using Rgui, so use Rterm instead.

    There shouldn't be a problem with multiple print statements in a task, but if you didn't set outfile, you shouldn't see any output since all output is redirected to /dev/null in that case.

    0 讨论(0)
提交回复
热议问题