samedi 7 novembre 2020

How to compare the last element of an array with the first element of the array of another process in MPI C?

I have an MPI program that takes a sequence of integers of size M and then has parts of the sequence shared to processes (P). These parts of the sequence are of size (M/P).

Each time I want the last element of a process to be compared with the first element of the next process.

e.g. P1: 1 2 3 5
     P2: 10 6 9 8

In the example shown above I want 5 to be compared with 10. For that I use P2P communication, however, the snippet shown below does not seem to work and I cannot tell why.

...
last_el = M/P;
int flag;
if(arr[0] > arr[last_el])
     flag = 1;
else 
     flag = 0;

if(rank == 0)
{
    for(i = 0; i < P; i++)
        MPI_Send(&arr[portion],1,MPI_INT, i+1, 55, MPI_COMM_WORLD);
}
else
{
    for(i = 0; i < P; i++)
        MPI_Recv(&arr[portion],1,MPI_INT, i, 55, MPI_COMM_WORLD, &s);
}
...

Any help is appreciated

Aucun commentaire:

Enregistrer un commentaire