How to wait the slave to be finished first then execute the master--MPI C++?

Hi,
How to wait the slave to be finished first then execute the master?
Can someone give me the specific function? Or the detailed example.
Thanks~

I think of all threads as peers. Doesn't barricade do this for you?