0

I have a code which has a 2D local array (cval).This local array is being calculated by every processor and in the end I call MPI_ALLREDUCE to sum this local array to a global array(gns). This local array has different sizes for different processors.The way I do a all reduce is as follows

k = n2spmax- n2spmin + 1 ! an arbitrary big value

do i = nmin, nmax
     call MPI_ALLREDUCE(cval(i,:),gns(i,:),k,MPI_DOUBLE_PRECISION,MPI_SUM,MPI_COMM_WORLD,ierr)
end do

Is this the correct way of writing it.I am not sure about it ?

1 Answer 1

1

No, you can't do it this way. MPI_Allreduce requires that all of the processes in the communicator are contributing the same amount of data. That's why there's a single count argument.

To give more guidance on what is the right way to do this, we'll need a bit more clarity on what you're trying to do. Is the idea that you're calculating gns(i,j) = the sum over all ranks of cval(i,j), but not all ranks have all the cval(i,j)s?

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for the prompt reply.Let me explain this in detail.I have two global ranges say (nmin,nmax) and (n2min,n2max). Hence gns has to be calculated for the entire range i.e gns(nmin:nmax,n2min:n2max).While these two ranges are divided among processors in an unequal fashion.So cval is the local array on each processor working on the the local ranges.At the end all the values of cval need to clubbed together in a single array gns.
@Vaibhaw: If you're summing the values, then you can pad smaller cval arrays with zeros so that they're all the same size, and your result will be the same.
Actually I have the cval allocated as cval(nmin:nmax,n2min:n2max) i.e same as gns.Before MPI_ALLREDUCE call, each processor works on cval(nl:nh,nln2:nhn2) where [nl,nh] is the local range for [nmin:nmax] while [nln2,nhn2] is the local range for [n2min,n2max].[nln2,nhn2] is of different size for different processor.I give you an example:
1st proc:[nl,nh],[nln2,nhn2]= [0,88],[0,88]
2nd proc:[nl,nh],[nln2,nhn2]= [88,125],[0,125]
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.