Python multiprocessing: restrict number of cores used

后端 未结 5 1418
忘掉有多难
忘掉有多难 2020-12-25 08:46

I want to know how to distribute N independent tasks to exactly M processors on a machine that has L cores, where L>M. I don\'t want to use all the processors because I sti

5条回答
  •  孤独总比滥情好
    2020-12-25 09:41

    On my dual-core machine the total number of processes is honoured, i.e. if I do

    p = Pool(1)
    

    Then I only see one CPU in use at any given time. The process is free to migrate to a different processor, but then the other processor is idle. I don't see how all your processors can be in use at the same time, so I don't follow how this can be related to your I/O issues. Of course, if your simulation is I/O bound, then you will see sluggish I/O regardless of core usage...

提交回复
热议问题