multithreading - How to easily implement parallel for in python? -
i'm c++ guy, love parallelism, hpc applications , know openmp pretty well. i'm learning python , know basics.
as personal project improve python skills, implement parallel version of elkan algorithm k-means. parallel version implemented c , openmp of algorithm present in vlfeat.
now, know how implement elkan algorithm in python...but parallelism? cool thing openmp take serial code, add #pragma omp parallel for , sbam, it's parallel!
how can achieve similar in python? or have design parallel algorithm beginning, i.e., not writing serial version first , make parallel, managing threads explicitly etc (which huge pain)?
first, cpu parallelism in python can obtained via native code or via multiple processes.
second, analogy openmp multiprocessing module.
it has lot going on, simple loops, etc. it's quite easy use.
results = map(operation, things) would become
import multiprocessing pool = multiprocessing.pool() results = pool.map(operation, things)
Comments
Post a Comment