Skip to content

Commit

Permalink
Move calls to MPI_Type_free before ncmpi_close
Browse files Browse the repository at this point in the history
  • Loading branch information
wkliao committed May 18, 2024
1 parent bccd432 commit 599bb92
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 27 deletions.
3 changes: 2 additions & 1 deletion examples/C/vard_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,11 @@ int main(int argc, char **argv) {
err = ncmpi_get_vard_all(ncid, varid0, rec_filetype, buf, bufcount,buftype);
ERR

err = ncmpi_close(ncid); ERR
MPI_Type_free(&rec_filetype);
MPI_Type_free(&fix_filetype);

err = ncmpi_close(ncid); ERR

nerrs += pnetcdf_check_mem_usage(MPI_COMM_WORLD);

MPI_Finalize();
Expand Down
6 changes: 3 additions & 3 deletions examples/CXX/vard_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ int main(int argc, char** argv)

/* read the fixed-size variable */
var1.getVard_all(fix_filetype, buf, bufcount, buftype);

MPI_Type_free(&rec_filetype);
MPI_Type_free(&fix_filetype);
}
catch(NcmpiException& e) {
cout << e.what() << " error code=" << e.errorCode() << " Error!\n";
return 1;
}

MPI_Type_free(&rec_filetype);
MPI_Type_free(&fix_filetype);

/* check if there is any PnetCDF internal malloc residue */
MPI_Offset malloc_size, sum_size;
int err = ncmpi_inq_malloc_size(&malloc_size);
Expand Down
6 changes: 3 additions & 3 deletions examples/F77/vard_int.f
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ program main
+ bufcount, buftype)
call check(err, 'In nfmpi_get_vard_all: ')

call MPI_Type_free(rec_filetype, err)
call MPI_Type_free(fix_filetype, err)

! close the file
err = nfmpi_close(ncid)
call check(err, 'In nfmpi_close: ')

call MPI_Type_free(rec_filetype, err)
call MPI_Type_free(fix_filetype, err)

! check if there is any PnetCDF internal malloc residue
998 format(A,I13,A)
err = nfmpi_inq_malloc_size(malloc_size)
Expand Down
6 changes: 3 additions & 3 deletions examples/F90/vard_int.f90
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ program main
bufcount, buftype)
call check(err, 'In nf90mpi_get_vard_all: ')

call MPI_Type_free(rec_filetype, err)
call MPI_Type_free(fix_filetype, err)

! close the file
err = nf90mpi_close(ncid)
call check(err, 'In nf90mpi_close: ')

call MPI_Type_free(rec_filetype, err)
call MPI_Type_free(fix_filetype, err)

! check if there is any PnetCDF internal malloc residue
998 format(A,I13,A)
err = nf90mpi_inq_malloc_size(malloc_size)
Expand Down
4 changes: 2 additions & 2 deletions test/largefile/large_reqs.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ int tst_vars(char *filename, MPI_Comm comm)
err = ncmpi_wait_all(ncid, NC_REQ_ALL, NULL, NULL);
CHECK_ERR

err = ncmpi_close(ncid); CHECK_ERR

MPI_Type_free(&buftype);

err = ncmpi_close(ncid); CHECK_ERR

free(varid);
free(buf);

Expand Down
4 changes: 2 additions & 2 deletions test/testcases/flexible_api.f
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ program main
err = nfmpi_wait_all(ncid, 1, req, st)
call check(err, 'In nfmpi_wait_all:')

call MPI_Type_free(subarray, err)

! close the file
err = nfmpi_close(ncid)
call check(err, 'In nfmpi_close: ')

call MPI_Type_free(subarray, err)

! check if there is any PnetCDF internal malloc residue
998 format(A,I13,A)
err = nfmpi_inq_malloc_size(malloc_size)
Expand Down
4 changes: 2 additions & 2 deletions test/testcases/flexible_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,10 @@ int main(int argc, char** argv)
/* check the contents of get buffer */
CHECK_GET_BUF(NY, NX, buf)

err = ncmpi_close(ncid); CHECK_ERROUT

MPI_Type_free(&subarray);

err = ncmpi_close(ncid); CHECK_ERROUT

/* check if PnetCDF freed all internal malloc */
MPI_Offset malloc_size, sum_size;
err = ncmpi_inq_malloc_size(&malloc_size);
Expand Down
4 changes: 2 additions & 2 deletions test/testcases/test_vard.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,6 @@ int main(int argc, char **argv) {
}
free(schar_buf);

err = ncmpi_close(ncid); CHECK_ERR

MPI_Type_free(&rec_filetype);
MPI_Type_free(&fix_filetype);
MPI_Type_free(&buftype);
Expand All @@ -500,6 +498,8 @@ int main(int argc, char **argv) {
free(flt_buf[0]); free(flt_buf);
free(dbl_buf[0]); free(dbl_buf);

err = ncmpi_close(ncid); CHECK_ERR

/* check if PnetCDF freed all internal malloc */
MPI_Offset malloc_size, sum_size;
err = ncmpi_inq_malloc_size(&malloc_size);
Expand Down
8 changes: 4 additions & 4 deletions test/testcases/test_vardf.F
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,15 @@ program main
call get_var_and_verify(ncid, varid1, NX,NY,start, count, buf,
+ buftype, ghost_buftype, fix_filetype, nerrs)

! close the file
err = nfmpi_close(ncid)
call check(err, 'In nfmpi_close: ')

call MPI_Type_free(rec_filetype, ierr)
call MPI_Type_free(fix_filetype, ierr)
call MPI_Type_free(buftype, ierr)
call MPI_Type_free(ghost_buftype, ierr)

! close the file
err = nfmpi_close(ncid)
call check(err, 'In nfmpi_close: ')

! check if there is any PnetCDF internal malloc residue
998 format(A,I13,A)
err = nfmpi_inq_malloc_size(malloc_size)
Expand Down
8 changes: 4 additions & 4 deletions test/testcases/test_vardf90.f90
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,15 @@ program main
call get_var_and_verify(ncid, varid1, NX,NY,start, count, buf, &
buftype, ghost_buftype, fix_filetype, nerrs)

! close the file
err = nf90mpi_close(ncid)
call check(err, 'In nf90mpi_close: ')

call MPI_Type_free(rec_filetype, ierr)
call MPI_Type_free(fix_filetype, ierr)
call MPI_Type_free(buftype, ierr)
call MPI_Type_free(ghost_buftype, ierr)

! close the file
err = nf90mpi_close(ncid)
call check(err, 'In nf90mpi_close: ')

! check if there is any PnetCDF internal malloc residue
998 format(A,I13,A)
err = nfmpi_inq_malloc_size(malloc_size)
Expand Down
4 changes: 3 additions & 1 deletion test/testcases/vectors.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ int main(int argc, char ** argv)
CHECK_ERR
err = ncmpi_get_vara(ncid, varid, &start, &acount, cmpbuf, 1, usertype);
CHECK_ERR

MPI_Type_free(&usertype);

err = ncmpi_close(ncid);
CHECK_ERR

Expand All @@ -116,7 +119,6 @@ int main(int argc, char ** argv)
nerrs += errs;
free(userbuf);
free(cmpbuf);
MPI_Type_free(&usertype);

/* check if PnetCDF freed all internal malloc */
MPI_Offset malloc_size, sum_size;
Expand Down

0 comments on commit 599bb92

Please sign in to comment.