• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gyrokinetics / gs2 / 1821477209

16 May 2025 02:50PM UTC coverage: 8.139% (+0.2%) from 7.92%
1821477209

push

gitlab-ci

David Dickinson
Merged in bugfix/use_uv_in_coverage_test_to_install_packages (pull request #1142)

3704 of 45511 relevant lines covered (8.14%)

122643.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/programs/mat_inv_benchmark.fpp
1
!> Times the matrix inversion code for a particular method for various sizes.
2
!> Can also check the correctness.
3
program mat_inv_benchmark
×
4
  use mp, only: init_mp, finish_mp, barrier, proc0
×
5
  use mat_inv, only: invert_serial, matrix_inversion_method_type
6
  use mat_inv, only: mat_inv_serial_gauss_jordan
7
  use ran, only: ranf
8
  use job_manage, only: timer_local
9
  use iso_fortran_env, only: output_unit
10
  implicit none
11
  complex, dimension(:, :), allocatable :: array, original_array
×
12
  integer, dimension(:), allocatable :: sizes
×
13
  integer :: icase, irep, nrep, current_size, ncases, j, k
14
  real, dimension(:), allocatable :: current_times
×
15
  real, dimension(:), allocatable :: average_times, max_times, min_times
×
16
  real :: time_a, time_b
17
  integer :: output
18
  type(matrix_inversion_method_type), parameter :: the_method = mat_inv_serial_gauss_jordan
19

20
  call init_mp
×
21

22
  output = output_unit
×
23

24
  if (proc0) then
×
25
     sizes =  [2,4,8,16,32,64,128,256,257,400,512,1024,2048]
×
26
     ncases = size(sizes)
×
27
     allocate(average_times(ncases))
×
28
     allocate(max_times(ncases))
×
29
     allocate(min_times(ncases))
×
30

31
     do icase = 1, ncases
×
32
        current_size = sizes(icase)
×
33
        nrep = max(1,sizes(ncases)/current_size)
×
34

35
        allocate( array(current_size, current_size))
×
36

37
        time_a = timer_local()
×
38
        do j = 1, current_size
×
39
           do k = 1, current_size
×
40
              array(j, k) = cmplx(ranf(), ranf())
×
41
           end do
42

43
           ! Try to ensure array is diagonally dominant
44
           array(j, j) = array(j, j) + 1.0
×
45
        end do
46

47
        original_array = array
×
48

49
        time_b = timer_local() - time_a
×
50
        write(output, '("Took ",F12.5,"s to construct with size ",I0," for ",I0," repeats")') time_b, current_size, nrep
×
51

52
        allocate(current_times(nrep))
×
53
        current_times = 0
×
54

55
        do irep = 1, nrep
×
56
           time_a = timer_local()
×
57

58
           call invert_serial(array, current_size, the_method)
×
59

60
           time_b = timer_local()
×
61
           current_times(irep) = time_b - time_a
×
62

63
           ! Test the inversion, if it fails abort.
64
           if(irep==1) then
×
65
              if(.not.test(original_array,array, print_error = .true.)) then
×
66
                 exit
×
67
              end if
68
           end if
69

70
        end do
71

72
        average_times(icase) = sum(current_times) / size(current_times)
×
73
        max_times(icase) = maxval(current_times)
×
74
        min_times(icase) = minval(current_times)
×
75
        deallocate(array)
×
76
        deallocate(current_times)
×
77
     end do
78

79
     write(output,'()')
×
80
     write(output,'("---------------------------------------------------")')
×
81
     write(output,'("Method : ",A)') trim(adjustl(the_method%get_name()))
×
82
     write(output,'()')
×
83
     write(output,'("Size : Average,          max,          min")')
×
84

85
     do icase = 1, ncases
×
86
        write(output,'(I0," : ",3(F12.5,"s "))') sizes(icase), average_times(icase), max_times(icase), min_times(icase)
×
87
     end do
88

89
  end if
90

91

92
  call finish_mp
×
93

94
contains
95

96
  logical function test(A, B, print_error)
×
97
    use optionals, only: get_option_with_default
98
    implicit none
99
    complex, dimension(:,:), intent(in) :: A, B
100
    logical, intent(in), optional :: print_error
101
    complex, dimension(:,:), allocatable :: C
×
102
    real, dimension(:,:), allocatable :: identity
×
103
    real, parameter :: tolerance = 1.0e-8
104
    real :: maxerr
105
    integer :: i, N
106
    integer, dimension(2) :: error_position
107
    logical :: print_error_internal
108

109
    C = matmul(A,B)
×
110
    N = size(A, dim = 1)
×
111
    allocate( identity(N, N))
×
112
    identity = 0
×
113
    do i = 1, N
×
114
       identity(i, i) = 1.0
×
115
    end do
116

117
    maxerr = maxval(abs(C - identity))
×
118

119
    test = maxerr <= tolerance
×
120
    print_error_internal = get_option_with_default(print_error, .false.)
×
121

122
    if (.not. test .and. print_error_internal) then
×
123
       print*,"ERROR: Inversion failed with maxerr = ",maxerr," compared to tolerance ",tolerance
×
124
       error_position = maxloc(abs(C - identity))
×
125
       print*,"Location of first maximum error is given at (",error_position(1),",",error_position(2),")"
×
126
    end if
127

128
  end function test
×
129

130
end program mat_inv_benchmark
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc