Using MPI, how do you wait for threads to finish?
For example:
for (int i = localstart; i < localend; i++)
{
// do stuff that is computationally intensive
}
// I need to wait for all other threads to finish here
if (rank == 0) do_something();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If by threads you meant processes/ranks, then the answer is
MPI_Barrier.But look at the other collective operations too: they might make sense in your application, and offer better performance than hand-coding communication. For example, you could use
MPI_Allgatherto communicate all data to all ranks, and so on.If you meant threads (like pthreads), then you’d have to use whatever the threading library offers.