[Omp] is MAX reduction available for c/c++ ?

ThanhVu H. Nguyen - Gmail nguyenthanhvuh at gmail.com
Sat Jun 25 09:50:55 PDT 2005


That will work but is it still parallel ?  since the only main
operation there is exec in sequential (locked when being used) .... 
Thanks 

--- "Shah, Sanjiv" <sanjiv.shah at intel.com> wrote:

> How about
> 
> int largest = 0;
> #pragma omp parallel for
> for( int I = 0; I < 1000; ++I) {
>     if( data[i]>largest ) {
> #      pragma omp critical
>        {
>            if( data[i] > largest ) largest=data[i];
>        }
>     }
> } 
> 
> 
> --
> Sanjiv, 217-403-4244
> 
> -----Original Message-----
> From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org] On
> Behalf
> Of ThanhVu H. Nguyen - Gmail
> Sent: Friday, June 24, 2005 6:28 PM
> To: omp at openmp.org
> Subject: [Omp] is MAX reduction available for c/c++ ?
> 
> Hi, I search online for MAX reduction and it seems only available for
> Fortran ?  In that case what is the simplest/standard parallel way to
> find the the max value in an array for code in c++ ?   Thanks,  
> 
> e.g  this is the sequential code for finding largest.  
> 
> int largest = 0 ; 
> for (int i = 0 ; i < 1000 ; ++i){
>    if (data[i]>largest)  largest=data[i];  
> }
> 
> tvn,
> 
> ThanhVu H. Nguyen
> 
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp_openmp.org
> 


tvn,

ThanhVu H. Nguyen




More information about the Omp mailing list