Skip to content

Commit a34b150

Browse files
authored
Merge pull request #160 from Parallel-NetCDF/misc_fix
Misc fix
2 parents f5269e0 + a704cc0 commit a34b150

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

src/drivers/common/error_mpi2nc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020

2121
/*----< ncmpii_error_mpi2nc() -----------------------------------------------*/
2222
/* translate MPI error codes to PnetCDF/netCDF error codes */
23-
int ncmpii_error_mpi2nc(int mpi_errorcode, /* returned value from MPI call */
24-
char *err_msg) /* extra error message */
23+
int ncmpii_error_mpi2nc(int mpi_errorcode, /* returned value from MPI call */
24+
const char *err_msg) /* extra error message */
2525
{
2626
int errorclass, errorStringLen;
2727
char errorString[MPI_MAX_ERROR_STRING];
28+
const char *dump_str = (err_msg == NULL) ? "" : err_msg;
2829

2930
/* check for specific error codes understood by PnetCDF */
3031

@@ -65,14 +66,13 @@ int ncmpii_error_mpi2nc(int mpi_errorcode, /* returned value from MPI call */
6566
*/
6667

6768
MPI_Error_string(mpi_errorcode, errorString, &errorStringLen);
68-
if (err_msg == NULL) err_msg = "";
6969
#ifdef PNETCDF_DEBUG
7070
/* report the world rank */
7171
int rank;
7272
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
73-
printf("rank %d: MPI error (%s) : %s\n", rank, err_msg, errorString);
73+
printf("rank %d: MPI error (%s) : %s\n", rank, dump_str, errorString);
7474
#else
75-
printf("MPI error (%s) : %s\n", err_msg, errorString);
75+
printf("MPI error (%s) : %s\n", dump_str, errorString);
7676
#endif
7777

7878
return NC_EFILE; /* other unknown file I/O error */

src/drivers/include/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ ncmpii_create_imaptype(int ndims, const MPI_Offset *count,
107107
MPI_Datatype *imaptype);
108108

109109
extern int
110-
ncmpii_error_mpi2nc(int mpi_errorcode, char *msg);
110+
ncmpii_error_mpi2nc(int mpi_errorcode, const char *msg);
111111

112112
extern int
113113
ncmpii_error_posix2nc(char *err_msg);

src/drivers/ncmpio/ncmpio_close.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,9 @@ ncmpio_close(void *ncdp)
190190
if (mpireturn == MPI_SUCCESS) {
191191
/* obtain file size */
192192
MPI_Offset *file_size;
193-
mpireturn = MPI_File_seek(fh, 0, MPI_SEEK_END);
193+
mpireturn = MPI_File_get_size(fh, &file_size);
194194
if (mpireturn != MPI_SUCCESS) {
195-
err = ncmpii_error_mpi2nc(mpireturn,"MPI_File_seek");
196-
if (status == NC_NOERR) status = err;
197-
}
198-
mpireturn = MPI_File_get_position(fh, &file_size);
199-
if (mpireturn != MPI_SUCCESS) {
200-
err = ncmpii_error_mpi2nc(mpireturn,"MPI_File_get_position");
195+
err = ncmpii_error_mpi2nc(mpireturn,"MPI_File_get_size");
201196
if (status == NC_NOERR) status = err;
202197
}
203198
/* truncate file size to header size, if larger than header */

test/testcases/flexible.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ int main(int argc, char **argv) {
135135
printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n",
136136
__FILE__,__LINE__,j,i,j+rank+10,buf[j][i]);
137137
nerrs++;
138+
j = NY;
138139
break;
139140
}
140141

@@ -147,6 +148,7 @@ int main(int argc, char **argv) {
147148
printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n",
148149
__FILE__,__LINE__,j,i,j+rank+10,buf[j][i]);
149150
nerrs++;
151+
j = NY;
150152
break;
151153
}
152154

@@ -169,10 +171,12 @@ int main(int argc, char **argv) {
169171
printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n",
170172
__FILE__,__LINE__,j,i,j+rank+10,schar_buf[j*NX+i]);
171173
nerrs++;
174+
j = NY;
172175
break;
173176
}
174177

175178
for (j=0; j<NY; j++) for (i=0; i<NX; i++) schar_buf[j*NX+i] = -1;
179+
176180
err = ncmpi_get_vara_all(ncid, varid3, start, count, schar_buf+NX, 1, buftype); CHECK_ERR
177181

178182
/* check read contents */
@@ -181,6 +185,7 @@ int main(int argc, char **argv) {
181185
printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n",
182186
__FILE__,__LINE__,j,i,j+rank+10,schar_buf[j*NX+i]);
183187
nerrs++;
188+
j = NY;
184189
break;
185190
}
186191

