Skip to content

Commit

Permalink
Merge pull request #160 from Parallel-NetCDF/misc_fix
Browse files Browse the repository at this point in the history
Misc fix
  • Loading branch information
wkliao authored Nov 26, 2024
2 parents f5269e0 + a704cc0 commit a34b150
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/drivers/common/error_mpi2nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 2 additions & 7 deletions src/drivers/ncmpio/ncmpio_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 9 additions & 0 deletions test/testcases/flexible.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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<NY; j++) for (i=0; i<NX; i++) schar_buf[j*NX+i] = -1;

err = ncmpi_get_vara_all(ncid, varid3, start, count, schar_buf+NX, 1, buftype); CHECK_ERR

/* check read contents */
Expand All @@ -181,6 +185,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,schar_buf[j*NX+i]);
nerrs++;
j = NY;
break;
}

Expand Down Expand Up @@ -259,6 +264,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,buf[j][i],getValue);
nerrs++;
j = (int)count[0];
break;
}
}
Expand All @@ -272,6 +278,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,buf[j][i],getValue);
nerrs++;
j = (int)count[0];
break;
}
}
Expand All @@ -288,6 +295,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,buf[j][i],getValue);
nerrs++;
j = (int)count[0];
break;
}
}
Expand All @@ -304,6 +312,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,buf[j][i],getValue);
nerrs++;
j = (int)count[0];
break;
}
}
Expand Down
18 changes: 17 additions & 1 deletion test/testcases/test_vard_rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<NY; j++) for (i=0; i<NX; i++) buf[j][i] = -1;

Expand Down
5 changes: 4 additions & 1 deletion test/testcases/tst_vars_fill.m4
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test_vars_$1(char *filename)
{
char var_name[32];
int i, j, k, nprocs, rank, err, nerrs=0, ncid, dimid[2], varid[NVARS];
int max_nerrs;
MPI_Offset start[2], count[2], stride[2];
$1 buf[NY][NX];

Expand Down Expand Up @@ -123,9 +124,11 @@ test_vars_$1(char *filename)
}
}
}
fn_exit:
MPI_Allreduce(&nerrs, &max_nerrs, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
if (max_nerrs > 0) break;
}

fn_exit:
err = ncmpi_close(ncid); CHECK_ERR
return nerrs;
}
Expand Down

0 comments on commit a34b150

Please sign in to comment.