Python: Splitting up a sum with threads

后端 未结 2 571
囚心锁ツ
囚心锁ツ 2021-01-24 13:49

i have a costly calculation to do for fitting some experimental data. The fitting function is a sum over eigenmodes, each of them containing a specific surface integral. As it i

相关标签:
2条回答
  • 2021-01-24 14:05

    Try out multiprocessing. This will effectively create separate Python processes using a thread-like interface. However, make sure that you profile your computation and make sure that it is the problem, not something else like IO. Starting processes is very slow, so keep them around for a while if you are planning to use them.

    You can also use numpy for those functions. They're written in C code, so they're stupid fast. Check them both out and see what fits best. I would go for the numpy solution myself...

    0 讨论(0)
  • 2021-01-24 14:17

    use multiprocessing pool

    import multiprocessing as mp
    
    p = mp.Pool(10)
    
    res = p.map(your_function, range(Mmin, Mmax))
    
    0 讨论(0)
提交回复
热议问题