I have an algorithm parallelized in main() using C with openMPI; it works perfect but now I want to move the code over to an external function.
void my_parallel_function(int v[], int size, int rank)
{
if(rank==0)
{
MPI_Send(&v[0], 5, MPI_INT, 1, 1, MPI_COMM_WORLD);
}
else
{
MPI_Recv(&v[0], 5, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD,&status);
printf("value of item 1: %d", v[0]);
}
}
int main(int argc, char *argv[])
{
int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Status status;
int vect[100];
if (rank==0)
{
my_parallel_function(vect, size, rank);
}
MPI_Finalize();
return 0;
}
The above code is only intended to illustrate what I would like to do. I can run my code from the console but then there is no response, it just hangs.
Any ideas? Thanks a lot!