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.
Instead of spreading elements from one process to many processes, MPI_Gather takes elements from many processes and gathers them to one single process. This routine is highly useful to many parallel algorithms, such as parallel sorting and searching.
SCATTER MEMVAR creates the memory variables; GATHER MEMVAR collects data from them. Using TO or FROM indicates that field data is stored in an array. SCATTER creates or redimensions the array, if necessary. GATHER collects data from the array, matching it element by element with the record.
ROOT Mpi is the integration of MPI and ROOT technologies in a framework for parallel computing. The motivation was to communicate ROOT objects through processes using serialization, to implement MPI with a better design for ROOT and create an interface that uses the new C++ features to write parallel code.
If you have to distribute an array of numbers, that can not be equally distributed to all processes, use MPI_Scatterv instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With