I have a program which uses MPI_Scatter() and MPI_Gather(). The program take as input an integer N and return the prime number from 2 to N. I create an array with the number from 2 to N and with the MPI_Scatter split the array into N/(number of procs) elements, then give them to the processes. If I insert a number N which is divisible for the number of processes ('size') everything works fine, but when I input a N not divisible for 'size' I'll have some errors. For example: N=16 and size=4 => 16/4= 4, so N%size==0, but when N%size!=0 I will have errors. I tried to add:
div = N/size;
if (N%size != 0)
if (rank == 0)
div++;
where rank is the rank of the current process, to give one more element to the root process. But it is still not working. How can I solve this problem? Thank you in advance.
recvcount
is an integer rather than an integer array, does this imply that all receiving processes can only receive the same number ofrecvtype
data? @Arnold – Kaykaya