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

gyrokinetics / gs2 / 1998640042

22 Aug 2025 01:50PM UTC coverage: 10.577% (-0.1%) from 10.718%
1998640042

push

gitlab-ci

David Dickinson
Merged in feature/dont_reset_configs_when_finishing_modules (pull request #1160)

4700 of 44434 relevant lines covered (10.58%)

125622.86 hits per line

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

0.0
/src/optimisation_configuration.f90
1
!> A module for handling the configuration of the optimisation
2
!! module via the namelist optimisation_config.
3
module optimisation_configuration
4
  use abstract_config, only: abstract_config_type, CONFIG_MAX_NAME_LEN
5
  use overrides, only: optimisations_overrides_type
6
  implicit none
7

8
  private
9

10
  public :: init_optimisation_config
11
  public :: finish_optimisation_config
12
  public :: optimisation_type
13
  public :: optimisation_results_type
14

15
  public :: optimisation_config_type
16
  public :: set_optimisation_config
17
  public :: get_optimisation_config
18

19
  logical :: initialized = .false.
20
  
21
  type optimisation_results_type
22
    ! Configuration
23

24
    ! Results
25
    real :: time
26
    real :: optimal_time
27
    real :: cost
28
    real :: optimal_cost
29
    real :: efficiency
30
    integer :: nproc
31
    logical :: optimal = .true.
32

33
  end type optimisation_results_type
34

35
  !> A type for storing the optimisation configuration,
36
  !! the results
37
  type optimisation_type
38
     integer :: nproc_max
39
     type(optimisation_results_type) :: results
40
     type(optimisations_overrides_type), &
41
          dimension(:), allocatable :: sorted_optimisations
42
     type(optimisation_results_type), dimension(:), allocatable :: sorted_results
43
     real :: timing_rel_error
44
     real :: timing_max_rel_error
45
     integer :: outunit
46
     logical :: on
47
     logical :: auto
48
     logical :: measure_all
49
     logical :: warm_up
50
     logical :: estimate_timing_error
51
     integer :: nstep_measure
52
     real :: max_imbalance
53
     integer :: max_unused_procs
54
     real :: min_efficiency
55
  end type optimisation_type
56

57
  !> Used to represent the input configuration for GS2's optimisation
58
  !> procedure. When turned on, GS2 performs a scan for the given input file,
59
  !> varying different optimisation flags. Results of this scan are reported
60
  !> in <runname>.optim. The optimal parameters are stored, allowing a user to
61
  !> run the same input file with optimised parameters in the same execution.
62
  !> A user can also choose to continue with a less-than-optimal set of
63
  !> parameters which satisfy other constraints.
64
  type, extends(abstract_config_type) :: optimisation_config_type
65
     ! namelist : optimisation_config
66
     ! indexed : false     
67
     !> When true, automatically continues GS2 to run the input file with the
68
     !> optimised parameters.
69
     logical :: auto = .true.
70
     !> Estimate the absolute and relative errors in timing data
71
     !> FIXME: Why would we want this to be false? On small core counts it
72
     !> doesn't seem like a big overhead.
73
     logical :: estimate_timing_error = .true.
74
     !> The maximum fraction of unused procs to allow in the optimisation
75
     !> scan.
76
     real :: max_imbalance = -1.0
77
     !> The maximum number of unused procs to allow in the optimisation scan.
78
     integer :: max_unused_procs = 0
79
     !> When true, use the "advance" timer.
80
     !> When false, use the "timestep" timer.
81
     logical :: measure_all = .false.
82
     !> The minimum efficiency (relative to the optimal parameters)
83
     !> considered when looking for a constrained set of parameters.
84
     !> A negative value implies only the optimal parameters are considered.
85
     real :: min_efficiency = -1.0
86
     !> The number of timestep to use in the timing experiments. Must
87
     !> be greater than 1
88
     integer :: nstep_measure = 5
89
     !> Set true to turn on optimisation procedure
90
     logical :: on = .false.
91
     !> When true, perform a few runs before beginning the timing experiment
92
     logical :: warm_up = .false.
93
#include "optimisation_overrides_and_bound_auto_gen.inc"
94
  end type optimisation_config_type
95
  
96
  type(optimisation_config_type) :: optimisation_config
97
  
98
contains
99
  subroutine init_optimisation_config(optim, optimisation_config_in)
×
100
    use file_utils, only: open_output_file
101
    use mp, only: nproc, proc0
102
    implicit none
103
    type(optimisation_type), intent(inout) :: optim
104
    type(optimisation_config_type), intent(in), optional :: optimisation_config_in
105
    if(initialized) return
×
106
    initialized = .true.
×
107
    call read_parameters(optim, optimisation_config_in)
×
108
    if(optim%on) then
×
109
      if (proc0) call open_output_file(optim%outunit, '.optim')
×
110
    end if
111
    optim%nproc_max = nproc
×
112
  end subroutine init_optimisation_config
113

114
  subroutine finish_optimisation_config(optim)
×
115
    use file_utils, only: close_output_file
116
    use mp, only: proc0
117
    implicit none
118
    type(optimisation_type), intent(inout) :: optim
119
    initialized = .false.
×
120

121
    if(optim%on) then
×
122
      if (proc0) call close_output_file(optim%outunit)
×
123
    end if
124
  end subroutine finish_optimisation_config
×
125

126
  subroutine read_parameters(optim, optimisation_config_in)
×
127
    use mp, only: proc0
128
    use file_utils, only: error_unit
129
    implicit none
130
    type(optimisation_type), intent(inout) :: optim
131
    type(optimisation_config_type), intent(in), optional :: optimisation_config_in
132

133
    if (present(optimisation_config_in)) optimisation_config = optimisation_config_in
×
134

135
    call optimisation_config%init(name = 'optimisation_config', requires_index = .false.)
×
136

137
    ! Copy out internal values into module level parameters
138
    associate(self => optimisation_config, &
139
         auto => optim%auto, estimate_timing_error => optim%estimate_timing_error, &
140
         max_imbalance => optim%max_imbalance, max_unused_procs => optim%max_unused_procs, &
141
         measure_all => optim%measure_all, min_efficiency => optim%min_efficiency, &
142
         nstep_measure => optim%nstep_measure, on => optim%on, warm_up => optim%warm_up)
143
#include "optimisation_copy_out_auto_gen.inc"
144
    end associate
145

146
    if (optim%nstep_measure < 2) then
×
147
       optim%nstep_measure = 2
×
148
       if (proc0) write(error_unit(), '("Warning nstep_measure must be at least 2. Forcing nstep_measure = 2")')
×
149
    end if
150

151
  end subroutine read_parameters
×
152

153
#include "optimisation_auto_gen.inc"
154
end module optimisation_configuration
×
155

×
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