How to share work roughly evenly between processes in MPI despite the array_size not being cleanly divisible by the number of processes?

前端 未结 7 1755
借酒劲吻你
借酒劲吻你 2021-01-04 10:25

Hi all, I have an array of length N, and I\'d like to divide it as best as possible between \'size\' processors. N/size has a remainder, e.g. 1000 array elements divided b

7条回答
  •  悲&欢浪女
    2021-01-04 11:12

    I know this is long sense gone but a simple way to do this is to give each process the floor of the (number of items) / (number of processes) + (1 if process_num < num_items mod num_procs). In python, an array with work counts:

    # Number of items
    NI=128
    # Number of processes
    NP=20
    
    # Items per process
    [NI/NP + (1 if P < NI%NP else 0)for P in range(0,NP)]
    

提交回复
热议问题