Line | Branch | Exec | Source |
---|---|---|---|
1 | !!!############################################################################# | ||
2 | !!! Code written by Ned Thaddeus Taylor | ||
3 | !!! Code part of the ATHENA library - a feedforward neural network library | ||
4 | !!!############################################################################# | ||
5 | !!! module contains random number generator initialisation | ||
6 | !!! module contains the following procedures: | ||
7 | !!! - random_setup - seed random number generator from seed vector or randomly | ||
8 | !!!############################################################################# | ||
9 | module random | ||
10 | implicit none | ||
11 | logical :: l_random_initialised=.false. | ||
12 | |||
13 | private | ||
14 | |||
15 | public :: random_setup | ||
16 | |||
17 | |||
18 | contains | ||
19 | |||
20 | !!!############################################################################# | ||
21 | !!! seed random number generator from vector of seeds | ||
22 | !!!############################################################################# | ||
23 | 3 | subroutine random_setup(seed, num_seed, restart, already_initialised) | |
24 | implicit none | ||
25 | integer, dimension(..), optional, intent(in) :: seed !dimension(..1) | ||
26 | integer, optional, intent(out) :: num_seed | ||
27 | logical, optional, intent(in) :: restart | ||
28 | logical, optional, intent(out) :: already_initialised | ||
29 | |||
30 | integer :: l | ||
31 | integer :: itmp1 | ||
32 | integer :: num_seed_ | ||
33 | logical :: restart_ | ||
34 | 3 | integer, allocatable, dimension(:) :: seed_arr | |
35 | |||
36 | !! check if restart is defined | ||
37 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if(present(restart))then |
38 | 3 | restart_ = restart | |
39 | else | ||
40 | ✗ | restart_ = .false. | |
41 | end if | ||
42 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if(present(already_initialised)) already_initialised = .false. |
43 | |||
44 | !! check if already initialised | ||
45 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if(l_random_initialised.and..not.restart_)then |
46 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if(present(already_initialised)) already_initialised = .true. |
47 | 1 | return !! no need to initialise if already initialised | |
48 | else | ||
49 | 2 | call random_seed(size=num_seed_) | |
50 |
7/14✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 2 times.
|
2 | allocate(seed_arr(num_seed_)) |
51 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | if(present(seed))then |
52 | 1 | select rank(seed) | |
53 | rank(0) | ||
54 | ✗ | seed_arr = seed | |
55 | rank(1) | ||
56 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if(size(seed,dim=1).ne.1)then |
57 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if(size(seed,dim=1).eq.num_seed_)then |
58 |
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 |
59 | else | ||
60 | write(0,*) "ERROR: seed size not consistent with & | ||
61 | ✗ | &seed size returned by implementation" | |
62 | ✗ | write(0,*) "Cannot resolve" | |
63 | ✗ | write(0,*) "Exiting..." | |
64 | ✗ | stop 1 | |
65 | end if | ||
66 | else | ||
67 | ✗ | seed_arr = seed(1) | |
68 | end if | ||
69 | end select | ||
70 | else | ||
71 | 1 | call system_clock(count=itmp1) | |
72 |
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_) /) |
73 | end if | ||
74 | 2 | call random_seed(put=seed_arr) | |
75 | 2 | l_random_initialised = .true. | |
76 | end if | ||
77 | |||
78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if(present(num_seed)) num_seed = num_seed_ |
79 | |||
80 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | end subroutine random_setup |
81 | !!!############################################################################# | ||
82 | |||
83 |
4/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
1 | end module random |
84 | !!!############################################################################# | ||
85 |