| 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 | void MPIR_MINLOC( |
|---|
| 44 | void *invec, |
|---|
| 45 | void *inoutvec, |
|---|
| 46 | int *Len, |
|---|
| 47 | MPI_Datatype *type ) |
|---|
| 48 | { |
|---|
| 49 | static const char FCNAME[] = "MPIR_MINLOC"; |
|---|
| 50 | int i, len = *Len, flen; |
|---|
| 51 | |
|---|
| 52 | flen = len * 2; /* used for Fortran types */ |
|---|
| 53 | |
|---|
| 54 | switch (*type) { |
|---|
| 55 | /* 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 | } |
|---|
| 121 | #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 | } |
|---|
| 135 | #endif |
|---|
| 136 | |
|---|
| 137 | /* now the Fortran types */ |
|---|
| 138 | #ifdef HAVE_FORTRAN_BINDING |
|---|
| 139 | #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 | } |
|---|
| 176 | #endif |
|---|
| 177 | #endif |
|---|
| 178 | /* --BEGIN ERROR HANDLING-- */ |
|---|
| 179 | default: { |
|---|
| 180 | MPIU_THREADPRIV_DECL; |
|---|
| 181 | 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" ); |
|---|
| 183 | break; |
|---|
| 184 | } |
|---|
| 185 | /* --END ERROR HANDLING-- */ |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | int MPIR_MINLOC_check_dtype( MPI_Datatype type ) |
|---|
| 191 | { |
|---|
| 192 | static const char FCNAME[] = "MPIR_MINLOC_check_dtype"; |
|---|
| 193 | |
|---|
| 194 | switch (type) { |
|---|
| 195 | /* first the C types */ |
|---|
| 196 | case MPI_2INT: |
|---|
| 197 | case MPI_FLOAT_INT: |
|---|
| 198 | case MPI_LONG_INT: |
|---|
| 199 | case MPI_SHORT_INT: |
|---|
| 200 | case MPI_DOUBLE_INT: |
|---|
| 201 | #if defined(HAVE_LONG_DOUBLE) |
|---|
| 202 | case MPI_LONG_DOUBLE_INT: |
|---|
| 203 | #endif |
|---|
| 204 | /* now the Fortran types */ |
|---|
| 205 | #ifdef HAVE_FORTRAN_BINDING |
|---|
| 206 | #ifndef HAVE_NO_FORTRAN_MPI_TYPES_IN_C |
|---|
| 207 | case MPI_2INTEGER: |
|---|
| 208 | case MPI_2REAL: |
|---|
| 209 | case MPI_2DOUBLE_PRECISION: |
|---|
| 210 | #endif |
|---|
| 211 | #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-- */ |
|---|
| 217 | } |
|---|
| 218 | } |
|---|