Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #3

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/turborvb-linter-build-test-gnu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:

- name: Test TurboRVB with ctest both serial and parallel versions
run: |
ctest --test-dir build --output-on-failure -j 2
ctest --test-dir build --output-on-failure
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ jobs:

- name: Test TurboRVB with ctest both serial and parallel versions
run: |
ctest --test-dir build --output-on-failure -j 2
ctest --test-dir build --output-on-failure
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,14 @@ if(EXT_MODTEST)
add_target_exe_serial_wrapper(test_zgetrf test_tools)
add_target_exe_serial_wrapper(test_dgetrfi test_tools)
add_target_exe_serial_wrapper(test_zgetrfi test_tools)
add_target_exe_serial_wrapper(test_zsktri test_tools)
add_target_exe_serial_wrapper(test_zsktrs test_tools)
add_target_exe_serial_wrapper(test_openmp_reduction_real test_tools)
add_target_exe_serial_wrapper(test_openmp_reduction_complex test_tools)
add_target_exe_serial_wrapper(test_upwinvp test_tools)
add_target_exe_serial_wrapper(test_upwinvp_complex test_tools)
#add_target_exe_serial_wrapper(test_upwinvp_pfaff test_tools)
#add_target_exe_serial_wrapper(test_upwinvp_pfaff_complex test_tools)

if(EXT_GPU)

Expand Down
38 changes: 38 additions & 0 deletions src/a_module_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,44 @@ foreach( EXECUTABLE IN LISTS EXECUTABLES_S_L
)
endif()

######################################################################
#
# Add sources and link libraries for zsktr[ri] wrapper tests
#

if(${EXECUTABLE} MATCHES test_zsktr[si])
set_target_properties( ${EXECUTABLE} PROPERTIES SUFFIX ".x")

target_sources( ${EXECUTABLE}
PRIVATE
${EXECUTABLE}.f90
)

target_link_libraries( ${EXECUTABLE}
PRIVATE
common-serial
)
endif()

######################################################################
#
# Add sources and link libraries for upwinvp wrapper tests
#

if(${EXECUTABLE} MATCHES test_upwinvp.*)
set_target_properties( ${EXECUTABLE} PROPERTIES SUFFIX ".x")

target_sources( ${EXECUTABLE}
PRIVATE
${EXECUTABLE}.f90
)

target_link_libraries( ${EXECUTABLE}
PRIVATE
common-serial
)
endif()

######################################################################
#
#
Expand Down
56 changes: 56 additions & 0 deletions src/a_module_tests/test_upwinvp.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
! Copyright (C) 2022 TurboRVB group
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.

program test_upwinvp
use constants, only: yes_ontarget
implicit none
integer, parameter :: nel = 3, indt = 4
real*8 :: psi(indt, nel, 2), ainv(nel), ainvn(nel), winv(nel, indt)
integer :: i, j, k
real*8, parameter :: eps = 1.0e-10 ! A small value for numerical comparison

yes_ontarget = .true.

! sleep to avoid unexpected corruptions.
call sleep(2)

! Initialize test data
winv = 0.0
do i = 1, indt
do j = 1, nel
do k = 1, 2
psi(i, j, k) = i*j*k
end do
end do
end do
ainv = (/1.0, 2.0, 3.0/)
ainvn = (/4.0, 5.0, 6.0/)

call upwinvp(nel, indt, winv, ainv, ainvn, psi)

! Check the result
do i = 1, indt
do j = 1, nel
if (abs(winv(j, i) - (ainv(j)*psi(i, j, 1) + ainvn(j)*psi(i, j, 2))) > eps) then
print *, "Test failed at i=", i, ", j=", j
print *, "ERROR"
stop 1
end if
end do
end do

print *, "OK"
print *, "All tests passed."
end program test_upwinvp
63 changes: 63 additions & 0 deletions src/a_module_tests/test_upwinvp_complex.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
! Copyright (C) 2022 TurboRVB group
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.

program test_upwinvp_complex
use constants, only: yes_ontarget
implicit none
integer, parameter :: nel = 3, indt = 4
complex*16 :: psi(indt, nel, 2), ainv(nel), ainvn(nel), winv(nel, indt), expected(nel, indt)
integer :: i, j, k
real*8, parameter :: eps = 1.0e-10 ! A small value for numerical comparison

yes_ontarget = .true.

! sleep to avoid unexpected corruptions.
call sleep(1)

! Initialize test data
winv = cmplx(0.0, 0.0)
do i = 1, indt
do j = 1, nel
do k = 1, 2
psi(i, j, k) = cmplx(i*j*k, i*j*k)
end do
end do
end do
ainv = (/cmplx(1.0, 1.0), cmplx(2.0, 2.0), cmplx(3.0, 3.0)/)
ainvn = (/cmplx(4.0, 4.0), cmplx(5.0, 5.0), cmplx(6.0, 6.0)/)

