multiprocessing
multiprocessing — Process-based parallelism — Python 3.7.4 documentation
https://docs.python.org/3/library/multiprocessing.html
multiprocessing --- プロセスベースの並列処理 — Python 3.7.4 ドキュメント
https://docs.python.org/ja/3/library/multiprocessing.html
Examples
MetPy Mondays
`#41 - multiprocessing : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/en/entry/metpy-mondays-41-multiprocessing
plotting figures
code:python
import multiprocessing as mp
with mp.Pool(processes=4) as pool:
pool.map(plot_datasets,cat.datesets-10:)
pool.close()
pool.join()
`#82 - Multiprocessing : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-82-multiprocessing
#mesonet
code:pyhon
import multiprocessing as mp
for fname in data_path.glob("*.mts")
pool.apply_async(get_station_means,args=(fname,),callback=record_means)
pool.close()
pool.join()
`#126 - Queue with Multiprocessing : Unidata Developer's Blog
writing data to a sigle file
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-126-queue-with
`#127 - Multiprocessing and Managed Dictionaries : Unidata Developer's Blog
precipitable water
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-127-multiprocessing-and
code:python
import multiprocessing as mp
from multiprocessing import Manager
def calculate_pw(d,station,timestamp):
dstation= ...
def main():
manager = Manager()
results = manager.dict()
pool = mp.Pool(4)
jobs = []
stations = ....
t=datetime(2020,3,19)
for station in stations:
job=pool.apply_async(calculate_pw,(results,station,t))
jobs.append(job)
for job in jobs:
job.get()
pool.close()
pool.join()
if __name__ = '__main__':
main()
matplotlibをmultiprocessing.Poolで並列化する際の覚書 - Qiita
https://qiita.com/1007/items/83312122b769a504dc98
code:python
with mp.get_context("spawn").Pool(4) as p:
p.map(myplot, range(n))
雨の中、Cを書かずにPythonで並列計算をする人間がいてもいい。自由とはそういうものだ。 - Qiita
https://qiita.com/yubais/items/5a9d91fe03fe715b21d0
python - Easy parallelization of numpy.apply_along_axis()? - Stack Overflow
https://stackoverflow.com/questions/45526700/easy-parallelization-of-numpy-apply-along-axis
Tip
python - Python3 multiprocessing pool unbalanced cpu usage on compute engine - Stack Overflow
Pythonのmultiprocessingで複数の引数を渡す - iMind Developers Blog
apply_async
python - multiprocessing.Pool: When to use apply, apply_async or map? - Stack Overflow
The order of the results is not guaranteed to be the same as the order of the calls to Pool.apply_async.