Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Feb 15, 2018
1 parent dd18710 commit d5ba0b3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 28 deletions.
46 changes: 28 additions & 18 deletions src/clib/pio_darray_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,13 @@ int write_darray_multi_par(file_desc_t *file, int nvars, int fndims, const int *
size_t count[fndims];
int ndims = iodesc->ndims;
#if USE_VARD
MPI_Aint displacements[num_regions];
MPI_Aint displacements[num_regions], final_displacements[num_regions];
int blocklengths[num_regions];
int mpierr;
MPI_Datatype filetype;
MPI_Datatype subarray[num_regions];
int sacount[ndims];
int sastart[ndims];
filetype = MPI_DATATYPE_NULL;
#else
PIO_Offset *startlist[num_regions]; /* Array of start arrays for ncmpi_iput_varn(). */
Expand Down Expand Up @@ -254,10 +258,6 @@ int write_darray_multi_par(file_desc_t *file, int nvars, int fndims, const int *
for (int i = 0; i < fndims; i++)
dsize *= count[i];
LOG((3, "dsize = %d", dsize));
#if USE_VARD
blocklengths[rrcnt] = 0;
displacements[rrcnt] = 0;
#endif
/* For pnetcdf's ncmpi_iput_varn() function, we need
* to provide arrays of arrays for start/count. */
if (dsize > 0)
Expand All @@ -268,11 +268,20 @@ int write_darray_multi_par(file_desc_t *file, int nvars, int fndims, const int *
{
gcount[i] = iodesc->dimlen[i];
lcoord[i] = start[i+(fndims-ndims)];
LOG((3, ": gcount[%d]=%ld lcoord[%d]=%ld",i,gcount[i],i,lcoord[i]));
sacount[i] = (int) count[i+(fndims-ndims)];
sastart[i] = (int) start[i+(fndims-ndims)];
LOG((3, "vard: sastart[%d]=%d sacount[%d]=%d", i, sastart[i], i, sacount[i]));
}
blocklengths[rrcnt] = dsize;
blocklengths[rrcnt] = 1;
displacements[rrcnt] = coord_to_lindex(ndims, lcoord, gcount) * iodesc->mpitype_size;
LOG((3, "%d: ndims=%d displacements[%d]=%ld",ios->union_rank, ndims,rrcnt,displacements[rrcnt]));

if((mpierr = MPI_Type_create_subarray(ndims, iodesc->dimlen,
sacount, sastart,MPI_ORDER_C
,iodesc->mpitype, subarray+rrcnt)))
return check_mpi(NULL, mpierr, __FILE__, __LINE__);

if((mpierr = MPI_Type_commit(subarray+rrcnt)))
return check_mpi(NULL, mpierr, __FILE__, __LINE__);
#else
/* Allocate storage for start/count arrays for
* this region. */
Expand Down Expand Up @@ -307,7 +316,6 @@ int write_darray_multi_par(file_desc_t *file, int nvars, int fndims, const int *
* the record dimension. */
#if USE_VARD
if(nv==0 || (nv > 0 && frame != NULL && frame[nv] != frame[nv-1])){
MPI_Aint final_displacements[num_regions];
PIO_Offset unlimdimoffset;
int mpierr;
if(filetype != MPI_DATATYPE_NULL)
Expand All @@ -322,14 +330,13 @@ int write_darray_multi_par(file_desc_t *file, int nvars, int fndims, const int *
else
unlimdimoffset = 0;

for( int rc=0; rc<rrcnt; rc++)
final_displacements[rc] = unlimdimoffset + displacements[rc];
for (int rc=0; rc < rrcnt; rc++)
LOG((3,"%d: rc=%d blocklength=%d displacement=%ld final_displacement=%ld unlimdimoffset=%ld size=%d llen=%d\n", ios->union_rank,rc,
blocklengths[rc], displacements[rc], final_displacements[rc], unlimdimoffset, iodesc->mpitype_size, llen));

if((mpierr = MPI_Type_create_hindexed(rrcnt, blocklengths, final_displacements, iodesc->mpitype, &filetype)))
for( int rc=0; rc<rrcnt; rc++){
final_displacements[rc] = unlimdimoffset;
LOG((3,"vard: blocklengths[%d]=%d displacement[%d]=%ld",rc,blocklengths[rc], rc, final_displacements[rc]));
}
if((mpierr = MPI_Type_create_struct(rrcnt, blocklengths, final_displacements, subarray, &filetype)))
return check_mpi(NULL, mpierr, __FILE__, __LINE__);

if((mpierr = MPI_Type_commit(&filetype)))
return check_mpi(NULL, mpierr, __FILE__, __LINE__);
}
Expand All @@ -355,9 +362,9 @@ int write_darray_multi_par(file_desc_t *file, int nvars, int fndims, const int *
LOG((3, "about to call ncmpi_iput_varn() varids[%d] = %d rrcnt = %d, llen = %d",
nv, varids[nv], rrcnt, llen));
#if USE_VARD
LOG((3, "call ncmpi_put_vard llen = %d", llen));
LOG((3, "vard: call ncmpi_put_vard llen = %d ", llen));
ierr = ncmpi_put_vard_all(file->fh, varids[nv], filetype, bufptr, llen, iodesc->mpitype);
LOG((3, "return ncmpi_put_vard ierr = %d", ierr));
LOG((3, "vard: return ncmpi_put_vard ierr = %d", ierr));
#else
ierr = ncmpi_iput_varn(file->fh, varids[nv], rrcnt, startlist, countlist,
bufptr, llen, iodesc->mpitype, &vdesc->request[vdesc->nreqs]);
Expand Down Expand Up @@ -392,6 +399,9 @@ int write_darray_multi_par(file_desc_t *file, int nvars, int fndims, const int *
if(filetype != MPI_DATATYPE_NULL)
{
int mpierr;
for(int i=0; i<rrcnt; i++)
if((mpierr = MPI_Type_free(subarray+i)))
return check_mpi(NULL, mpierr, __FILE__, __LINE__);
if((mpierr = MPI_Type_free(&filetype)))
return check_mpi(NULL, mpierr, __FILE__, __LINE__);
}
Expand Down
19 changes: 15 additions & 4 deletions tests/unit/basic_tests.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module basic_tests

use pio
use pio
use global_vars

Implicit None
Expand Down Expand Up @@ -53,7 +53,7 @@ Subroutine test_create(test_id, err_msg)
err_msg = "Could not create " // trim(filename)
call mpi_abort(MPI_COMM_WORLD, 0, ret_val2)
end if

call mpi_barrier(mpi_comm_world,ret_val)
! netcdf files need to end define mode before closing
if (is_netcdf(iotype)) then
Expand Down Expand Up @@ -215,6 +215,16 @@ Subroutine test_open(test_id, err_msg)
call mpi_abort(MPI_COMM_WORLD, 0, ret_val2)
end if

ret_val = PIO_put_att(pio_file, pio_var, '_FillValue', -1)
if (ret_val .ne. PIO_NOERR) then
! Error in PIO_def_var
err_msg = "Could not define _FillValue attribute"
call PIO_closefile(pio_file)
call mpi_abort(MPI_COMM_WORLD, 0, ret_val2)
end if



! Leave define mode
ret_val = PIO_enddef(pio_file)
if (ret_val .ne. PIO_NOERR) then
Expand Down Expand Up @@ -290,11 +300,11 @@ Subroutine test_open(test_id, err_msg)
call mpi_abort(MPI_COMM_WORLD, 0, ret_val2)
end if
ret_val = PIO_set_log_level(0)

! Close file
call PIO_closefile(pio_file)
end if

call mpi_barrier(MPI_COMM_WORLD,ret_val)

! Try to open standard binary file as netcdf (if iotype = netcdf)
Expand All @@ -304,6 +314,7 @@ Subroutine test_open(test_id, err_msg)

ret_val = PIO_openfile(pio_iosystem, pio_file, iotype, &
"not_netcdf.ieee", PIO_nowrite)

if (ret_val.eq.PIO_NOERR) then
! Error in PIO_openfile
err_msg = "Opened a non-netcdf file as netcdf"
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Program pio_unit_test_driver

! local variables
character(len=str_len) :: err_msg
integer :: fail_cnt, test_cnt, ios, test_id, ierr, test_val
integer :: fail_cnt, test_cnt, ios, test_id, ierr, test_val
logical :: ltest_netcdf, ltest_pnetcdf
logical :: ltest_netcdf4p, ltest_netcdf4c
namelist/piotest_nml/ ltest_netcdf, &
Expand All @@ -26,7 +26,7 @@ Program pio_unit_test_driver
integer ret_val
character(len=pio_max_name) :: errmsg
character(len=pio_max_name) :: expected

! Set up MPI
call MPI_Init(ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, my_rank, ierr)
Expand Down Expand Up @@ -63,7 +63,7 @@ Program pio_unit_test_driver

! Ignore namelist values if PIO not built with correct options
! (i.e. don't test pnetcdf if not built with pnetcdf)
ret_val = PIO_set_log_level(2)

#ifndef _NETCDF
if (ltest_netcdf) then
write(*,"(A,1x,A)") "WARNING: can not test netcdf files because PIO", &
Expand Down Expand Up @@ -132,7 +132,7 @@ Program pio_unit_test_driver
print *, err_msg
call parse(err_msg, fail_cnt)
end if

do test_id=1,ntest
if (ltest(test_id)) then
! Make sure i is a valid test number
Expand All @@ -154,7 +154,7 @@ Program pio_unit_test_driver
write(*,"(A,I0)") "Error, not configured for test #", test_id
call MPI_Abort(MPI_COMM_WORLD, 0, ierr)
end select

! test_create()
if (master_task) write(*,"(3x,A,1x)") "testing PIO_createfile..."
call test_create(test_id, err_msg)
Expand Down Expand Up @@ -209,7 +209,7 @@ Program pio_unit_test_driver
call MPI_Finalize(ierr)
if(fail_cnt>0) then
stop 1
else
else
stop 0
endif
Contains
Expand Down

0 comments on commit d5ba0b3

Please sign in to comment.