Skip to content

Commit

Permalink
Start of ctest for mpifx
Browse files Browse the repository at this point in the history
  • Loading branch information
bhourahine committed Nov 7, 2020
1 parent c7cd859 commit 0f92dd8
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 17 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ include(GNUInstallDirs)

add_subdirectory(lib)
if(NOT BUILD_EXPORTED_TARGETS_ONLY)
enable_testing()
add_subdirectory(test)
endif()

Expand Down
27 changes: 24 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
set(targets
set(tested
test_allgather
test_allgatherv
)
set(targets
test_allreduce
test_bcast
test_comm_split
test_gather
test_gatherv
test_reduce
test_scatter
test_scatterv)
test_scatterv
)
list(APPEND targets ${tested})

foreach(target IN LISTS targets)
add_executable(${target} ${target}.f90)
add_executable(${target} ${target}.f90 testhelper.f90)
target_link_libraries(${target} MpiFx)
endforeach()

foreach(target IN LISTS tested)
add_test(NAME ${target}
COMMAND ${MPIEXEC_EXECUTABLE}
${MPIEXEC_NUMPROC_FLAG}
${MPIEXEC_MAX_NUMPROCS}
${MPIEXEC_PREFLAGS}
${CMAKE_CURRENT_BINARY_DIR}/${target}
${MPIEXEC_POSTFLAGS}
)
set_tests_properties(${target} PROPERTIES
PASS_REGULAR_EXPRESSION "TestPASSED"
)
set_tests_properties(${target} PROPERTIES
FAIL_REGULAR_EXPRESSION "TestFAILED"
)
endforeach()
43 changes: 29 additions & 14 deletions test/test_allgather.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
!> Test various patterns of allgather
program test_allgather
use libmpifx_module
use testhelper
implicit none

type(mpifx_comm) :: mycomm
Expand All @@ -8,6 +10,7 @@ program test_allgather
integer, allocatable :: recv1(:), recv2(:,:)
character(100) :: formstr
character(*), parameter :: label = "(I2.2,'-',I3.3,'|',1X"
logical :: tPassed

call mpifx_init()
call mycomm%init()
Expand All @@ -16,12 +19,16 @@ program test_allgather
send0 = mycomm%rank * 2
allocate(recv1(1 * mycomm%size))
recv1(:) = 0
write(*, label // ",A,1X,I0)") 1, mycomm%rank, &
& "Send0 buffer:", send0
write(*, label // ",A,1X,I0)") 1, mycomm%rank, "Send0 buffer:", send0
call mpifx_allgather(mycomm, send0, recv1)
write(formstr, "(A,I0,A)") "A,", size(recv1), "(1X,I0))"
write(*, label // formstr) 2, mycomm%rank, &
& "Recv1 buffer:", recv1(:)
write(*, label // formstr) 2, mycomm%rank, "Recv1 buffer:", recv1(:)
if (sum(recv1) /= mycomm%size * (mycomm%size-1)) then
tPassed = .false.
else
tPassed = .true.
end if
call testReturn(mycomm, tPassed)
deallocate(recv1)

! I1 -> I1
Expand All @@ -30,25 +37,33 @@ program test_allgather
recv1(:) = 0
send1(:) = [ mycomm%rank, mycomm%rank + 1 ]
write(formstr, "(A,I0,A)") "A,", size(send1), "(1X,I0))"
write(*, label // formstr) 3, mycomm%rank, &
& "Send1 buffer:", send1(:)
write(*, label // formstr) 3, mycomm%rank, "Send1 buffer:", send1(:)
call mpifx_allgather(mycomm, send1, recv1)
write(formstr, "(A,I0,A)") "A,", size(recv1), "(1X,I0))"
write(*, label // formstr) 4, mycomm%rank, &
& "Recv1 buffer:", recv1
write(*, label // formstr) 4, mycomm%rank, "Recv1 buffer:", recv1
if (sum(recv1) /= mycomm%size**2) then
tPassed = .false.
else
tPassed = .true.
end if
call testReturn(mycomm, tPassed)

! I1 -> I2
allocate(recv2(size(send1), mycomm%size))
recv2(:,:) = 0
send1(:) = [ mycomm%rank, mycomm%rank + 1 ]
write(formstr, "(A,I0,A)") "A,", size(send1), "(1X,I0))"
write(*, label // formstr) 5, mycomm%rank, &
& "Send1 buffer:", send1(:)
write(*, label // formstr) 5, mycomm%rank, "Send1 buffer:", send1(:)
call mpifx_allgather(mycomm, send1, recv2)
write(formstr, "(A,I0,A)") "A,", size(recv2), "(1X,I0))"
write(*, label // formstr) 6, mycomm%rank, &
& "Recv2 buffer:", recv2

write(*, label // formstr) 6, mycomm%rank, "Recv2 buffer:", recv2
if (sum(recv1) /= mycomm%size**2) then
tPassed = .false.
else
tPassed = .true.
end if
call testReturn(mycomm, tPassed)

call mpifx_finalize()

end program test_allgather
14 changes: 14 additions & 0 deletions test/test_allgatherv.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
!> Test various patterns of allgatherv
program test_allgatherv
use libmpifx_module
use testhelper
implicit none

type(mpifx_comm) :: mycomm
Expand All @@ -12,6 +14,8 @@ program test_allgatherv
integer :: ii, nrecv, nCol
character(100) :: formstr
character(*), parameter :: label = "(I2.2,'-',I3.3,'|',1X"
logical :: tPassed
integer :: iCount

call mpifx_init()
call mycomm%init()
Expand All @@ -33,6 +37,16 @@ program test_allgatherv
if (mycomm%rank == mycomm%size - 1) then
write(*, *) "Recv1 buffer:", recv1
end if
iCount = 0
do ii = 1, mycomm%size
iCount = iCount + ii**2
end do
if (nint(sum(recv1)) /= iCount) then
tPassed = .false.
else
tPassed = .true.
end if
call testReturn(mycomm, tPassed)
deallocate(recvcounts)
deallocate(recv1)

Expand Down
36 changes: 36 additions & 0 deletions test/testhelper.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
!> Helper routines for testers
module testhelper
use libmpifx_module, only : mpifx_comm, mpifx_barrier, mpifx_finalize
implicit none

private
public :: testReturn

contains

!> Return expected labels for ctest
subroutine testReturn(mycomm, tPassed)

type(mpifx_comm), intent(in) :: mycomm

logical, intent(in) :: tPassed

call mpifx_barrier(mycomm)

if (tPassed) then
if (mycomm%rank == 0) then
! label for ctest regex
write(*,*)'TestPASSED'
end if
else
if (mycomm%rank == 0) then
! label for ctest regex
write(*,*)'TestFAILED'
end if
call mpifx_finalize()
stop
end if

end subroutine testReturn

end module testhelper

0 comments on commit 0f92dd8

Please sign in to comment.