Problem in mpi4py point to point communication

14 views
Skip to first unread message

Partha Sarathi Pal

unread,
May 29, 2021, 10:58:15 AM5/29/21
to mpi4py
Hi,
   I am trying to write a parallel python script with mpi4py. 
I am facing one problem while distributing the  code in all worker CPUs.
I want to share 12 iterations on 9 worker CPUs. 
For 3 cases one worker CPU will be assigned 2 jobs. How to distribute that.

    if rank ==  0:
        d = range(150, 162)
        e = range(516, 517)
        paramlist = list(itertools.product(d,e))
        #print(len(paramlist))

        for i2 in range(len(paramlist)):
            rnk = (i2) % (size - 1)
            if rnk == 0:
                rnk = size - 1
            print(i2, rnk, paramlist[i2][0], paramlist[i2][1])
            comm.send(paramlist[i2], dest=rnk, tag=1000+rnk)

    elif rank > 0:
        paramlist = comm.recv(source=0, tag=1000+rank)
#        print(rank, paramlist)
        a = analysis2(paramlist)
        print(a)
len(paramlist) = 12
print(i2, rnk, paramlist[i2][0], paramlist[i2][1]) prints the following:
0 9 150 516
1 1 151 516
2 2 152 516
3 3 153 516
4 4 154 516
5 5 155 516
6 6 156 516
7 7 157 516
8 8 158 516
9 9 159 516
10 1 160 516
11 2 161 516
Print(a) prints the following:
(1, 151, 516, 496.6346740722656)
(2, 152, 516, 486.2257995605469)
(3, 153, 516, 479.7689514160156)
(4, 154, 516, 479.3370666503906)
(5, 155, 516, 479.4616394042969)
(6, 156, 516, 482.2262268066406)
(7, 157, 516, 482.8017272949219)
(8, 158, 516, 485.6268005371094)
(9, 150, 516, 488.07647705078125)

For case 9 10, 11 they are assigned to rank 9, 1, 2, respectively.
9 9 159 516
10 1 160 516
11 2 161 516
Rank 9, 1, 2 are getting 2 jobs. How to distribute jobs in this case.
When one rank will be assigned more than once.

Thank you
Partha
Reply all
Reply to author
Forward
0 new messages