Code:
if( rank == root )
i = 0;
while( i < n )
{
if( rank == root )
{
/* ...do stuff... */
MPI_Scatter( ); /* Move this line out of IF, if everyone does MPI_ */
}
/* For everyone, or if for !root, add in an IF to handle it. */
for (j=0;j<x;j++) // I WANT ALL PROCESSORS TO SEE THIS CODE (Each do their own for loop)
/* ...do stuff... */
if( rank == root )
{
MPI_Gather( ); /* Same as above... */
i++; /* Move so it's visible to whoever is supposed to increment it. */
}
}
You just need to think about who needs to do what, and block the appropriate people from doing it. Don't expect me to figure the whole thing out for you, you need to think about it and decide what lines are needed by who, and then IF them appropriately.
Quzah.