326 lines
11 KiB
Fortran
326 lines
11 KiB
Fortran
program test_external_request
|
|
use fem_precision
|
|
use fem_error
|
|
use fem_sparse_csr
|
|
use fem_sparse_csr_diagnostics
|
|
use fem_linsol_ext_request
|
|
implicit none
|
|
|
|
real(rk), parameter :: TOL = 1.0e-10_rk
|
|
|
|
call check_ready_spd()
|
|
call check_general_capability()
|
|
call check_nonsquare_policy()
|
|
call check_unavailable_backend()
|
|
call check_error_paths()
|
|
|
|
contains
|
|
|
|
subroutine check_ready_spd()
|
|
type(csr_matrix) :: a
|
|
type(external_solver_request) :: request
|
|
real(rk) :: b(3)
|
|
real(rk) :: x(3)
|
|
integer :: row0(4)
|
|
integer :: col0(7)
|
|
real(rk) :: vals(7)
|
|
integer :: valid
|
|
integer :: ready
|
|
integer :: backend
|
|
integer :: nrow
|
|
integer :: ncol
|
|
integer :: nnz
|
|
integer :: class_id
|
|
integer :: status
|
|
integer :: reason
|
|
real(rk) :: matrix_norm
|
|
real(rk) :: rhs_norm
|
|
real(rk) :: initial_resid
|
|
real(rk) :: initial_rel
|
|
character(len=32) :: name
|
|
integer :: ierr
|
|
|
|
call build_spd(a)
|
|
b = (/ ONE, ZERO, ONE /)
|
|
x = ZERO
|
|
call external_request_build(a, b, x, 11, 0, 1, 1, &
|
|
EXT_REQ_CAP_DIRECT + EXT_REQ_CAP_SPD, request, ierr)
|
|
call require_success(ierr, 10)
|
|
|
|
if (request%valid .ne. 1) call fail(11)
|
|
if (request%ready .ne. 1) call fail(12)
|
|
if (request%backend_compatible .ne. 1) call fail(13)
|
|
if (request%exportable .ne. 1) call fail(14)
|
|
if (request%status .ne. EXT_REQ_STATUS_READY) call fail(15)
|
|
if (request%reason .ne. EXT_REQ_REASON_NONE) call fail(16)
|
|
if (request%profile%class_id .ne. CSR_CLASS_SPD_CAND) call fail(17)
|
|
call check_close(request%matrix_norm, 4.0_rk, 18)
|
|
call check_close(request%rhs_norm, sqrt(2.0_rk), 19)
|
|
call check_close(request%initial_resid, sqrt(2.0_rk), 20)
|
|
call check_close(request%initial_rel, ONE, 21)
|
|
call check_close(request%x_norm, ZERO, 22)
|
|
|
|
call external_request_summary(request, valid, ready, backend, nrow, ncol, &
|
|
nnz, class_id, status, reason, matrix_norm, &
|
|
rhs_norm, initial_resid, initial_rel, ierr)
|
|
call require_success(ierr, 23)
|
|
if (valid .ne. 1 .or. ready .ne. 1) call fail(24)
|
|
if (backend .ne. 11) call fail(25)
|
|
if (nrow .ne. 3 .or. ncol .ne. 3 .or. nnz .ne. 7) call fail(26)
|
|
if (class_id .ne. CSR_CLASS_SPD_CAND) call fail(27)
|
|
if (status .ne. EXT_REQ_STATUS_READY) call fail(28)
|
|
if (reason .ne. EXT_REQ_REASON_NONE) call fail(29)
|
|
call check_close(matrix_norm, request%matrix_norm, 30)
|
|
call check_close(rhs_norm, request%rhs_norm, 31)
|
|
call check_close(initial_resid, request%initial_resid, 32)
|
|
call check_close(initial_rel, request%initial_rel, 33)
|
|
|
|
call external_request_export(a, request, row0, col0, vals, ierr)
|
|
call require_success(ierr, 34)
|
|
call check_int_array(row0, (/ 0, 2, 5, 7 /), 35)
|
|
call check_int_array(col0, (/ 0, 1, 0, 1, 2, 1, 2 /), 36)
|
|
call check_close(vals(1), 2.0_rk, 37)
|
|
call check_close(vals(2), -ONE, 38)
|
|
call check_close(vals(7), 2.0_rk, 39)
|
|
|
|
call external_request_status_name(request%status, name, ierr)
|
|
call require_success(ierr, 40)
|
|
if (trim(name) .ne. 'ready') call fail(41)
|
|
call external_request_reason_name(request%reason, name, ierr)
|
|
call require_success(ierr, 42)
|
|
if (trim(name) .ne. 'none') call fail(43)
|
|
|
|
call csr_free(a, ierr)
|
|
call require_success(ierr, 44)
|
|
end subroutine check_ready_spd
|
|
|
|
subroutine check_general_capability()
|
|
type(csr_matrix) :: a
|
|
type(external_solver_request) :: request
|
|
real(rk) :: b(2)
|
|
real(rk) :: x(2)
|
|
integer :: ready
|
|
integer :: status
|
|
integer :: reason
|
|
integer :: ierr
|
|
|
|
call build_general(a)
|
|
b = (/ ONE, 2.0_rk /)
|
|
x = ZERO
|
|
|
|
call external_request_build(a, b, x, 12, 1, 1, 1, &
|
|
EXT_REQ_CAP_SPD, request, ierr)
|
|
call require_success(ierr, 50)
|
|
if (request%valid .ne. 1) call fail(51)
|
|
if (request%ready .ne. 0) call fail(52)
|
|
if (request%status .ne. EXT_REQ_STATUS_INCOMPATIBLE) call fail(53)
|
|
if (request%reason .ne. EXT_REQ_REASON_CAPABILITY) call fail(54)
|
|
if (request%profile%class_id .ne. CSR_CLASS_GENERAL) call fail(55)
|
|
|
|
call external_request_ready(request, ready, status, reason, ierr)
|
|
call require_success(ierr, 56)
|
|
if (ready .ne. 0) call fail(57)
|
|
if (status .ne. EXT_REQ_STATUS_INCOMPATIBLE) call fail(58)
|
|
if (reason .ne. EXT_REQ_REASON_CAPABILITY) call fail(59)
|
|
|
|
call external_request_build(a, b, x, 12, 1, 1, 1, &
|
|
EXT_REQ_CAP_DIRECT + EXT_REQ_CAP_GENERAL, request, ierr)
|
|
call require_success(ierr, 60)
|
|
if (request%ready .ne. 1) call fail(61)
|
|
if (request%status .ne. EXT_REQ_STATUS_READY) call fail(62)
|
|
if (request%reason .ne. EXT_REQ_REASON_NONE) call fail(63)
|
|
call check_close(request%matrix_norm, 4.0_rk, 64)
|
|
call check_close(request%initial_resid, sqrt(5.0_rk), 65)
|
|
|
|
call csr_free(a, ierr)
|
|
call require_success(ierr, 66)
|
|
end subroutine check_general_capability
|
|
|
|
subroutine check_nonsquare_policy()
|
|
type(csr_matrix) :: a
|
|
type(external_solver_request) :: request
|
|
real(rk) :: b(2)
|
|
real(rk) :: x(3)
|
|
integer :: compatible
|
|
integer :: status
|
|
integer :: reason
|
|
integer :: ierr
|
|
|
|
call build_nonsquare(a)
|
|
b = (/ ONE, -ONE /)
|
|
x = ZERO
|
|
|
|
call external_request_build(a, b, x, 13, 0, 1, 1, &
|
|
EXT_REQ_CAP_DIRECT + EXT_REQ_CAP_GENERAL, request, ierr)
|
|
call require_success(ierr, 70)
|
|
if (request%valid .ne. 1) call fail(71)
|
|
if (request%ready .ne. 0) call fail(72)
|
|
if (request%status .ne. EXT_REQ_STATUS_INCOMPATIBLE) call fail(73)
|
|
if (request%reason .ne. EXT_REQ_REASON_NON_SQUARE) call fail(74)
|
|
if (request%profile%square .ne. 0) call fail(75)
|
|
|
|
call external_request_compatible(request%profile, 0, 1, &
|
|
EXT_REQ_CAP_GENERAL, compatible, status, reason, ierr)
|
|
call require_success(ierr, 76)
|
|
if (compatible .ne. 1) call fail(77)
|
|
if (status .ne. EXT_REQ_STATUS_READY) call fail(78)
|
|
if (reason .ne. EXT_REQ_REASON_NONE) call fail(79)
|
|
|
|
call external_request_build(a, b, x, 13, 0, 0, 1, &
|
|
EXT_REQ_CAP_DIRECT + EXT_REQ_CAP_GENERAL, request, ierr)
|
|
call require_success(ierr, 80)
|
|
if (request%ready .ne. 1) call fail(81)
|
|
call check_close(request%rhs_norm, sqrt(2.0_rk), 82)
|
|
|
|
call csr_free(a, ierr)
|
|
call require_success(ierr, 83)
|
|
end subroutine check_nonsquare_policy
|
|
|
|
subroutine check_unavailable_backend()
|
|
type(csr_matrix) :: a
|
|
type(external_solver_request) :: request
|
|
real(rk) :: b(3)
|
|
real(rk) :: x(3)
|
|
integer :: ready
|
|
integer :: status
|
|
integer :: reason
|
|
character(len=32) :: name
|
|
integer :: ierr
|
|
|
|
call build_spd(a)
|
|
b = (/ ZERO, ZERO, ONE /)
|
|
x = (/ ONE, ONE, ONE /)
|
|
|
|
call external_request_build(a, b, x, 14, 0, 1, 0, &
|
|
EXT_REQ_CAP_DIRECT + EXT_REQ_CAP_SPD, request, ierr)
|
|
call require_success(ierr, 90)
|
|
if (request%valid .ne. 1) call fail(91)
|
|
if (request%ready .ne. 0) call fail(92)
|
|
if (request%backend_available .ne. 0) call fail(93)
|
|
if (request%status .ne. EXT_REQ_STATUS_INCOMPATIBLE) call fail(94)
|
|
if (request%reason .ne. EXT_REQ_REASON_NO_BACKEND) call fail(95)
|
|
if (request%initial_resid .le. ZERO) call fail(96)
|
|
|
|
call external_request_ready(request, ready, status, reason, ierr)
|
|
call require_success(ierr, 97)
|
|
if (ready .ne. 0) call fail(98)
|
|
if (status .ne. EXT_REQ_STATUS_INCOMPATIBLE) call fail(99)
|
|
if (reason .ne. EXT_REQ_REASON_NO_BACKEND) call fail(100)
|
|
|
|
call external_request_status_name(status, name, ierr)
|
|
call require_success(ierr, 101)
|
|
if (trim(name) .ne. 'incompatible') call fail(102)
|
|
call external_request_reason_name(reason, name, ierr)
|
|
call require_success(ierr, 103)
|
|
if (trim(name) .ne. 'backend_unavailable') call fail(104)
|
|
|
|
call csr_free(a, ierr)
|
|
call require_success(ierr, 105)
|
|
end subroutine check_unavailable_backend
|
|
|
|
subroutine check_error_paths()
|
|
type(csr_matrix) :: a
|
|
type(external_solver_request) :: request
|
|
real(rk) :: b2(2)
|
|
real(rk) :: b3(3)
|
|
real(rk) :: x3(3)
|
|
integer :: row0(4)
|
|
integer :: col0(7)
|
|
real(rk) :: vals(7)
|
|
character(len=16) :: name
|
|
integer :: ierr
|
|
|
|
call build_spd(a)
|
|
b2 = ONE
|
|
b3 = ONE
|
|
x3 = ZERO
|
|
|
|
call external_request_build(a, b3, x3, 15, 2, 1, 1, &
|
|
EXT_REQ_CAP_GENERAL, request, ierr)
|
|
if (ierr .eq. FEM_SUCCESS) call fail(110)
|
|
if (request%status .ne. EXT_REQ_STATUS_INVALID) call fail(111)
|
|
if (request%reason .ne. EXT_REQ_REASON_INDEX_BASE) call fail(112)
|
|
|
|
call external_request_build(a, b2, x3, 15, 0, 1, 1, &
|
|
EXT_REQ_CAP_GENERAL, request, ierr)
|
|
if (ierr .eq. FEM_SUCCESS) call fail(113)
|
|
if (request%status .ne. EXT_REQ_STATUS_INVALID) call fail(114)
|
|
if (request%reason .ne. EXT_REQ_REASON_VECTOR_SIZE) call fail(115)
|
|
|
|
call external_request_reset(request)
|
|
call external_request_export(a, request, row0, col0, vals, ierr)
|
|
if (ierr .eq. FEM_SUCCESS) call fail(116)
|
|
|
|
call external_request_status_name(777, name, ierr)
|
|
if (ierr .eq. FEM_SUCCESS) call fail(117)
|
|
call external_request_reason_name(777, name, ierr)
|
|
if (ierr .eq. FEM_SUCCESS) call fail(118)
|
|
|
|
call csr_free(a, ierr)
|
|
call require_success(ierr, 119)
|
|
end subroutine check_error_paths
|
|
|
|
subroutine build_spd(a)
|
|
type(csr_matrix), intent(inout) :: a
|
|
integer :: ierr
|
|
|
|
call csr_create_pattern(a, 3, 3, (/ 1, 3, 6, 8 /), &
|
|
(/ 1, 2, 1, 2, 3, 2, 3 /), ierr)
|
|
call require_success(ierr, 200)
|
|
a%val = (/ 2.0_rk, -ONE, -ONE, 2.0_rk, -ONE, -ONE, 2.0_rk /)
|
|
end subroutine build_spd
|
|
|
|
subroutine build_general(a)
|
|
type(csr_matrix), intent(inout) :: a
|
|
integer :: ierr
|
|
|
|
call csr_create_pattern(a, 2, 2, (/ 1, 3, 4 /), (/ 1, 2, 2 /), ierr)
|
|
call require_success(ierr, 210)
|
|
a%val = (/ ONE, 2.0_rk, 4.0_rk /)
|
|
end subroutine build_general
|
|
|
|
subroutine build_nonsquare(a)
|
|
type(csr_matrix), intent(inout) :: a
|
|
integer :: ierr
|
|
|
|
call csr_create_pattern(a, 2, 3, (/ 1, 3, 4 /), (/ 1, 3, 2 /), ierr)
|
|
call require_success(ierr, 220)
|
|
a%val = (/ 2.0_rk, -ONE, 3.0_rk /)
|
|
end subroutine build_nonsquare
|
|
|
|
subroutine check_int_array(actual, expected, code)
|
|
integer, intent(in) :: actual(:)
|
|
integer, intent(in) :: expected(:)
|
|
integer, intent(in) :: code
|
|
integer :: i
|
|
|
|
if (size(actual) .ne. size(expected)) call fail(code)
|
|
do i = 1, size(actual)
|
|
if (actual(i) .ne. expected(i)) call fail(code)
|
|
end do
|
|
end subroutine check_int_array
|
|
|
|
subroutine check_close(actual, expected, code)
|
|
real(rk), intent(in) :: actual
|
|
real(rk), intent(in) :: expected
|
|
integer, intent(in) :: code
|
|
|
|
if (abs(actual - expected) .gt. TOL) call fail(code)
|
|
end subroutine check_close
|
|
|
|
subroutine require_success(ierr, code)
|
|
integer, intent(in) :: ierr
|
|
integer, intent(in) :: code
|
|
|
|
if (ierr .ne. FEM_SUCCESS) call fail(code)
|
|
end subroutine require_success
|
|
|
|
subroutine fail(code)
|
|
integer, intent(in) :: code
|
|
|
|
print *, 'test_external_request failure', code
|
|
stop 1
|
|
end subroutine fail
|
|
|
|
end program test_external_request
|