[mpich] MPICH primary repository branch, master, updated. v3.2a1-4-g96c1107
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "MPICH primary repository". The branch, master has been updated via 96c1107031f89b02dd3b4360862ddf98b8d5f43e (commit) from c99d3467e2d96ecfd143921740eaa60cec222494 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://git.mpich.org/mpich.git/commitdiff/96c1107031f89b02dd3b4360862ddf98b8... commit 96c1107031f89b02dd3b4360862ddf98b8d5f43e Author: Junchao Zhang <[email protected]> Date: Fri Sep 5 14:17:15 2014 -0500 Fix switch(datatype) kind of errors In MPI, the predefined named constant handles like MPI_INT are link-time but not necessarily compile-time constants, so they should not be used in switch/case clauses. If you do so, this kind of code only compiles with MPICH but not OpenMPI. Fixes #2169, #2171 Signed-off-by: Rob Latham <[email protected]> diff --git a/src/env/mpivars.c b/src/env/mpivars.c index 080aedd..91e21aa 100644 --- a/src/env/mpivars.c +++ b/src/env/mpivars.c @@ -468,33 +468,25 @@ int getCvarValueAsStr( int idx, MPI_Datatype datatype, MPI_T_cvar_handle_alloc( idx, NULL, &chandle, &count ); if (count == 1 || (datatype==MPI_CHAR && count < varValueLen)) { - switch (datatype) { - case MPI_INT: + if (MPI_INT == datatype) { MPI_T_cvar_read( chandle, &ival ); snprintf( varValue, varValueLen, "%d", ival ); hasValue = 1; - break; - case MPI_UNSIGNED: + } else if (MPI_UNSIGNED == datatype) { MPI_T_cvar_read( chandle, &uval ); snprintf( varValue, varValueLen, "%u", uval ); hasValue = 1; - break; - case MPI_UNSIGNED_LONG: + } else if (MPI_UNSIGNED_LONG == datatype) { MPI_T_cvar_read( chandle, &ulval ); snprintf( varValue, varValueLen, "%lu", ulval ); hasValue = 1; - break; - case MPI_UNSIGNED_LONG_LONG: + } else if (MPI_UNSIGNED_LONG_LONG == datatype) { MPI_T_cvar_read( chandle, &ullval ); snprintf( varValue, varValueLen, "%llu", ullval ); hasValue = 1; - break; - case MPI_CHAR: + } else if (MPI_CHAR == datatype) { MPI_T_cvar_read( chandle, varValue ); hasValue = 1; - break; - default: - break; } } MPI_T_cvar_handle_free( &chandle ); @@ -534,38 +526,29 @@ int getPvarValueAsStr( int idx, MPI_Datatype datatype, int isContinuous, goto fn_fail; } } - switch (datatype) { - case MPI_INT: + if (MPI_INT == datatype) { MPI_T_pvar_read( session, phandle, &ival ); snprintf( varValue, varValueLen, "%d", ival ); hasValue = 1; - break; - case MPI_UNSIGNED: + } else if (MPI_UNSIGNED == datatype) { MPI_T_pvar_read( session, phandle, &uval ); snprintf( varValue, varValueLen, "%u", uval ); hasValue = 1; - break; - case MPI_UNSIGNED_LONG: + } else if (MPI_UNSIGNED_LONG == datatype) { MPI_T_pvar_read( session, phandle, &ulval ); snprintf( varValue, varValueLen, "%lu", ulval ); hasValue = 1; - break; - case MPI_UNSIGNED_LONG_LONG: + } else if (MPI_UNSIGNED_LONG_LONG == datatype) { MPI_T_pvar_read( session, phandle, &ullval ); snprintf( varValue, varValueLen, "%llu", ullval ); hasValue = 1; - break; - case MPI_DOUBLE: + } else if (MPI_DOUBLE == datatype) { MPI_T_pvar_read( session, phandle, &dval ); snprintf( varValue, varValueLen, "%e", dval ); hasValue = 1; - break; - case MPI_CHAR: + } else if (MPI_CHAR == datatype) { MPI_T_pvar_read( session, phandle, varValue ); hasValue = 1; - break; - default: - break; } } fn_fail: diff --git a/test/mpi/mpi_t/cvarwrite.c b/test/mpi/mpi_t/cvarwrite.c index aaf84d2..41d0b29 100644 --- a/test/mpi/mpi_t/cvarwrite.c +++ b/test/mpi/mpi_t/cvarwrite.c @@ -45,55 +45,47 @@ int main(int argc, char* argv[]) MPI_T_cvar_handle_alloc(i, NULL, &chandle, &count); if (count == 1 || (datatype == MPI_CHAR && count < sizeof(cin))) { - switch (datatype) { - case MPI_INT: - iin = 123; - iout = 456; - MPI_T_cvar_read(chandle, &iold); /* Read the old value */ - MPI_T_cvar_write(chandle, &iin); /* Write an arbitrary value */ - MPI_T_cvar_read(chandle, &iout); /* Read the value again */ - MPI_T_cvar_write(chandle, &iold); /* Restore the old value */ - if (iin != iout) errs++; - break; - case MPI_UNSIGNED: - uin = 133; - uout = 986; - MPI_T_cvar_read(chandle, &uold); - MPI_T_cvar_write(chandle, &uin); - MPI_T_cvar_read(chandle, &uout); - MPI_T_cvar_write(chandle, &uold); - if (uin != uout) errs++; - break; - case MPI_UNSIGNED_LONG: - ulin = 1830; - ulout = 2014; - MPI_T_cvar_read(chandle, &ulold); - MPI_T_cvar_write(chandle, &ulin); - MPI_T_cvar_read(chandle, &ulout); - MPI_T_cvar_write(chandle, &ulold); - if (ulin != ulout) errs++; - break; - case MPI_UNSIGNED_LONG_LONG: - ullin = 11930; - ullout = 52014; - MPI_T_cvar_read(chandle, &ullold); - MPI_T_cvar_write(chandle, &ullin); - MPI_T_cvar_read(chandle, &ullout); - MPI_T_cvar_write(chandle, &ullold); - if (ullin != ullout) errs++; - break; - case MPI_CHAR: - strcpy(cin, "GARBAGE MPI_CHAR CVAR VALUE"); - strcpy(cout, "TEMPORARY MPI_CHAR CVAR VALUE"); - MPI_T_cvar_read(chandle, cold); - MPI_T_cvar_write(chandle, cin); - MPI_T_cvar_read(chandle, cout); - MPI_T_cvar_write(chandle, cold); - /* printf("%s = %s\n", name, cold); */ - if (strcmp(cin, cout)) errs++; - break; - default: - break; + if (MPI_INT == datatype) { + iin = 123; + iout = 456; + MPI_T_cvar_read(chandle, &iold); /* Read the old value */ + MPI_T_cvar_write(chandle, &iin); /* Write an arbitrary value */ + MPI_T_cvar_read(chandle, &iout); /* Read the value again */ + MPI_T_cvar_write(chandle, &iold); /* Restore the old value */ + if (iin != iout) errs++; + } else if (MPI_UNSIGNED == datatype) { + uin = 133; + uout = 986; + MPI_T_cvar_read(chandle, &uold); + MPI_T_cvar_write(chandle, &uin); + MPI_T_cvar_read(chandle, &uout); + MPI_T_cvar_write(chandle, &uold); + if (uin != uout) errs++; + } else if (MPI_UNSIGNED_LONG == datatype) { + ulin = 1830; + ulout = 2014; + MPI_T_cvar_read(chandle, &ulold); + MPI_T_cvar_write(chandle, &ulin); + MPI_T_cvar_read(chandle, &ulout); + MPI_T_cvar_write(chandle, &ulold); + if (ulin != ulout) errs++; + } else if (MPI_UNSIGNED_LONG_LONG == datatype) { + ullin = 11930; + ullout = 52014; + MPI_T_cvar_read(chandle, &ullold); + MPI_T_cvar_write(chandle, &ullin); + MPI_T_cvar_read(chandle, &ullout); + MPI_T_cvar_write(chandle, &ullold); + if (ullin != ullout) errs++; + } else if (MPI_CHAR == datatype) { + strcpy(cin, "GARBAGE MPI_CHAR CVAR VALUE"); + strcpy(cout, "TEMPORARY MPI_CHAR CVAR VALUE"); + MPI_T_cvar_read(chandle, cold); + MPI_T_cvar_write(chandle, cin); + MPI_T_cvar_read(chandle, cout); + MPI_T_cvar_write(chandle, cold); + /* printf("%s = %s\n", name, cold); */ + if (strcmp(cin, cout)) errs++; } } ----------------------------------------------------------------------- Summary of changes: src/env/mpivars.c | 39 +++++-------------- test/mpi/mpi_t/cvarwrite.c | 90 ++++++++++++++++++++------------------------ 2 files changed, 52 insertions(+), 77 deletions(-) hooks/post-receive -- MPICH primary repository
participants (1)
-
noreply@mpich.org