GCC Code Coverage Report


Directory: src/athena/
File: src/athena/athena_random.f90
Date: 2026-04-15 16:08:59
Exec Total Coverage
Lines: 23 28 82.1%
Functions: 0 0 -%
Branches: 47 86 54.7%

Line Branch Exec Source
1 module athena__random
2 !! Module containing functions to initialise the random number generator
3 use coreutils, only: stop_program
4 implicit none
5 logical :: l_random_initialised=.false.
6
7
8 private
9
10 public :: random_setup
11
12
13
14 contains
15
16 !###############################################################################
17 7 subroutine random_setup(seed, num_seed, restart, already_initialised)
18 !! Initialise the random number generator
19 implicit none
20
21 ! Arguments
22 integer, dimension(..), optional, intent(in) :: seed
23 !! Seed for the random number generator
24 integer, optional, intent(out) :: num_seed
25 !! Number of seeds
26 logical, optional, intent(in) :: restart
27 !! Restart the random number generator
28 logical, optional, intent(out) :: already_initialised
29 !! Check if the random number generator is already initialised
30
31 ! Local variables
32 integer :: l
33 !! Loop index
34 integer :: itmp1
35 !! Temporary integer
36 integer :: num_seed_
37 !! Number of seeds
38 logical :: restart_
39 !! Restart the random number generator
40 7 integer, allocatable, dimension(:) :: seed_arr
41 !! Seed array
42 character(256) :: err_msg
43 !! Error message
44
45
46 !---------------------------------------------------------------------------
47 ! Check if restart is defined
48 !---------------------------------------------------------------------------
49
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(present(restart))then
50 7 restart_ = restart
51 else
52 restart_ = .false.
53 end if
54
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
7 if(present(already_initialised)) already_initialised = .false.
55
56 !---------------------------------------------------------------------------
57 ! Check if already initialised
58 !---------------------------------------------------------------------------
59
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if(l_random_initialised.and..not.restart_)then
60
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(present(already_initialised)) already_initialised = .true.
61 1 return !! no need to initialise if already initialised
62 else
63 6 call random_seed(size=num_seed_)
64
7/14
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 6 times.
6 allocate(seed_arr(num_seed_))
65
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
6 if(present(seed))then
66 5 select rank(seed)
67 rank(0)
68
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 4 times.
36 seed_arr = seed
69 rank(1)
70
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(size(seed,dim=1).ne.1)then
71
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(size(seed,dim=1).eq.num_seed_)then
72
8/20
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 8 times.
✓ Branch 23 taken 1 times.
9 seed_arr = seed
73 else
74 write(err_msg,'(A)') &
75 "seed size not consistent with &
76 &seed size returned by implementation" // &
77 achar(13) // achar(10) // &
78 "Cannot resolve"
79 call stop_program(err_msg)
80 return
81 end if
82 else
83 seed_arr = seed(1)
84 end if
85 end select
86 else
87 1 call system_clock(count=itmp1)
88
10/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 8 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 8 times.
✓ Branch 16 taken 1 times.
25 seed_arr = itmp1 + 37* (/ (l-1,l=1,num_seed_) /)
89 end if
90 6 call random_seed(put=seed_arr)
91 6 l_random_initialised = .true.
92 end if
93
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(present(num_seed)) num_seed = num_seed_
95
96
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 end subroutine random_setup
97 !###############################################################################
98
99
6/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
5 end module athena__random
100