@@ -259,6 +264,7 @@ int main(int argc, char **argv) {
259264
printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n",
260265
__FILE__,__LINE__,j,i,buf[j][i],getValue);
261266
nerrs++;
267+
j = (int)count[0];
262268
break;
263269
}
264270
}
@@ -272,6 +278,7 @@ int main(int argc, char **argv) {
272278
printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n",
273279
__FILE__,__LINE__,j,i,buf[j][i],getValue);
274280
nerrs++;
281+
j = (int)count[0];
275282
break;
276283
}
277284
}
@@ -288,6 +295,7 @@ int main(int argc, char **argv) {
288295
printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n",
289296
__FILE__,__LINE__,j,i,buf[j][i],getValue);
290297
nerrs++;
298+
j = (int)count[0];
291299
break;
292300
}
293301
}
@@ -304,6 +312,7 @@ int main(int argc, char **argv) {
304312
printf("Error at %s line %d: expect buf[%d][%d]=%d but got %d\n",
305313
__FILE__,__LINE__,j,i,buf[j][i],getValue);
306314
nerrs++;
315+
j = (int)count[0];
307316
break;
308317
}
309318
}

test/testcases/test_vard_rec.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int main(int argc, char **argv) {
4545

4646
char filename[256];
4747
int i, j, err, nerrs=0, ncid, varid, dimids[2], unlimit_dimid;
48-
int rank, nprocs, array_of_blocklengths[2], buf[NY][NX];
48+
int rank, nprocs, verbose, array_of_blocklengths[2], buf[NY][NX];
4949
MPI_Offset recsize, len;
5050
MPI_Aint array_of_displacements[2];
5151
MPI_Datatype rec_filetype;
@@ -54,6 +54,8 @@ int main(int argc, char **argv) {
5454
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
5555
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
5656

57+
verbose = 0;
58+
5759
if (argc > 2) {
5860
if (!rank) printf("Usage: %s [filename]\n",argv[0]);
5961
MPI_Finalize();
@@ -94,6 +96,10 @@ int main(int argc, char **argv) {
9496
MPI_INT, &rec_filetype);
9597
MPI_Type_commit(&rec_filetype);
9698

99+
if (verbose)
100+
printf("%d: %s line %d: displacements=%ld blocklengths=%d\n",rank,
101+
__func__,__LINE__, array_of_displacements[0], array_of_blocklengths[0]);
102+
97103
/* write the record variable */
98104
err = ncmpi_put_vard_all(ncid, varid, rec_filetype, buf, NX, MPI_INT);
99105
CHECK_ERR
@@ -113,6 +119,10 @@ int main(int argc, char **argv) {
113119
MPI_INT, &rec_filetype);
114120
MPI_Type_commit(&rec_filetype);
115121

122+
if (verbose)
123+
printf("%d: %s line %d: displacements=%ld blocklengths=%d\n",rank,
124+
__func__,__LINE__, array_of_displacements[0], array_of_blocklengths[0]);
125+
116126
/* write the record variable */
117127
err = ncmpi_put_vard_all(ncid, varid, rec_filetype, buf[1], NX, MPI_INT);
118128
CHECK_ERR
@@ -142,6 +152,12 @@ int main(int argc, char **argv) {
142152
MPI_INT, &rec_filetype);
143153
MPI_Type_commit(&rec_filetype);
144154

155+
if (verbose)
156+
printf("%d: %s line %d: displacements=%ld %ld blocklengths=%d %d\n",rank,
157+
__func__,__LINE__,
158+
array_of_displacements[0], array_of_displacements[1],
159+
array_of_blocklengths[0], array_of_blocklengths[1]);
160+
145161
/* reset contents of buf before read */
146162
for (j=0; j<NY; j++) for (i=0; i<NX; i++) buf[j][i] = -1;
147163

test/testcases/tst_vars_fill.m4

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ test_vars_$1(char *filename)
5555
{
5656
char var_name[32];
5757
int i, j, k, nprocs, rank, err, nerrs=0, ncid, dimid[2], varid[NVARS];
58+
int max_nerrs;
5859
MPI_Offset start[2], count[2], stride[2];
5960
$1 buf[NY][NX];
6061

@@ -123,9 +124,11 @@ test_vars_$1(char *filename)
123124
}
124125
}
125126
}
127+
fn_exit:
128+
MPI_Allreduce(&nerrs, &max_nerrs, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
129+
if (max_nerrs > 0) break;
126130
}
127131

128-
fn_exit:
129132
err = ncmpi_close(ncid); CHECK_ERR
130133
return nerrs;
131134
}

0 commit comments

Comments
 (0)