From 2d732625e1fdea69b2041378beed282b54945161 Mon Sep 17 00:00:00 2001 From: Wei-keng Liao Date: Thu, 14 Nov 2024 16:48:27 -0600 Subject: [PATCH 1/4] Call MPI_File_get_size to get current file size No need to call MPI_File_seek(fh, 0, MPI_SEEK_END); --- src/drivers/ncmpio/ncmpio_close.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/drivers/ncmpio/ncmpio_close.c b/src/drivers/ncmpio/ncmpio_close.c index 0f2dff772..c3cf33977 100644 --- a/src/drivers/ncmpio/ncmpio_close.c +++ b/src/drivers/ncmpio/ncmpio_close.c @@ -190,14 +190,9 @@ ncmpio_close(void *ncdp) if (mpireturn == MPI_SUCCESS) { /* obtain file size */ MPI_Offset *file_size; - mpireturn = MPI_File_seek(fh, 0, MPI_SEEK_END); + mpireturn = MPI_File_get_size(fh, &file_size); if (mpireturn != MPI_SUCCESS) { - err = ncmpii_error_mpi2nc(mpireturn,"MPI_File_seek"); - if (status == NC_NOERR) status = err; - } - mpireturn = MPI_File_get_position(fh, &file_size); - if (mpireturn != MPI_SUCCESS) { - err = ncmpii_error_mpi2nc(mpireturn,"MPI_File_get_position"); + err = ncmpii_error_mpi2nc(mpireturn,"MPI_File_get_size"); if (status == NC_NOERR) status = err; } /* truncate file size to header size, if larger than header */ From 30834bce24f61ea60f629c2c9045e287353aaae7 Mon Sep 17 00:00:00 2001 From: Wei-keng Liao Date: Thu, 14 Nov 2024 16:50:43 -0600 Subject: [PATCH 2/4] add const type qualifier to argument err_msg Contents of argument err_msg is not modified --- src/drivers/common/error_mpi2nc.c | 10 +++++----- src/drivers/include/common.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/drivers/common/error_mpi2nc.c b/src/drivers/common/error_mpi2nc.c index af4b79a76..2d4f3981c 100644 --- a/src/drivers/common/error_mpi2nc.c +++ b/src/drivers/common/error_mpi2nc.c @@ -20,11 +20,12 @@ /*----< ncmpii_error_mpi2nc() -----------------------------------------------*/ /* translate MPI error codes to PnetCDF/netCDF error codes */ -int ncmpii_error_mpi2nc(int mpi_errorcode, /* returned value from MPI call */ - char *err_msg) /* extra error message */ +int ncmpii_error_mpi2nc(int mpi_errorcode, /* returned value from MPI call */ + const char *err_msg) /* extra error message */ { int errorclass, errorStringLen; char errorString[MPI_MAX_ERROR_STRING]; + const char *dump_str = (err_msg == NULL) ? "" : err_msg; /* check for specific error codes understood by PnetCDF */ @@ -65,14 +66,13 @@ int ncmpii_error_mpi2nc(int mpi_errorcode, /* returned value from MPI call */ */ MPI_Error_string(mpi_errorcode, errorString, &errorStringLen); - if (err_msg == NULL) err_msg = ""; #ifdef PNETCDF_DEBUG /* report the world rank */ int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - printf("rank %d: MPI error (%s) : %s\n", rank, err_msg, errorString); + printf("rank %d: MPI error (%s) : %s\n", rank, dump_str, errorString); #else - printf("MPI error (%s) : %s\n", err_msg, errorString); + printf("MPI error (%s) : %s\n", dump_str, errorString); #endif return NC_EFILE; /* other unknown file I/O error */ diff --git a/src/drivers/include/common.h b/src/drivers/include/common.h index 4f6d4f953..8e3d30aa3 100644 --- a/src/drivers/include/common.h +++ b/src/drivers/include/common.h @@ -107,7 +107,7 @@ ncmpii_create_imaptype(int ndims, const MPI_Offset *count, MPI_Datatype *imaptype); extern int -ncmpii_error_mpi2nc(int mpi_errorcode, char *msg); +ncmpii_error_mpi2nc(int mpi_errorcode, const char *msg); extern int ncmpii_error_posix2nc(char *err_msg); From a6fe2f1f6b52dcb79cce196ab75d19710fc145d6 Mon Sep 17 00:00:00 2001 From: wkliao Date: Mon, 25 Nov 2024 17:22:18 -0600 Subject: [PATCH 3/4] break loop when encountering first error stop checking collectively when error occurs in one of processes break 2nd loop when encountering first error --- test/testcases/flexible.c | 9 +++++++++ test/testcases/tst_vars_fill.m4 | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/test/testcases/flexible.c b/test/testcases/flexible.c index 2e5cf9e9b..8655af319 100644 --- a/test/testcases/flexible.c +++ b/test/testcases/flexible.c @@ -135,6 +135,7 @@ int main(int argc, char **argv) { printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n", __FILE__,__LINE__,j,i,j+rank+10,buf[j][i]); nerrs++; + j = NY; break; } @@ -147,6 +148,7 @@ int main(int argc, char **argv) { printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n", __FILE__,__LINE__,j,i,j+rank+10,buf[j][i]); nerrs++; + j = NY; break; } @@ -169,10 +171,12 @@ int main(int argc, char **argv) { printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n", __FILE__,__LINE__,j,i,j+rank+10,schar_buf[j*NX+i]); nerrs++; + j = NY; break; } for (j=0; j 0) break; } -fn_exit: err = ncmpi_close(ncid); CHECK_ERR return nerrs; } From a704cc08e7bd71b49ed648a430f54e8d5abffa56 Mon Sep 17 00:00:00 2001 From: wkliao Date: Mon, 25 Nov 2024 17:22:42 -0600 Subject: [PATCH 4/4] test_vard_rec.c: add verbose mode --- test/testcases/test_vard_rec.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/testcases/test_vard_rec.c b/test/testcases/test_vard_rec.c index 39d6ad5ec..4a74b1cc2 100644 --- a/test/testcases/test_vard_rec.c +++ b/test/testcases/test_vard_rec.c @@ -45,7 +45,7 @@ int main(int argc, char **argv) { char filename[256]; int i, j, err, nerrs=0, ncid, varid, dimids[2], unlimit_dimid; - int rank, nprocs, array_of_blocklengths[2], buf[NY][NX]; + int rank, nprocs, verbose, array_of_blocklengths[2], buf[NY][NX]; MPI_Offset recsize, len; MPI_Aint array_of_displacements[2]; MPI_Datatype rec_filetype; @@ -54,6 +54,8 @@ int main(int argc, char **argv) { MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); + verbose = 0; + if (argc > 2) { if (!rank) printf("Usage: %s [filename]\n",argv[0]); MPI_Finalize(); @@ -94,6 +96,10 @@ int main(int argc, char **argv) { MPI_INT, &rec_filetype); MPI_Type_commit(&rec_filetype); + if (verbose) + printf("%d: %s line %d: displacements=%ld blocklengths=%d\n",rank, + __func__,__LINE__, array_of_displacements[0], array_of_blocklengths[0]); + /* write the record variable */ err = ncmpi_put_vard_all(ncid, varid, rec_filetype, buf, NX, MPI_INT); CHECK_ERR @@ -113,6 +119,10 @@ int main(int argc, char **argv) { MPI_INT, &rec_filetype); MPI_Type_commit(&rec_filetype); + if (verbose) + printf("%d: %s line %d: displacements=%ld blocklengths=%d\n",rank, + __func__,__LINE__, array_of_displacements[0], array_of_blocklengths[0]); + /* write the record variable */ err = ncmpi_put_vard_all(ncid, varid, rec_filetype, buf[1], NX, MPI_INT); CHECK_ERR @@ -142,6 +152,12 @@ int main(int argc, char **argv) { MPI_INT, &rec_filetype); MPI_Type_commit(&rec_filetype); + if (verbose) + printf("%d: %s line %d: displacements=%ld %ld blocklengths=%d %d\n",rank, + __func__,__LINE__, + array_of_displacements[0], array_of_displacements[1], + array_of_blocklengths[0], array_of_blocklengths[1]); + /* reset contents of buf before read */ for (j=0; j