Tutorial:embarrassingly easy parallel in Python, Perl and R
0
1
Entering edit mode
8.5 years ago
Echo ▴ 70

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 • 3.7k views
ADD COMMENT

Login before adding your answer.

Traffic: 1569 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6