Skip to content

Commit

Permalink
TestArrayGroup: add tests for integer and complex grid arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaas80 committed Aug 3, 2024
1 parent fad387d commit 5d8a9c9
Show file tree
Hide file tree
Showing 40 changed files with 690 additions and 451 deletions.
14 changes: 14 additions & 0 deletions TestArrayGroup/interface.ccl
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@ CCTK_REAL test_array[4] TYPE=array DIM=2 SIZE=5,6 DISTRIB=constant
CCTK_REAL test_gf TYPE=gf CENTERING={VVV} "Test grid function for verifying CarpetX implementation of DynamicData"

CCTK_REAL test_scalar TYPE=scalar "Test scalar for verifying CarpetX implementation of DynamicData"

CCTK_INT test_array_int[4] TYPE=array DIM=2 SIZE=5,6 DISTRIB=constant
{
test_int1 test_int2 test_int3
} "Test integer arrays for verifying CarpetX implementation of non-distributed array data"

CCTK_INT test_scalar_int TYPE=scalar "Test integer scalar for verifying CarpetX implementation of DynamicData"

CCTK_COMPLEX test_array_complex[4] TYPE=array DIM=2 SIZE=5,6 DISTRIB=constant
{
test_complex1 test_complex2 test_complex3
} "Test complex arrays for verifying CarpetX implementation of non-distributed array data"

CCTK_COMPLEX test_scalar_complex TYPE=scalar "Test complex scalar for verifying CarpetX implementation of DynamicData"
32 changes: 22 additions & 10 deletions TestArrayGroup/schedule.ccl
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
# Schedule definitions for thorn CarpetX

STORAGE: test_scalar test_array test_gf
STORAGE: test_scalar_int test_array_int
STORAGE: test_scalar_complex test_array_complex

SCHEDULE TestArrayGroup_Initialize AT Initial
{
LANG: C
WRITES: test_scalar(everywhere)
WRITES: test_array(everywhere)
WRITES: test_gf(everywhere)
WRITES: test_scalar(everywhere) test_array(everywhere) test_gf(everywhere)
WRITES: test_scalar_int(everywhere) test_array_int(everywhere)
WRITES: test_scalar_complex(everywhere) test_array_complex(everywhere)
} "Initialize data in grid functions, scalars, and distrib=const arrays"

SCHEDULE TestArrayGroup_Compare AT PostInitial
{
LANG: C
READS: test_scalar(everywhere)
READS: test_array(everywhere)
READS: test_gf(everywhere)
READS: test_scalar(everywhere) test_array(everywhere) test_gf(everywhere)
READS: test_scalar_int(everywhere) test_array_int(everywhere)
READS: test_scalar_complex(everywhere) test_array_complex(everywhere)
} "Test data in grid functions, scalars, and distrib=const arrays"

SCHEDULE TestArrayGroup_CompareF AT PostInitial
{
LANG: Fortran
# no local support so far
OPTION: global
READS: test_scalar(everywhere)
READS: test_array(everywhere)
READS: test_scalar(everywhere) test_array(everywhere)
READS: test_scalar_int(everywhere) test_array_int(everywhere)
READS: test_scalar_complex(everywhere) test_array_complex(everywhere)
} "Test data in grid scalars and distrib=const arrays"

SCHEDULE TestArrayGroup_DynamicData AT PostInitial
Expand All @@ -35,6 +40,13 @@ SCHEDULE TestArrayGroup_DynamicDataF AT PostInitial
LANG: Fortran
# no local support so far
OPTION: global
READS: test_scalar(everywhere)
READS: test_array(everywhere)
READS: test_scalar(everywhere) test_array(everywhere)
READS: test_scalar_int(everywhere) test_array_int(everywhere)
READS: test_scalar_complex(everywhere) test_array_complex(everywhere)
} "Test DynamicData for Fortran scalars, and distrib=const arrays"

SCHEDULE TestArrayGroup_Terminate AT Terminate
{
LANG: C
OPTION: meta
} "Set exit code based on test results"
90 changes: 60 additions & 30 deletions TestArrayGroup/src/TestArray.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,84 @@ subroutine TestArrayGroup_CompareF(CCTK_ARGUMENTS)
integer, parameter :: nmax = 4
integer, parameter :: size = imax * jmax * nmax

integer :: array_error_count(3)
integer :: scalar_error_count
integer :: array_real_error_count(3)
integer :: array_int_error_count(3)
integer :: array_complex_error_count(3)

integer :: i,j,n
character*256 :: warnline

