Show
Ignore:
Timestamp:
07/02/09 13:29:08 (5 months ago)
Author:
buntinas
Message:

squashed float == warnings in opminloc and opmaxloc, and refactored code

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • mpich2/trunk/src/mpi/coll/opminloc.c

    r1245 r4891  
    4141#endif 
    4242 
     43/* Note a subtlety in these two macros which avoids compiler warnings. 
     44   The compiler complains about using == on floats, but the standard 
     45   requires that we set loc to min of the locs if the two values are 
     46   equal.  So we do "if a>b {} else if a>=b Y" which is the same as 
     47   "if a>b X else if a==b Y" but avoids the warning. */ 
     48#define MPIR_MINLOC_C_CASE(c_type_) {                   \ 
     49        c_type_ *a = (c_type_ *)inoutvec;               \ 
     50        c_type_ *b = (c_type_ *)invec;                  \ 
     51        for (i=0; i<len; i++) {                         \ 
     52            if (a[i].value > b[i].value) {              \ 
     53                a[i].value = b[i].value;                \ 
     54                a[i].loc   = b[i].loc;                  \ 
     55            } else if (a[i].value >= b[i].value)        \ 
     56                a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); \ 
     57        }                                               \ 
     58    }                                                   \ 
     59    break 
     60 
     61#define MPIR_MINLOC_F_CASE(f_type_) {                   \ 
     62        f_type_ *a = (f_type_ *)inoutvec;               \ 
     63        f_type_ *b = (f_type_ *)invec;                  \ 
     64        for ( i=0; i<flen; i+=2 ) {                     \ 
     65            if (a[i] > b[i]) {                          \ 
     66                a[i]   = b[i];                          \ 
     67                a[i+1] = b[i+1];                        \ 
     68            } else if (a[i] >= b[i])                    \ 
     69                a[i+1] = MPIR_MIN(a[i+1],b[i+1]);       \ 
     70        }                                               \ 
     71    }                                                   \ 
     72    break 
     73 
     74#undef FUNCNAME 
     75#define FUNCNAME MPIR_MINLOC 
     76#undef FCNAME 
     77#define FCNAME MPIU_QUOTE(FUNCNAME) 
    4378void MPIR_MINLOC(  
    4479        void *invec,  
     
    4782        MPI_Datatype *type ) 
    4883{ 
    49     static const char FCNAME[] = "MPIR_MINLOC"; 
     84    int mpi_errno = MPI_SUCCESS; 
    5085    int i, len = *Len, flen; 
    51  
     86     
    5287    flen = len * 2; /* used for Fortran types */ 
    5388 
    5489    switch (*type) { 
    5590    /* first the C types */ 
    56     case MPI_2INT: { 
    57         MPIR_2int_loctype *a = (MPIR_2int_loctype *)inoutvec; 
    58         MPIR_2int_loctype *b = (MPIR_2int_loctype *)invec; 
    59         for (i=0; i<len; i++) { 
    60             if (a[i].value == b[i].value) 
    61                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    62             else if (a[i].value > b[i].value) { 
    63                 a[i].value = b[i].value; 
    64                 a[i].loc   = b[i].loc; 
    65             } 
    66         } 
    67         break; 
    68     } 
    69     case MPI_FLOAT_INT: { 
    70         MPIR_floatint_loctype *a = (MPIR_floatint_loctype *)inoutvec; 
    71         MPIR_floatint_loctype *b = (MPIR_floatint_loctype *)invec; 
    72         for (i=0; i<len; i++) { 
    73             if (a[i].value == b[i].value) 
    74                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    75             else if (a[i].value > b[i].value) { 
    76                 a[i].value = b[i].value; 
    77                 a[i].loc   = b[i].loc; 
    78             } 
    79         } 
    80         break; 
    81     } 
    82     case MPI_LONG_INT: { 
    83         MPIR_longint_loctype *a = (MPIR_longint_loctype *)inoutvec; 
    84         MPIR_longint_loctype *b = (MPIR_longint_loctype *)invec; 
    85         for (i=0; i<len; i++) { 
    86             if (a[i].value == b[i].value) 
    87                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    88             else if (a[i].value > b[i].value) { 
    89                 a[i].value = b[i].value; 
    90                 a[i].loc   = b[i].loc; 
    91             } 
    92         } 
    93         break; 
    94     } 
    95     case MPI_SHORT_INT: { 
    96         MPIR_shortint_loctype *a = (MPIR_shortint_loctype *)inoutvec; 
    97         MPIR_shortint_loctype *b = (MPIR_shortint_loctype *)invec; 
    98         for (i=0; i<len; i++) { 
    99             if (a[i].value == b[i].value) 
    100                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    101             else if (a[i].value > b[i].value) { 
    102                 a[i].value = b[i].value; 
    103                 a[i].loc   = b[i].loc; 
    104             } 
    105         } 
    106         break; 
    107     } 
    108     case MPI_DOUBLE_INT: { 
    109         MPIR_doubleint_loctype *a = (MPIR_doubleint_loctype *)inoutvec; 
    110         MPIR_doubleint_loctype *b = (MPIR_doubleint_loctype *)invec; 
    111         for (i=0; i<len; i++) { 
    112             if (a[i].value == b[i].value) 
    113                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    114             else if (a[i].value > b[i].value) { 
    115                 a[i].value = b[i].value; 
    116                 a[i].loc   = b[i].loc; 
    117             } 
    118         } 
    119         break; 
    120     } 
     91    case MPI_2INT:       MPIR_MINLOC_C_CASE(MPIR_2int_loctype);         
     92    case MPI_FLOAT_INT:  MPIR_MINLOC_C_CASE(MPIR_floatint_loctype); 
     93    case MPI_LONG_INT:   MPIR_MINLOC_C_CASE(MPIR_longint_loctype); 
     94    case MPI_SHORT_INT:  MPIR_MINLOC_C_CASE(MPIR_shortint_loctype); 
     95    case MPI_DOUBLE_INT: MPIR_MINLOC_C_CASE(MPIR_doubleint_loctype); 
    12196#if defined(HAVE_LONG_DOUBLE) 
    122     case MPI_LONG_DOUBLE_INT: { 
    123         MPIR_longdoubleint_loctype *a = (MPIR_longdoubleint_loctype *)inoutvec; 
    124         MPIR_longdoubleint_loctype *b = (MPIR_longdoubleint_loctype *)invec; 
    125         for (i=0; i<len; i++) { 
    126             if (a[i].value == b[i].value) 
    127                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    128             else if (a[i].value > b[i].value) { 
    129                 a[i].value = b[i].value; 
    130                 a[i].loc   = b[i].loc; 
    131             } 
    132         } 
    133         break; 
    134     } 
     97    case MPI_LONG_DOUBLE_INT: MPIR_MINLOC_C_CASE(MPIR_longdoubleint_loctype); 
    13598#endif 
    13699 
     
    138101#ifdef HAVE_FORTRAN_BINDING 
    139102#ifndef HAVE_NO_FORTRAN_MPI_TYPES_IN_C 
    140     case MPI_2INTEGER: { 
    141         int *a = (int *)inoutvec; int *b = (int *)invec; 
    142         for ( i=0; i<flen; i+=2 ) { 
    143             if (a[i] == b[i]) 
    144                 a[i+1] = MPIR_MIN(a[i+1],b[i+1]); 
    145             else if (a[i] > b[i]) { 
    146                 a[i]   = b[i]; 
    147                 a[i+1] = b[i+1]; 
    148             } 
    149         } 
    150         break; 
    151     } 
    152     case MPI_2REAL: { 
    153         float *a = (float *)inoutvec; float *b = (float *)invec; 
    154         for ( i=0; i<flen; i+=2 ) { 
    155             if (a[i] == b[i]) 
    156                 a[i+1] = MPIR_MIN(a[i+1],b[i+1]); 
    157             else if (a[i] > b[i]) { 
    158                 a[i]   = b[i]; 
    159                 a[i+1] = b[i+1]; 
    160             } 
    161         } 
    162         break; 
    163     } 
    164     case MPI_2DOUBLE_PRECISION: { 
    165         double *a = (double *)inoutvec; double *b = (double *)invec; 
    166         for ( i=0; i<flen; i+=2 ) { 
    167             if (a[i] == b[i]) 
    168                 a[i+1] = MPIR_MIN(a[i+1],b[i+1]); 
    169             else if (a[i] > b[i]) { 
    170                 a[i]   = b[i]; 
    171                 a[i+1] = b[i+1]; 
    172             } 
    173         } 
    174         break; 
    175     } 
     103    case MPI_2INTEGER:          MPIR_MINLOC_F_CASE(int); 
     104    case MPI_2REAL:             MPIR_MINLOC_F_CASE(float); 
     105    case MPI_2DOUBLE_PRECISION: MPIR_MINLOC_F_CASE(double); 
    176106#endif 
    177107#endif 
     
    180110        MPIU_THREADPRIV_DECL; 
    181111        MPIU_THREADPRIV_GET; 
    182         MPIU_THREADPRIV_FIELD(op_errno) = MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OP, "**opundefined","**opundefined %s", "MPI_MINLOC" ); 
     112        MPIU_ERR_SET1(mpi_errno, MPI_ERR_OP, "**opundefined","**opundefined %s", "MPI_MINLOC" ); 
     113        MPIU_THREADPRIV_FIELD(op_errno) = mpi_errno; 
    183114        break; 
    184115    } 
    185116        /* --END ERROR HANDLING-- */ 
    186117    } 
     118 
    187119} 
    188120 
    189121 
     122 
     123 
     124#undef FUNCNAME 
     125#define FUNCNAME MPIR_MINLOC_check_dtype 
     126#undef FCNAME 
     127#define FCNAME MPIU_QUOTE(FUNCNAME) 
    190128int MPIR_MINLOC_check_dtype( MPI_Datatype type ) 
    191129{ 
    192     static const char FCNAME[] = "MPIR_MINLOC_check_dtype"; 
     130    int mpi_errno = MPI_SUCCESS; 
    193131     
    194132    switch (type) { 
     
    210148#endif 
    211149#endif 
    212         return MPI_SUCCESS; 
    213         /* --BEGIN ERROR HANDLING-- */ 
    214     default:  
    215         return MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OP, "**opundefined","**opundefined %s", "MPI_MINLOC" ); 
    216         /* --END ERROR HANDLING-- */ 
     150        break; 
     151 
     152    default: MPIU_ERR_SET1(mpi_errno, MPI_ERR_OP, "**opundefined", "**opundefined %s", "MPI_MINLOC"); 
    217153    } 
     154     
     155    return mpi_errno; 
    218156}