int main (int argc, char *argv[])
{
//some serial code goes here
parallel_function(arg1, arg2);
//some more serial code goes here
}
void parallel_function (int arg1, int arg2)
{
//init MPI and do some stuff in parallel
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
//now do some parallel stuff
//....
//finalize to end MPI??
MPI_Finalize();
}
My code runs fine and I get the expected output, but the problem is that the main function is also running in a separate process, so the sequence code is executed more than once. I don’t know how much it is Run this time, because I didn’t even call MPI_Init (if my printer called parallel_function before main, I see multiple printf’s)
After finishing, how can I run the program in parallel?
Thanks for any response!
Short story: MPI_Init and MPI_Finalize does not mark the beginning and end of parallel processing. MPI processes run completely in parallel.
This is a very basic MPI question, but I can’t surround it. I have one The main function is to call another function that uses MPI. The main function I want is serial execution, and the other function is executed in parallel. My code is like this:
int main (int argc, char *argv[])
{
//some serial code goes here
parallel_function(arg1, arg2);
//some more serial code goes here
}
void parallel_function(int arg1, int arg2)
{
//init MPI and do some stuff in parallel
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
//now do some parallel stuff
//....
//finalize to end MPI??
MPI_Finalize();
)
My code runs normally and I get the expected output, but the problem is that the main function is also Run in a separate process, so the sequence code is executed more than once. I don’t know how many times it runs because I didn’t even call MPI_Init (if I call parallel_function before the main printer, I see multiple printf’s)< /p>
After finishing, how can I run the program in parallel?
Thanks for any response!
Check out this answer.
Short story: MPI_Init and MPI_Finalize do not mark the beginning and end of parallel processing. MPI process Run completely in parallel.