This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Tutorial: embarrassingly easy parallel in Python, Perl and R

Many bioinformatics problems are embarrassingly easy parallel.

With several lines of codes, you can make your code run in parallel using multicore in your machine.

Below are examples I copied from official docs. (I used them in production with minor change)

Python

from multiprocessing import Pool
def f(x):
    return x*x

if __name__ == '__main__':
    p = Pool(5)
    print(p.map(f, [1, 2, 3]))

https://docs.python.org/2/library/multiprocessing.html

Perl

use MCE::Loop;

MCE::Loop::init {
   chunk_size => 1
};
mce_loop { do_work($_) } [ 1..10000 ];

https://metacpan.org/pod/MCE::Loop

For R, it is easy to do too, there are several options.

I used 'foreach' and it can even combine the result for me.

parallel

0 answers

No answers yet.

Log in to answer this question.