Welcome to Scicomp!
If every process knows its thread/rank id, and you have one global rule as to how the region of responsibility of a (constant size) array for a process is calculated, then there is no need to communicate. Every process can calculate its own responsibility. That also means that you can calculate the ranges of all ranks from afar without asking them.
Say you have an array of length N, and number of processes P. Then each rank may simply call the following methods.
C++ MWE (godbolt):
#include <iostream>
constexpr int getMyRangeStart(const int myThreadid,const int noOfThreads,const int N){
return myThreadid*((N/noOfThreads));
}
constexpr int getMyRangeEnd(const int myThreadid,const int noOfThreads,const int N){
if(myThreadid==(noOfThreads-1)){
return N-1;
} else{
return (myThreadid+1)*((N/noOfThreads))-1;
}
}
int main() {
int N = 33; //array length
int P = 4; //no of threads/ranks
for(int thread = 0; thread <P; thread++){
std::cout <<" array range of thread " <<thread << " is from : " << getMyRangeStart(thread,P,N) << " to " << getMyRangeEnd(thread,P,N) << std::endl;
}
return 0;
}
The output is as follows:
array range of thread 0 is from : 0 to 7
array range of thread 1 is from : 8 to 15
array range of thread 2 is from : 16 to 23
array range of thread 3 is from : 24 to 32
Note that you have to handle special cases when your array is not cleanly divisible by your number of threads. Then the region of the thread with the highest thread number may extend a little further.
This appraoch is possible as long as the size of your data array does not change during runtime. If the size changes, then you may either force recalculation of the ranges, or employ more elaborate load balancing.
MPI_Gather
. 3. What do you mean "use the list for MPI_Irecv"? $\endgroup$