NEST main@caf0ae8
 
Loading...
Searching...
No Matches
vp_manager_impl.h
Go to the documentation of this file.
1/*
2 * vp_manager_impl.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_IMPL_H
24#define VP_MANAGER_IMPL_H
25
26#include "vp_manager.h"
27
28// Includes from nestkernel:
29#include "kernel_manager.h"
30#include "mpi_manager.h"
31#include "mpi_manager_impl.h"
32
33namespace nest
34{
35
36inline size_t
41
42inline size_t
43VPManager::node_id_to_vp( const size_t node_id ) const
44{
45 return node_id % get_num_virtual_processes();
46}
47
48inline size_t
49VPManager::vp_to_thread( const size_t vp ) const
50{
51 return vp / kernel().mpi_manager.get_num_processes();
52}
53
54inline size_t
59
60inline bool
61VPManager::is_local_vp( const size_t vp ) const
62{
64}
65
66inline size_t
67VPManager::thread_to_vp( const size_t tid ) const
68{
70}
71
72inline bool
73VPManager::is_node_id_vp_local( const size_t node_id ) const
74{
75 return ( node_id % get_num_virtual_processes() == static_cast< size_t >( get_vp() ) );
76}
77
78inline size_t
79VPManager::node_id_to_lid( const size_t node_id ) const
80{
81 // starts at lid 0 for node_ids >= 1 (expected value for neurons, excl. node ID 0)
82 return std::ceil( static_cast< double >( node_id ) / get_num_virtual_processes() ) - 1;
83}
84
85inline size_t
86VPManager::lid_to_node_id( const size_t lid ) const
87{
88 const size_t vp = get_vp();
89 return ( lid + static_cast< size_t >( vp == 0 ) ) * get_num_virtual_processes() + vp;
90}
91
92inline size_t
94{
95 return std::ceil( static_cast< double >( kernel().mpi_manager.get_num_processes() ) / n_threads_ );
96}
97
98inline size_t
99VPManager::get_start_rank_per_thread( const size_t tid ) const
100{
102}
103
104inline size_t
105VPManager::get_end_rank_per_thread( const size_t rank_start, const size_t num_assigned_ranks_per_thread ) const
106{
107 size_t rank_end = rank_start + num_assigned_ranks_per_thread;
108
109 // if we have more threads than ranks, or if ranks can not be
110 // distributed evenly on threads, we need to make sure, that all
111 // threads care only about existing ranks
112 if ( rank_end > kernel().mpi_manager.get_num_processes() )
113 {
114 rank_end = std::max( rank_start, kernel().mpi_manager.get_num_processes() );
115 }
116
117 return rank_end;
118}
119
120inline AssignedRanks
122{
123 AssignedRanks assigned_ranks;
124 assigned_ranks.begin = get_start_rank_per_thread( tid );
126 assigned_ranks.end = get_end_rank_per_thread( assigned_ranks.begin, assigned_ranks.max_size );
127 assigned_ranks.size = assigned_ranks.end - assigned_ranks.begin;
128 return assigned_ranks;
129}
130
131} // namespace nest
132
133#endif /* VP_MANAGER_IMPL_H */
size_t get_process_id_of_vp(const size_t vp) const
Return the process id for a given virtual process.
Definition mpi_manager_impl.h:42
size_t get_num_processes() const
Return the number of processes used during simulation.
Definition mpi_manager.h:492
size_t get_rank() const
Get rank of MPI process.
Definition mpi_manager.h:498
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
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
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
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
size_t get_start_rank_per_thread(const size_t tid) const
Definition vp_manager_impl.h:99
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
MPIManager mpi_manager
Definition kernel_manager.h:233
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
KernelManager & kernel()
Definition kernel_manager.h:311
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