Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use of MPI_Scatter if the set is not divisible among processes

Tags:

c

mpi

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.

like image 512
damaar Avatar asked Jan 24 '14 12:01

damaar


People also ask

What is the purpose of using Allgather () function in MPI?

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.

What is the difference between the scatter and gather Command explain?

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.

What is root process in MPI?

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.


1 Answers

If you have to distribute an array of numbers, that can not be equally distributed to all processes, use MPI_Scatterv instead.

like image 116
haraldkl Avatar answered Oct 12 '22 22:10

haraldkl