vastgroup / vast-tools

A toolset for profiling alternative splicing events in RNA-Seq data.
MIT License
77 stars 28 forks source link

writeLines doesn't work inside mclapply when ncores > 1 #39

Closed lpantano closed 9 years ago

lpantano commented 9 years ago

Hi,

congrats for the tools, is amazing :) so much work here!!!

I just noticed that when I set -c 2 or any other value different than 1, I don't get any line written inside the sighandle file in the diff module.

For instance, this code:

library("parallel")
sighandle <- file("openfile", 'w')
mclapply(1:10, function(i) {
    print(i)
    writeLines(paste0("t",i), sighandle)
    # flush(sighandle)
}, mc.cores=2, mc.preschedule=TRUE, mc.cleanup=TRUE) #End For
close(sighandle)

it gives me an empty file. I tested in two different computers, linux and macosx. If you change to write it works ok. (or add flush(sighandle))

cheers

timbitz commented 9 years ago

Hi Lorena, That code worked fine on my development node, so that's weird-- our buffering settings could be different than default. Thanks for letting me know!

Either way, the method of printing from within that mclapply was flawed and needed to be changed. If -c was set high enough, two nodes could print at the same time and truncate each others output. I just commited d3ca2f5, --the printing is now post-computation, and shouldn't be prone to those buffering issues I think.

Cheers, -Tim

lpantano commented 9 years ago

thanks a lot. quite weird is working different but so happy you found a solution!