I have a parallel program for sending messages using the mpi library, but it does not work correctly. Once shown the output by console is waiting for something and continues running. I show you the code.
#include<stdio.h>
#include<mpi.h>
int main( int argc, char* argv[] ) {
int this_proc, total_procs;
MPI_Init( &argc, &argv );
MPI_Comm_size( MPI_COMM_WORLD, &total_procs );
MPI_Comm_rank( MPI_COMM_WORLD, &this_proc );
int i;
int* localI;
localI=(int*)malloc(sizeof(double));
if(this_proc!=0){
MPI_Send(&this_proc,1,MPI_INT,0,0,MPI_COMM_WORLD);
}else{
for(i=1;i<total_procs;i++){
MPI_Recv(localI,1,MPI_INT,i,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE);
printf("Recibiendo mensaje del proceso nro %d \n",*localI);
}
}
MPI_Finalize();
printf("Finalizando %d\n",this_proc);
}
I run in 5 processes:
mpirun -np 5 helloWorld
The output by console is as follows:
Recibiendo mensaje del proceso nro 1 Recibiendo mensaje del proceso nro 2 Recibiendo mensaje del proceso nro 3 Recibiendo mensaje del proceso nro 4
And the cursor is waiting for something. In other words, the program continues running. I can not tell what the problem is. If someone can help me, I'll thank you. Greetings. PS: I did not get a more consistent label.