Move the Allreduce out of the IF (all processes must do the reduce even
if they didn't all see the condition):
--------
CONDITION = 0; /* '0' for all the processes */
for(n=1; n<=Nt; n++)
{
for(i=1; i=Nx; i++)
for(j=1; j=Ny; j++)
for(k=1; k=Nz; k++)
if(condition met)
{
CONDITION = 1; /* if condition is true for any of the processes */
}
MPI_Allreduc(&CONDITION,&CONDITION,1,MPI_INT,MPI_MAX,MPI_COMM_WORLD);
if(CONDITION == 1) break;
}
--------
I still can't be sure this is right without all the braces.
/jr
---
Ravi R. Kumar wrote:
> Hi David,
>
> Thank you for your reply.
>
> Infact, my code looks like this:
>
> -----------------------------------------------
> CONDITION = 0; /* '0' for all the processes */
> for(n=1; n<=Nt; n++)
> {
>
> for(i=1; i=Nx; i++)
> for(j=1; j=Ny; j++)
> for(k=1; k=Nz; k++)
> if(condition met)
> {
> CONDITION = 1; /* if condition is true for any of the processes */
> MPI_Allreduc(&CONDITION,&CONDITION,1,MPI_INT,MPI_MAX,MPI_COMM_WORLD);
> }
>
> if(CONDITION == 1) break;
>
> }
> -------------------------------------
>
> I want to break the outermost 'for' loop (i.e. for(n=1; n<=Nt; n++) ). I tried
> your way, but it's not working. I want that if condtion is true for any of the
> processes then it should be communicated to all the processes and hence
> all the
> processes must break come out of the outermost 'for' loop. This is what I want
> to achieve. Please help me how to implement this thing.
>
>
> Looking forward to hearing from you.
>
> Thanks,
>
|