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/opmaxloc.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_MAXLOC_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 
    4360 
     61#define MPIR_MAXLOC_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 
     75#undef FUNCNAME 
     76#define FUNCNAME MPIR_MAXLOC 
     77#undef FCNAME 
     78#define FCNAME MPIU_QUOTE(FUNCNAME) 
    4479void MPIR_MAXLOC(  
    4580        void *invec,  
     
    4883        MPI_Datatype *type ) 
    4984{ 
    50     static const char FCNAME[] = "MPIR_MAXLOC"; 
     85    int mpi_errno = MPI_SUCCESS; 
    5186    int i, len = *Len, flen; 
    5287     
     
    5590    switch (*type) { 
    5691    /* first the C types */ 
    57     case MPI_2INT: { 
    58         MPIR_2int_loctype *a = (MPIR_2int_loctype *)inoutvec; 
    59         MPIR_2int_loctype *b = (MPIR_2int_loctype *)invec; 
    60         for (i=0; i<len; i++) { 
    61             if (a[i].value == b[i].value) 
    62                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    63             else if (a[i].value < b[i].value) { 
    64                 a[i].value = b[i].value; 
    65                 a[i].loc   = b[i].loc; 
    66             } 
    67         } 
    68         break; 
    69     } 
    70     case MPI_FLOAT_INT: { 
    71         MPIR_floatint_loctype *a = (MPIR_floatint_loctype *)inoutvec; 
    72         MPIR_floatint_loctype *b = (MPIR_floatint_loctype *)invec; 
    73         for (i=0; i<len; i++) { 
    74             if (a[i].value == b[i].value) 
    75                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    76             else if (a[i].value < b[i].value) { 
    77                 a[i].value = b[i].value; 
    78                 a[i].loc   = b[i].loc; 
    79             } 
    80         } 
    81         break; 
    82     } 
    83     case MPI_LONG_INT: { 
    84         MPIR_longint_loctype *a = (MPIR_longint_loctype *)inoutvec; 
    85         MPIR_longint_loctype *b = (MPIR_longint_loctype *)invec; 
    86         for (i=0; i<len; i++) { 
    87             if (a[i].value == b[i].value) 
    88                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    89             else if (a[i].value < b[i].value) { 
    90                 a[i].value = b[i].value; 
    91                 a[i].loc   = b[i].loc; 
    92             } 
    93         } 
    94         break; 
    95     } 
    96     case MPI_SHORT_INT: { 
    97         MPIR_shortint_loctype *as = (MPIR_shortint_loctype *)inoutvec; 
    98         MPIR_shortint_loctype *bs = (MPIR_shortint_loctype *)invec; 
    99         for (i=0; i<len; i++) { 
    100             if (as[i].value == bs[i].value) 
    101                 as[i].loc = MPIR_MIN(as[i].loc,bs[i].loc); 
    102             else if (as[i].value < bs[i].value) { 
    103                 as[i].value = bs[i].value; 
    104                 as[i].loc   = bs[i].loc; 
    105             } 
    106         } 
    107         break; 
    108     } 
    109     case MPI_DOUBLE_INT: { 
    110         MPIR_doubleint_loctype *a = (MPIR_doubleint_loctype *)inoutvec; 
    111         MPIR_doubleint_loctype *b = (MPIR_doubleint_loctype *)invec; 
    112         for (i=0; i<len; i++) { 
    113             if (a[i].value == b[i].value) 
    114                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    115             else if (a[i].value < b[i].value) { 
    116                 a[i].value = b[i].value; 
    117                 a[i].loc   = b[i].loc; 
    118             } 
    119         } 
    120         break; 
    121     } 
    122      
     92    case MPI_2INT:       MPIR_MAXLOC_C_CASE(MPIR_2int_loctype);         
     93    case MPI_FLOAT_INT:  MPIR_MAXLOC_C_CASE(MPIR_floatint_loctype); 
     94    case MPI_LONG_INT:   MPIR_MAXLOC_C_CASE(MPIR_longint_loctype); 
     95    case MPI_SHORT_INT:  MPIR_MAXLOC_C_CASE(MPIR_shortint_loctype); 
     96    case MPI_DOUBLE_INT: MPIR_MAXLOC_C_CASE(MPIR_doubleint_loctype); 
    12397#if defined(HAVE_LONG_DOUBLE) 
    124     case MPI_LONG_DOUBLE_INT: { 
    125         MPIR_longdoubleint_loctype *a = (MPIR_longdoubleint_loctype *)inoutvec; 
    126         MPIR_longdoubleint_loctype *b = (MPIR_longdoubleint_loctype *)invec; 
    127         for (i=0; i<len; i++) { 
    128             if (a[i].value == b[i].value) 
    129                 a[i].loc = MPIR_MIN(a[i].loc,b[i].loc); 
    130             else if (a[i].value < b[i].value) { 
    131                 a[i].value = b[i].value; 
    132                 a[i].loc   = b[i].loc; 
    133             } 
    134         } 
    135         break; 
    136     } 
     98    case MPI_LONG_DOUBLE_INT: MPIR_MAXLOC_C_CASE(MPIR_longdoubleint_loctype); 
    13799#endif 
    138100 
     
    140102#ifdef HAVE_FORTRAN_BINDING 
    141103#ifndef HAVE_NO_FORTRAN_MPI_TYPES_IN_C 
    142     case MPI_2INTEGER: { 
    143         int *a = (int *)inoutvec; int *b = (int *)invec; 
    144         for ( i=0; i<flen; i+=2 ) { 
    145             if (a[i] == b[i]) 
    146                 a[i+1] = MPIR_MIN(a[i+1],b[i+1]); 
    147             else if (a[i] < b[i]) { 
    148                 a[i]   = b[i]; 
    149                 a[i+1] = b[i+1]; 
    150             } 
    151         } 
    152         break; 
    153     } 
    154     case MPI_2REAL: { 
    155         float *a = (float *)inoutvec; float *b = (float *)invec; 
    156         for ( i=0; i<flen; i+=2 ) { 
    157             if (a[i] == b[i]) 
    158                 a[i+1] = MPIR_MIN(a[i+1],b[i+1]); 
    159             else if (a[i] < b[i]) { 
    160                 a[i]   = b[i]; 
    161                 a[i+1] = b[i+1]; 
    162             } 
    163         } 
    164         break; 
    165     } 
    166     case MPI_2DOUBLE_PRECISION: { 
    167         double *a = (double *)inoutvec; double *b = (double *)invec; 
    168         for ( i=0; i<flen; i+=2 ) { 
    169             if (a[i] == b[i]) 
    170                 a[i+1] = MPIR_MIN(a[i+1],b[i+1]); 
    171             else if (a[i] < b[i]) { 
    172                 a[i]   = b[i]; 
    173                 a[i+1] = b[i+1]; 
    174             } 
    175         } 
    176         break; 
    177     } 
     104    case MPI_2INTEGER:          MPIR_MAXLOC_F_CASE(int); 
     105    case MPI_2REAL:             MPIR_MAXLOC_F_CASE(float); 
     106    case MPI_2DOUBLE_PRECISION: MPIR_MAXLOC_F_CASE(double); 
    178107#endif 
    179108#endif 
     
    182111        MPIU_THREADPRIV_DECL; 
    183112        MPIU_THREADPRIV_GET; 
    184         MPIU_THREADPRIV_FIELD(op_errno) = MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OP, "**opundefined","**opundefined %s", "MPI_MAXLOC" ); 
     113        MPIU_ERR_SET1(mpi_errno, MPI_ERR_OP, "**opundefined","**opundefined %s", "MPI_MAXLOC" ); 
     114        MPIU_THREADPRIV_FIELD(op_errno) = mpi_errno; 
    185115        break; 
    186116    } 
     
    191121 
    192122 
     123#undef FUNCNAME 
     124#define FUNCNAME MPIR_MAXLOC_check_dtype 
     125#undef FCNAME 
     126#define FCNAME MPIU_QUOTE(FUNCNAME) 
    193127int MPIR_MAXLOC_check_dtype( MPI_Datatype type ) 
    194128{ 
    195     static const char FCNAME[] = "MPIR_MAXLOC_check_dtype"; 
     129    int mpi_errno = MPI_SUCCESS; 
     130     
    196131    switch (type) { 
    197132    /* first the C types */ 
     
    212147#endif 
    213148#endif 
    214         return MPI_SUCCESS; 
    215         /* --BEGIN ERROR HANDLING-- */ 
    216     default:  
    217         return MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OP, "**opundefined","**opundefined %s", "MPI_MAXLOC" ); 
    218         /* --END ERROR HANDLING-- */ 
     149        break; 
     150 
     151    default: MPIU_ERR_SET1(mpi_errno, MPI_ERR_OP, "**opundefined", "**opundefined %s", "MPI_MAXLOC"); 
    219152    } 
     153     
     154    return mpi_errno; 
    220155} 
    221156