LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Ravi R. Kumar (rrkuma0_at_[hidden])
Date: 2005-09-25 09:31:25


Hi Robinson,

Thank you for your help.

I applied your code, but it still doesnt work. It hangs when condition is met
for the first time. Please suggest if you have any other idea to implement it.

Thanks a lot,

-- 
Ravi R. Kumar
859-333-8174
Quoting John Robinson <jr_at_[hidden]>:
> 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,
>>
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
>