call upwinvp_complex(nel, indt, winv, ainv, ainvn, psi)

! Calculate expected result
do i = 1, indt
do j = 1, nel
expected(j, i) = ainv(j)*psi(i, j, 1) + ainvn(j)*psi(i, j, 2)
end do
end do

! Check the result
do i = 1, indt
do j = 1, nel
if (abs(winv(j, i) - expected(j, i)) > eps) then
print *, "Test failed at i=", i, ", j=", j
print *, "OK"
stop 1
end if
end do
end do

print *, "OK"
print *, "All tests passed."
end program test_upwinvp_complex
96 changes: 96 additions & 0 deletions src/a_module_tests/test_zsktri.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
! Copyright (C) 2022 TurboRVB group
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.

program test_zsktri
implicit none

complex*16, allocatable, dimension(:, :) :: A, A_inv, A_inv_orig
complex*16, allocatable, dimension(:) :: W
integer, allocatable, dimension(:) :: ipiv
real*8, allocatable, dimension(:, :) :: helper_r, helper_c
complex*16 :: one = 1.d0, zero = 0.d0
integer :: s, gen, ii, jj, info
character(len=1) :: uplo

! s dimension of the test matrix, s x s.
! uplo: U->upper triangular, L->lower triangular
! gen = 0 : Compare matrices, gen = 1 : Generate matrices
write (*, *) 's, uplo, gen'
read (*, *) s, uplo, gen

allocate (ipiv(s))
allocate (A(s, s))
allocate (A_inv(s, s))
allocate (A_inv_orig(s, s))
allocate (W(s**2 + 12*s - 2))
allocate (helper_r(s, s))
allocate (helper_c(s, s))

if (gen .eq. 1) then

! generate a skew_symmetric matrix A
call random_number(helper_r)
call random_number(helper_c)

do ii = 1, s
do jj = 1, ii - 1
helper_c(jj, ii) = -helper_c(ii, jj)
helper_r(jj, ii) = -helper_r(ii, jj)
end do
end do

do ii = 1, s
helper_r(ii, ii) = 0
helper_c(ii, ii) = 0
end do

A = cmplx(helper_r, helper_c)

else
open (unit=10, form="unformatted", file="A", action="read")
read (10) A
close (10)
open (unit=10, form="unformatted", file="A_inv_orig", action="read")
read (10) A_inv_orig
close (10)
end if

W = 0

do ii = 1, s
ipiv(ii) = ii
end do

call zsktri(uplo, s, A, s, A_inv, s, ipiv, W, info)

if (gen .eq. 1) then
open (unit=10, form="unformatted", file="A", action="write")
write (10) A
close (10)
open (unit=10, form="unformatted", file="A_inv_orig", action="write")
write (10) A_inv_orig
close (10)
else
A_inv = A_inv - A_inv_orig
if (maxval(abs(A_inv)) > 1.0d-10) then
print *, "ERROR"
else
print *, "OK"
end if
end if

deallocate (A, A_inv, A_inv_orig, W, helper_r, helper_c)

end program test_zsktri
77 changes: 77 additions & 0 deletions src/a_module_tests/test_zsktrs.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
! Copyright (C) 2022 TurboRVB group
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.

program test_zsktrs
implicit none

complex*16, allocatable, dimension(:, :) :: B, B_orig, X
complex*16, allocatable, dimension(:) :: A
real*8, allocatable, dimension(:) :: helper_r, helper_c
complex*16 :: one = 1.d0, zero = 0.d0
integer :: s, gen, ii, jj, info
character(len=1) :: uplo

! s dimension of the test matrix, s x s.
! uplo: U->upper triangular, L->lower triangular
! gen = 0 : Compare matrices, gen = 1 : Generate matrices
write (*, *) 's, uplo, gen'
read (*, *) s, uplo, gen

allocate (A(s - 1))
allocate (B(s, s))
allocate (B_orig(s, s))
allocate (X(s, s))
allocate (helper_r(s - 1))
allocate (helper_c(s - 1))

if (gen .eq. 1) then

! generate tridiagonal skewsymmetric matrix A
call random_number(helper_r)
call random_number(helper_c)
A = cmplx(helper_r, helper_c)

else
open (unit=10, form="unformatted", file="A", action="read")
read (10) A
close (10)
open (unit=10, form="unformatted", file="B_orig", action="read")
read (10) B_orig
close (10)
end if

X = 0

call zsktrs(uplo, s, s, A, B, s, X, info)

if (gen .eq. 1) then
open (unit=10, form="unformatted", file="A", action="write")
write (10) A
close (10)
open (unit=10, form="unformatted", file="B_orig", action="write")
write (10) B_orig
close (10)
else
B = B - B_orig
if (maxval(abs(B)) > 1.0d-10) then
print *, "ERROR"
else
print *, "OK"
end if
end if

deallocate (A, B, B_orig, X, helper_r, helper_c)

end program test_zsktrs
Loading
Loading