1 |
subroutine distwork(myid,numprocs,nmax,mystart,myend,my_veclen) |
2 |
! There are numprocs of MPI processes calling this routine |
3 |
! Distribute different sections to the processes |
4 |
implicit none |
5 |
|
6 |
! Input variables |
7 |
integer :: myid,nmax,numprocs |
8 |
! Output variables |
9 |
integer :: mystart,myend |
10 |
! Local variables |
11 |
integer :: rest, my_veclen |
12 |
|
13 |
rest = mod(nmax,numprocs) |
14 |
! if(rest.gt.numprocs/2) then |
15 |
if(rest .ne. 0) then |
16 |
! If each process takes my_veclen, total will be bigger than nmax |
17 |
my_veclen = (nmax+(numprocs-rest))/numprocs |
18 |
mystart = 1 + myid*my_veclen |
19 |
myend = mystart + my_veclen - 1 |
20 |
if(myid.eq.numprocs-1) myend = nmax |
21 |
else |
22 |
! If each process takes my_veclen, total will be less than nmax |
23 |
my_veclen = nmax/numprocs |
24 |
mystart = 1 + myid*my_veclen |
25 |
myend = mystart + my_veclen - 1 |
26 |
if(myid.eq.numprocs-1) myend = nmax |
27 |
endif |
28 |
end subroutine distwork |
29 |
|