1 /*
2  *  kernel_manager.h
3  *
4  *  This file is part of NEST.
5  *
6  *  Copyright (C) 2004 The NEST Initiative
7  *
8  *  NEST is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation, either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  NEST is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef KERNEL_MANAGER_H
24 #define KERNEL_MANAGER_H
25 
26 // Includes from nestkernel:
27 #include "connection_manager.h"
28 #include "event_delivery_manager.h"
29 #include "io_manager.h"
30 #include "logging_manager.h"
31 #include "model_manager.h"
32 #include "modelrange_manager.h"
33 #include "mpi_manager.h"
34 #include "music_manager.h"
35 #include "node_manager.h"
36 #include "random_manager.h"
37 #include "simulation_manager.h"
38 #include "sp_manager.h"
39 #include "vp_manager.h"
40 
41 // Includes from sli:
42 #include "dictdatum.h"
43 
44 // clang-format off
45 /** @BeginDocumentation
46  Name: kernel - Global properties of the simulation kernel.
47 
48  Description:
49  Global properties of the simulation kernel.
50 
51  Parameters:
52  The following parameters are available in the kernel status dictionary.
53 
54  Time and resolution
55  resolution                    doubletype  - The resolution of the simulation (in ms)
56  time                          doubletype  - The current simulation time
57  to_do                         integertype - The number of steps yet to be simulated (read only)
58  max_delay                     doubletype  - The maximum delay in the network
59  min_delay                     doubletype  - The minimum delay in the network
60  ms_per_tic                    doubletype  - The number of milliseconds per tic
61  tics_per_ms                   doubletype  - The number of tics per millisecond
62  tics_per_step                 integertype - The number of tics per simulation time step
63  T_max                         doubletype  - The largest representable time value (read only)
64  T_min                         doubletype  - The smallest representable time value (read only)
65 
66  Parallel processing
67  total_num_virtual_procs       integertype - The total number of virtual processes
68  local_num_threads             integertype - The local number of threads
69  num_processes                 integertype - The number of MPI processes (read only)
70  off_grid_spiking              booltype    - Whether to transmit precise spike times in MPI
71                                              communication (read only)
72 
73  Random number generators
74  rng_types                     arraytype   - Names of random number generator types available (read only)
75  rng_type                      stringtype  - Name of random number generator type used by kernel
76  rng_seed                      integertype - Seed value used as basis of seeding of all random number
77                                              generators managed by the kernel (\f$1 leq s \leq 2^{32}-1\f$).
78 
79  Output
80  data_path                     stringtype  - A path, where all data is written to
81                                              (default is the current directory)
82  data_prefix                   stringtype  - A common prefix for all data files
83  overwrite_files               booltype    - Whether to overwrite existing data files
84  print_time                    booltype    - Whether to print progress information during the simulation
85 
86  Network information
87  network_size                  integertype - The number of nodes in the network (read only)
88  num_connections               integertype - The number of connections in the network
89                                              (read only, local only)
90 
91  Waveform relaxation method (wfr)
92  use_wfr                       booltype    - Whether to use waveform relaxation method
93  wfr_comm_interval             doubletype  - Desired waveform relaxation communication interval
94  wfr_tol                       doubletype  - Convergence tolerance of waveform relaxation method
95  wfr_max_iterations            integertype - Maximal number of iterations used for waveform relaxation
96  wfr_interpolation_order       integertype - Interpolation order of polynomial used in wfr iterations
97 
98  Miscellaneous
99  dict_miss_is_error            booltype    - Whether missed dictionary entries are treated as errors
100 
101  SeeAlso: Simulate, Node
102  */
103 // clang-format on
104 
105 namespace nest
106 {
107 
108 class KernelManager
109 {
110 private:
111   KernelManager();
112   ~KernelManager();
113 
114   unsigned long fingerprint_;
115 
116   static KernelManager* kernel_manager_instance_;
117 
118   KernelManager( KernelManager const& );  // do not implement
119   void operator=( KernelManager const& ); // do not implement
120 
121 public:
122   /**
123    * Create/destroy and access the KernelManager singleton.
124    */
125   static void create_kernel_manager();
126   static void destroy_kernel_manager();
127   static KernelManager& get_kernel_manager();
128 
129   /**
130    * Prepare kernel for operation.
131    *
132    * This method calls the initialization methods of the specific
133    * managers in the proper order.
134    *
135    * @see finalize(), reset()
136    */
137   void initialize();
138 
139   /**
140    * Take down kernel after operation.
141    *
142    * This method calls the finalization methods of the specific managers
143    * in the proper order, i.e., inverse to initialize().
144    *
145    * @see initialize(), reset()
146    */
147   void finalize();
148 
149   /**
150    * Reset kernel.
151    *
152    * Resets kernel by finalizing and initializing.
153    *
154    * @see initialize(), finalize()
155    */
156   void reset();
157 
158   /**
159    * Change number of threads.
160    *
161    * The kernel first needs to be finalized with the old number of threads
162    * and then initialized with the new number of threads.
163    *
164    * @see initialize(), finalize()
165    */
166   void change_number_of_threads( thread );
167 
168   void prepare();
169   void cleanup();
170 
171   void set_status( const DictionaryDatum& );
172   void get_status( DictionaryDatum& );
173 
174   //! Returns true if kernel is initialized
175   bool is_initialized() const;
176 
177   unsigned long get_fingerprint() const;
178 
179   LoggingManager logging_manager;
180   MPIManager mpi_manager;
181   VPManager vp_manager;
182   RandomManager random_manager;
183   SimulationManager simulation_manager;
184   ModelRangeManager modelrange_manager;
185   ConnectionManager connection_manager;
186   SPManager sp_manager;
187   EventDeliveryManager event_delivery_manager;
188   ModelManager model_manager;
189   MUSICManager music_manager;
190   NodeManager node_manager;
191   IOManager io_manager;
192 
193 private:
194   std::vector< ManagerInterface* > managers;
195   bool initialized_; //!< true if all sub-managers initialized
196 };
197 
198 KernelManager& kernel();
199 
200 } // namespace nest
201 
202 inline nest::KernelManager&
get_kernel_manager()203 nest::KernelManager::get_kernel_manager()
204 {
205   assert( kernel_manager_instance_ );
206   return *kernel_manager_instance_;
207 }
208 
209 inline nest::KernelManager&
kernel()210 nest::kernel()
211 {
212   return KernelManager::get_kernel_manager();
213 }
214 
215 inline bool
is_initialized()216 nest::KernelManager::is_initialized() const
217 {
218   return initialized_;
219 }
220 
221 inline unsigned long
get_fingerprint()222 nest::KernelManager::get_fingerprint() const
223 {
224   return fingerprint_;
225 }
226 
227 #endif /* KERNEL_MANAGER_H */
228