-:    0:Source:/home/MPI/testing/mpich2/mpich2/src/mpi/coll/opmaxloc.c
        -:    0:Graph:opmaxloc.gcno
        -:    0:Data:opmaxloc.gcda
        -:    0:Runs:4080
        -:    0:Programs:1195
        -:    1:/* -*- Mode: C; c-basic-offset:4 ; -*- */
        -:    2:/*
        -:    3: *
        -:    4: *  (C) 2001 by Argonne National Laboratory.
        -:    5: *      See COPYRIGHT in top-level directory.
        -:    6: */
        -:    7:
        -:    8:#include "mpiimpl.h"
        -:    9:
        -:   10:/* MINLOC and MAXLOC structures */
        -:   11:typedef struct MPIR_2int_loctype {
        -:   12:  int  value;
        -:   13:  int  loc;
        -:   14:} MPIR_2int_loctype;
        -:   15:
        -:   16:typedef struct MPIR_floatint_loctype {
        -:   17:  float  value;
        -:   18:  int    loc;
        -:   19:} MPIR_floatint_loctype;
        -:   20:
        -:   21:typedef struct MPIR_longint_loctype {
        -:   22:  long  value;
        -:   23:  int    loc;
        -:   24:} MPIR_longint_loctype;
        -:   25:
        -:   26:typedef struct MPIR_shortint_loctype {
        -:   27:  short  value;
        -:   28:  int    loc;
        -:   29:} MPIR_shortint_loctype;
        -:   30:
        -:   31:typedef struct MPIR_doubleint_loctype {
        -:   32:  double  value;
        -:   33:  int     loc;
        -:   34:} MPIR_doubleint_loctype;
        -:   35:
        -:   36:#if defined(HAVE_LONG_DOUBLE)
        -:   37:typedef struct MPIR_longdoubleint_loctype {
        -:   38:  long double   value;
        -:   39:  int           loc;
        -:   40:} MPIR_longdoubleint_loctype;
        -:   41:#endif
        -:   42:
        -:   43:
        -:   44:void MPIR_MAXLOC( 
        -:   45:	void *invec, 
        -:   46:	void *inoutvec, 
        -:   47:	int *Len, 
        -:   48:	MPI_Datatype *type )
     2892:   49:{
        -:   50:    static const char FCNAME[] = "MPIR_MAXLOC";
     2892:   51:    int i, len = *Len, flen;
        -:   52:    
     2892:   53:    flen = len * 2; /* used for Fortran types */
        -:   54:
     2892:   55:    switch (*type) {
        -:   56:    /* first the C types */
        -:   57:    case MPI_2INT: {
      493:   58:        MPIR_2int_loctype *a = (MPIR_2int_loctype *)inoutvec;
      493:   59:        MPIR_2int_loctype *b = (MPIR_2int_loctype *)invec;
   218884:   60:        for (i=0; i<len; i++) {
   218391:   61:            if (a[i].value == b[i].value)
        8:   62:                a[i].loc = MPIR_MIN(a[i].loc,b[i].loc);
   218383:   63:            else if (a[i].value < b[i].value) {
    94223:   64:                a[i].value = b[i].value;
    94223:   65:                a[i].loc   = b[i].loc;
        -:   66:            }
        -:   67:        }
        -:   68:        break;
        -:   69:    }
        -:   70:    case MPI_FLOAT_INT: {
      493:   71:        MPIR_floatint_loctype *a = (MPIR_floatint_loctype *)inoutvec;
      493:   72:        MPIR_floatint_loctype *b = (MPIR_floatint_loctype *)invec;
   218884:   73:        for (i=0; i<len; i++) {
   218391:   74:            if (a[i].value == b[i].value)
        8:   75:                a[i].loc = MPIR_MIN(a[i].loc,b[i].loc);
   218383:   76:            else if (a[i].value < b[i].value) {
    94223:   77:                a[i].value = b[i].value;
    94223:   78:                a[i].loc   = b[i].loc;
        -:   79:            }
        -:   80:        }
        -:   81:        break;
        -:   82:    }
        -:   83:    case MPI_LONG_INT: {
      493:   84:        MPIR_longint_loctype *a = (MPIR_longint_loctype *)inoutvec;
      493:   85:        MPIR_longint_loctype *b = (MPIR_longint_loctype *)invec;
   218884:   86:        for (i=0; i<len; i++) {
   218391:   87:            if (a[i].value == b[i].value)
        8:   88:                a[i].loc = MPIR_MIN(a[i].loc,b[i].loc);
   218383:   89:            else if (a[i].value < b[i].value) {
    94223:   90:                a[i].value = b[i].value;
    94223:   91:                a[i].loc   = b[i].loc;
        -:   92:            }
        -:   93:        }
        -:   94:        break;
        -:   95:    }
        -:   96:    case MPI_SHORT_INT: {
      493:   97:        MPIR_shortint_loctype *as = (MPIR_shortint_loctype *)inoutvec;
      493:   98:        MPIR_shortint_loctype *bs = (MPIR_shortint_loctype *)invec;
   218884:   99:        for (i=0; i<len; i++) {
   218391:  100:            if (as[i].value == bs[i].value)
        8:  101:                as[i].loc = MPIR_MIN(as[i].loc,bs[i].loc);
   218383:  102:            else if (as[i].value < bs[i].value) {
    94223:  103:                as[i].value = bs[i].value;
    94223:  104:                as[i].loc   = bs[i].loc;
        -:  105:            }
        -:  106:        }
        -:  107:        break;
        -:  108:    }
        -:  109:    case MPI_DOUBLE_INT: {
      472:  110:        MPIR_doubleint_loctype *a = (MPIR_doubleint_loctype *)inoutvec;
      472:  111:        MPIR_doubleint_loctype *b = (MPIR_doubleint_loctype *)invec;
   145891:  112:        for (i=0; i<len; i++) {
   145419:  113:            if (a[i].value == b[i].value)
       10:  114:                a[i].loc = MPIR_MIN(a[i].loc,b[i].loc);
   145409:  115:            else if (a[i].value < b[i].value) {
    62749:  116:                a[i].value = b[i].value;
    62749:  117:                a[i].loc   = b[i].loc;
        -:  118:            }
        -:  119:        }
        -:  120:        break;
        -:  121:    }
        -:  122:    
        -:  123:#if defined(HAVE_LONG_DOUBLE)
        -:  124:    case MPI_LONG_DOUBLE_INT: {
      448:  125:        MPIR_longdoubleint_loctype *a = (MPIR_longdoubleint_loctype *)inoutvec;
      448:  126:        MPIR_longdoubleint_loctype *b = (MPIR_longdoubleint_loctype *)invec;
   109519:  127:        for (i=0; i<len; i++) {
   109071:  128:            if (a[i].value == b[i].value)
        8:  129:                a[i].loc = MPIR_MIN(a[i].loc,b[i].loc);
   109063:  130:            else if (a[i].value < b[i].value) {
    47025:  131:                a[i].value = b[i].value;
    47025:  132:                a[i].loc   = b[i].loc;
        -:  133:            }
        -:  134:        }
        -:  135:        break;
        -:  136:    }
        -:  137:#endif
        -:  138:
        -:  139:    /* now the Fortran types */
        -:  140:#ifdef HAVE_FORTRAN_BINDING
        -:  141:#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:    }
        -:  178:#endif
        -:  179:#endif
        -:  180:	/* --BEGIN ERROR HANDLING-- */
        -:  181:    default: {
    #####:  182:	MPIU_THREADPRIV_DECL;
    #####:  183:	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" );
        -:  185:        break;
        -:  186:    }
        -:  187:	/* --END ERROR HANDLING-- */
        -:  188:    }
        -:  189:
     2892:  190:}
        -:  191:
        -:  192:
        -:  193:int MPIR_MAXLOC_check_dtype( MPI_Datatype type )
     4744:  194:{
        -:  195:    static const char FCNAME[] = "MPIR_MAXLOC_check_dtype";
     4744:  196:    switch (type) {
        -:  197:    /* first the C types */
        -:  198:    case MPI_2INT: 
        -:  199:    case MPI_FLOAT_INT: 
        -:  200:    case MPI_LONG_INT: 
        -:  201:    case MPI_SHORT_INT: 
        -:  202:    case MPI_DOUBLE_INT: 
        -:  203:#if defined(HAVE_LONG_DOUBLE)
        -:  204:    case MPI_LONG_DOUBLE_INT: 
        -:  205:#endif
        -:  206:    /* now the Fortran types */
        -:  207:#ifdef HAVE_FORTRAN_BINDING
        -:  208:#ifndef HAVE_NO_FORTRAN_MPI_TYPES_IN_C
        -:  209:    case MPI_2INTEGER: 
        -:  210:    case MPI_2REAL: 
        -:  211:    case MPI_2DOUBLE_PRECISION: 
        -:  212:#endif
        -:  213:#endif
     4738:  214:        return MPI_SUCCESS;
        -:  215:	/* --BEGIN ERROR HANDLING-- */
        -:  216:    default: 
        6:  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-- */
        -:  219:    }
        -:  220:}
        -:  221: