Debian Codegraph @

gcc/testsuite/gfortran.target/riscv/rvv/pr118182.f

raw
1 ! { dg-do run }
2 ! { dg-options "-fno-vect-cost-model" }
3
4 program dqnorm_calculator
5 implicit none
6
7 ! Declare variables
8 integer, parameter :: nx = 33, ny = 33, nz =16
9 real(8) :: dq(5, nx, ny, nz)
10 real(8) :: result, expected_result, tolerance
11 integer :: i, j, k, l
12
13 ! Initialize the dq array with values calculated as k + j + i + 5
14 do k = 1, nz
15 do j = 1, ny
16 do i = 1, nx
17 do l = 1, 5
18 dq(l, i, j, k) = k + j + i + 5
19 end do
20 end do
21 end do
22 end do
23
24 ! Call the subroutine to calculate the norm
25 call redsum(dq, nx, ny, nz, result)
26
27 ! Check the result
28 expected_result = 214213560.0d0
29 tolerance = 0.0001d0
30 if (abs(result - expected_result) > tolerance) then
31 print *, "Result is incorrect: ", result
32 call abort()
33 end if
34 end
35
36 subroutine redsum(dq, nx, ny, nz, result)
37 implicit none
38
39 ! Declare arguments and local variables
40 integer, intent(in) :: nx, ny, nz
41 real(8), intent(in) :: dq(5, nx, ny, nz)
42 real(8), intent(out) :: result
43 real(8) :: dqnorm
44 integer :: i, j, k, l
45
46 ! Initialize dqnorm
47 dqnorm = 0.0d0
48
49 ! Compute the sum of squares of dq elements
50 do k = 1, nz
51 do j = 1, ny
52 do i = 1, nx
53 do l = 1, 5
54 dqnorm = dqnorm + dq(l, i, j, k) * dq(l, i, j, k)
55 end do
56 end do
57 end do
58 end do
59
60 result = dqnorm
61
62 end subroutine redsum
63