I can't seem to figure out how to send data between nodes instead of sending it to the root node and then sending it to all other nodes.
If I have N nodes each with an array created like so, where SIZE is the total number of nodes, and for the moment assume it's a preprocessor constant (when possible, avoid malloc like the plague). Also, it goes without saying that rank is the current node's rank.
int dummy [SIZE][5];
int i, n;
for (n = 0; n < SIZE; n++){
for (i = 0; i <5; i++){
if ( n == rank ){
dummy [ n ][ i ] = 123;
This gives each node a nearly empty array of dimensions SIZE * 5, with only one row of the numbers 123. Now I want to take all these individual arrays and 'merge' them. The only thing I can think of is the below, but I am certain this will lead to a deadlock, even if I do bother checking to see if I source node does not equal target node:
for ( i = 0; i < SIZE; i++ ){
for ( j = 0; j < SIZE; j++ ){
MPI_Send ( &dummy [ i ], 5, MPI_INT, j, 123, MPI_COMM_WORLD );
}
}
for ( i = 0; i < SIZE; i++ ){
for ( j = 0; j < SIZE; j++ ){
MPI_Recv ( &dummy [ j ], 5, MPI_INT, i, 123, MPI_COMM_WORLD );
}
}
Can someone kindly provide me with some pseudocode as to how to tackle this problem. Cheers