NEST main@caf0ae8
 
Loading...
Searching...
No Matches
vp_manager.h
Go to the documentation of this file.
1/*
2 * vp_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 VP_MANAGER_H
24#define VP_MANAGER_H
25
26// Includes from libnestutil:
27#include "manager_interface.h"
28
29// Includes from nestkernel:
30#include "nest_types.h"
31
32
33#ifdef _OPENMP
34// C includes:
35#include <omp.h>
36#endif
37
38namespace nest
39{
40
42{
43 size_t begin;
44 size_t end;
45 size_t size;
46 size_t max_size;
47};
48
50{
51public:
52 VPManager();
53 ~VPManager() override
54 {
55 }
56
57 void initialize( const bool ) override;
58 void finalize( const bool ) override;
59
60 virtual void set_status( const Dictionary& ) override;
61 virtual void get_status( Dictionary& ) override;
62
68 size_t get_thread_id() const;
69
75 void set_num_threads( const size_t n_threads );
76
82 size_t get_num_threads() const;
83
89 size_t get_OMP_NUM_THREADS() const;
90
94 bool is_node_id_vp_local( const size_t node_id ) const;
95
99 size_t node_id_to_lid( const size_t node_id ) const;
100
104 size_t lid_to_node_id( const size_t lid ) const;
105
109 size_t get_vp() const;
110
120 size_t node_id_to_vp( const size_t node_id ) const;
121
125 size_t vp_to_thread( const size_t vp ) const;
126
130 size_t thread_to_vp( const size_t tid ) const;
131
135 bool is_local_vp( const size_t tid ) const;
136
140 size_t get_num_virtual_processes() const;
141
145 void assert_single_threaded() const;
146
150 void assert_thread_parallel() const;
151
157
158 size_t get_start_rank_per_thread( const size_t tid ) const;
159 size_t get_end_rank_per_thread( const size_t rank_start, const size_t num_assigned_ranks_per_thread ) const;
160
168 AssignedRanks get_assigned_ranks( const size_t tid );
169
170private:
172 size_t n_threads_;
173};
174
175inline size_t
177{
178#ifdef _OPENMP
179 return omp_get_thread_num();
180#else
181 return 0;
182#endif
183}
184
185inline size_t
187{
188 return n_threads_;
189}
190
191inline void
193{
194#ifdef _OPENMP
195 assert( omp_get_num_threads() == 1 );
196#endif
197}
198
199inline void
201{
202#ifdef _OPENMP
203 // omp_get_num_threads() returns int
204 assert( omp_get_num_threads() == static_cast< int >( n_threads_ ) );
205#endif
206}
207
208} // namespace nest
209
210#endif /* #ifndef VP_MANAGER_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Interface for kernel manager classes.
Definition manager_interface.h:46
Definition vp_manager.h:50
void assert_thread_parallel() const
Fails if NEST is not in thread-parallel section.
Definition vp_manager.h:200
size_t node_id_to_vp(const size_t node_id) const
Return a thread number for a given global node id.
Definition vp_manager_impl.h:43
void assert_single_threaded() const
Fails if NEST is in thread-parallel section.
Definition vp_manager.h:192
VPManager()
Definition vp_manager.cpp:40
size_t lid_to_node_id(const size_t lid) const
Returns the node ID of a given local index.
Definition vp_manager_impl.h:86
bool is_node_id_vp_local(const size_t node_id) const
Returns true if the given global node exists on this vp.
Definition vp_manager_impl.h:73
size_t get_num_threads() const
Get number of threads.
Definition vp_manager.h:186
virtual void set_status(const Dictionary &) override
Set the status of the manager.
Definition vp_manager.cpp:100
const bool force_singlethreading_
Definition vp_manager.h:171
size_t get_num_assigned_ranks_per_thread() const
Returns the number of processes that are taken care of by a single thread while processing MPI buffer...
Definition vp_manager_impl.h:93
size_t vp_to_thread(const size_t vp) const
Convert a given VP ID to the corresponding thread ID.
Definition vp_manager_impl.h:49
size_t thread_to_vp(const size_t tid) const
Convert a given thread ID to the corresponding VP ID.
Definition vp_manager_impl.h:67
AssignedRanks get_assigned_ranks(const size_t tid)
Returns assigned ranks per thread to fill MPI buffers.
Definition vp_manager_impl.h:121
size_t get_vp() const
Returns virtual process index.
Definition vp_manager_impl.h:37
size_t get_num_virtual_processes() const
Returns the number of virtual processes.
Definition vp_manager_impl.h:55
void finalize(const bool) override
Take down manager after operation.
Definition vp_manager.cpp:81
~VPManager() override
Definition vp_manager.h:53
size_t n_threads_
Number of threads per process.
Definition vp_manager.h:172
size_t get_thread_id() const
Gets ID of local thread.
Definition vp_manager.h:176
bool is_local_vp(const size_t tid) const
Return true, if the given VP is on the local machine.
Definition vp_manager_impl.h:61
virtual void get_status(Dictionary &) override
Retrieve the status of the manager.
Definition vp_manager.cpp:180
size_t get_start_rank_per_thread(const size_t tid) const
Definition vp_manager_impl.h:99
void set_num_threads(const size_t n_threads)
Set the number of threads by setting the internal variable n_threads_, the corresponding value in the...
Definition vp_manager.cpp:187
size_t node_id_to_lid(const size_t node_id) const
Returns thread local index of a given global node.
Definition vp_manager_impl.h:79
size_t get_end_rank_per_thread(const size_t rank_start, const size_t num_assigned_ranks_per_thread) const
Definition vp_manager_impl.h:105
size_t get_OMP_NUM_THREADS() const
Get OMP_NUM_THREADS environment variable.
Definition vp_manager.cpp:86
void initialize(const bool) override
Prepare manager for operation.
Definition vp_manager.cpp:51
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
Definition vp_manager.h:42
size_t end
Definition vp_manager.h:44
size_t size
Definition vp_manager.h:45
size_t max_size
Definition vp_manager.h:46
size_t begin
Definition vp_manager.h:43