I'm trying to pass a frequency vector between processes and to update it in the process. The processes communicate in a tree topology:
0: 1 2
1: 0 3 4 5 6
2: 0 7 8
3: 1
4: 1 9 10
5: 1
6: 1
7: 2
8: 2 11
9: 4
10: 4
11: 8
Basically rank 0 can communicate only with 1 and 2, 1 only with 0,3,4,5,6 and so on. In the end Rank 0 should have a frequency vector with all the values from other ranks.
if (rank == 0) {
for (i = 0; i < nr_elements; i++) {
MPI_Recv(local_frequency, num_alphabets, MPI_INT, neigh[i], 0, MPI_COMM_WORLD, &status);
printf("[RANK %d]Received from %d\n", rank, neigh[i]);
for(i = 0; i < num_alphabets; i++) {
frequency[i]+=local_frequency[i];
}
}
}
else {
//leaf
if (nr_elements == 1) {
MPI_Send(frequency, num_alphabets, MPI_INT, parent, 0, MPI_COMM_WORLD);
printf("[RANK %d]Sent to %d\n", rank, parent);
}
else {
//first we receive
for (i = 0; i < nr_elements; i++) {
if (neigh[i] != parent) {
MPI_Recv(local_frequency, num_alphabets, MPI_INT, neigh[i], 0, MPI_COMM_WORLD, &status);
printf("[RANK %d]Received from %d\n", rank, neigh[i]);
for(i = 0; i < num_alphabets; i++) {
frequency[i]+=local_frequency[i];
}
}
}
MPI_Send(frequency, num_alphabets, MPI_INT, parent, 0, MPI_COMM_WORLD);
printf("[RANK %d]Sent to %d\n", rank, parent);
}
This is the result of their communication:
- [RANK 2]Received from 7
- [RANK 2]Sent to 0
- [RANK 3]Sent to 1
- [RANK 6]Sent to 1
- [RANK 7]Sent to 2
- [RANK 4]Received from 9
- [RANK 4]Sent to 1
- [RANK 5]Sent to 1
- [RANK 9]Sent to 4
- [RANK 0]Received from 1
- [RANK 1]Received from 3
- [RANK 1]Sent to 0
- [RANK 10]Sent to 4
- [RANK 11]Sent to 8
- [RANK 8]Received from 11
- [RANK 8]Sent to 2
Every child send info to their parent, but apparently not all messages are received. However if I remove the update operation after every MPI_Recv everything works normally. Is there any problem with synchronization? What should I do?
Some things you should know:
- num_alphabets = 256
- parent and nr_elements are well calculated
- neigh is the neighbours vector
MPI_Ircv
etc), which solves many problems. I am not sure though if this solves your problem. – Thomas Langnr_elements
and/orneighs
. Same issue with rank 2 sending to 0 before receiving from 8. – Gilles Gouaillardeti
as an index of the innermost loop ... then you can delete this question since it will not help future readers. – Gilles Gouaillardet