array_error_count = (/0,0,0/)
array_real_error_count = (/0,0,0/)
array_int_error_count = (/0,0,0/)
array_complex_error_count = (/0,0,0/)
do n = 1,nmax
do j = 1,jmax
do i = 1,imax
! -1 is due to data being filled by C code counting from 0
if (test1(i,j,n) /= 1 + (i-1) * (j-1) * (n-1)) then
array_error_count(1) = array_error_count(1) + 1
if (test1(i,j,n) /= 1 + i * j * n) then
array_real_error_count(1) = array_real_error_count(1) + 1
end if
if (test2(i,j,n) /= 1 + 7 * (i-1) * (j-1) * (n-1)) then
array_error_count(2) = array_error_count(2) + 1
if (test_int1(i,j,n) /= 2 + i * j * n) then
array_int_error_count(1) = array_int_error_count(1) + 1
end if
if (test3(i,j,n) /= 1 + 13 * (i-1) * (j-1) * (n-1)) then
array_error_count(3) = array_error_count(3) + 1
if (test_complex1(i,j,n) /= CMPLX(3 + i * j * n, 1, KIND(test_complex1(1,1,1)))) then
array_complex_error_count(1) = array_complex_error_count(1) + 1
end if
if (test2(i,j,n) /= 1 + 7 * i * j * n) then
array_real_error_count(2) = array_real_error_count(2) + 1
end if
if (test_int2(i,j,n) /= 2 + 7 * i * j * n) then
array_int_error_count(2) = array_int_error_count(2) + 1
end if
if (test_complex2(i,j,n) /= CMPLX(3 + 7 * i * j * n, 1, KIND(test_complex2(1,1,1)))) then
array_complex_error_count(2) = array_complex_error_count(2) + 1
end if
if (test3(i,j,n) /= 1 + 13 * i * j * n) then
array_real_error_count(3) = array_real_error_count(3) + 1
end if
if (test_int3(i,j,n) /= 2 + 13 * i * j * n) then
array_int_error_count(3) = array_int_error_count(3) + 1
end if
if (test_complex3(i,j,n) /= CMPLX(3 + 13 * i * j * n, 1, KIND(test_complex3(1,1,1)))) then
array_complex_error_count(3) = array_complex_error_count(3) + 1
end if
end do
end do
end do

if (array_error_count(1) > 0) then
write(warnline, "('TestArrayGroup: Fortran grid array test1 failed in ', i3, ' of ', i3, ' elements')") array_error_count(1), size
call CCTK_ERROR(warnline)
end if

if (array_error_count(2) > 0) then
write(warnline, "('TestArrayGroup: Fortran grid array test2 failed in ', i3, ' of ', i3, ' elements')") array_error_count(2), size
call CCTK_ERROR(warnline)
end if

if (array_error_count(3) > 0) then
write(warnline, "('TestArrayGroup: Fortran grid array test3 failed in ', i3, ' of ', i3, ' elements')") array_error_count(3), size
call CCTK_ERROR(warnline)
end if
do i = 1,3
if (array_real_error_count(i) > 0) then
write(warnline, "('TestArrayGroup: Fortran CCTK_REAL grid array test', i1, ' failed in ', i3, ' of ', i3, ' elements')") i, array_real_error_count(i), size
call CCTK_WARN(CCTK_WARN_ALERT, warnline)
call TestArrayGroup_FoundError()
end if
end do
do i = 1,3
if (array_int_error_count(i) > 0) then
write(warnline, "('TestArrayGroup: Fortran CCTK_INT grid array test', i1, ' failed in ', i3, ' of ', i3, ' elements')") i, array_int_error_count(i), size
call CCTK_WARN(CCTK_WARN_ALERT, warnline)
call TestArrayGroup_FoundError()
end if
end do
do i = 1,3
if (array_complex_error_count(i) > 0) then
write(warnline, "('TestArrayGroup: Fortran CCTK_COMPLEX grid array test', i1, ' failed in ', i3, ' of ', i3, ' elements')") i, array_complex_error_count(i), size
call CCTK_WARN(CCTK_WARN_ALERT, warnline)
call TestArrayGroup_FoundError()
end if
end do

! test grid scalar
scalar_error_count = 0

if(test_scalar /= 1) then
scalar_error_count = scalar_error_count + 1
call CCTK_WARN(CCTK_WARN_ALERT, "TestArrayGroup: CCTK_REAL grid scalar failed")
call TestArrayGroup_FoundError()
end if

if (scalar_error_count > 0) then
write(warnline, "('TestArrayGroup: Fortran grid scalr test_scalar failed in ', i3, ' of ', i3, ' elements')") scalar_error_count, 1
call CCTK_ERROR(warnline)
if(test_scalar_int /= 2) then
call CCTK_WARN(CCTK_WARN_ALERT, "TestArrayGroup: CCTK_INT grid scalar failed")
call TestArrayGroup_FoundError()
end if
if(test_scalar_complex /= 3) then
call CCTK_WARN(CCTK_WARN_ALERT, "TestArrayGroup: CCTK_COMPLEX grid scalar failed")
call TestArrayGroup_FoundError()
end if
end subroutine TestArrayGroup_CompareF
Loading

0 comments on commit 5d8a9c9

Please sign in to comment.