Line data Source code
1 1 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : /// \file
5 : /// Defines functions that provide low-level system information such as number
6 : /// of nodes and processors, in a way that they are mockable in ActionTesting.
7 :
8 : #pragma once
9 :
10 : #include <cstddef>
11 :
12 : /// Functionality for parallelization.
13 : ///
14 : /// The functions in namespace `Parallel` that return information on
15 : /// nodes and cores are templated on DistribObject. Actions should
16 : /// use these functions rather than the raw charm++ versions (in the
17 : /// sys namespace in Utilities/System/ParallelInfo.hpp) so that the
18 : /// mocking framework will see the mocked cores and nodes.
19 : namespace Parallel {
20 :
21 : /*!
22 : * \ingroup ParallelGroup
23 : * \brief Number of processing elements.
24 : */
25 : template <typename T, typename DistribObject>
26 1 : T number_of_procs(const DistribObject& distributed_object) {
27 : return static_cast<T>(distributed_object.number_of_procs());
28 : }
29 :
30 : /*!
31 : * \ingroup ParallelGroup
32 : * \brief %Index of my processing element.
33 : */
34 : template <typename T, typename DistribObject>
35 1 : T my_proc(const DistribObject& distributed_object) {
36 : return static_cast<T>(distributed_object.my_proc());
37 : }
38 :
39 : /*!
40 : * \ingroup ParallelGroup
41 : * \brief Number of nodes.
42 : */
43 : template <typename T, typename DistribObject>
44 1 : T number_of_nodes(const DistribObject& distributed_object) {
45 : return static_cast<T>(distributed_object.number_of_nodes());
46 : }
47 :
48 : /*!
49 : * \ingroup ParallelGroup
50 : * \brief %Index of my node.
51 : */
52 : template <typename T, typename DistribObject>
53 1 : T my_node(const DistribObject& distributed_object) {
54 : return static_cast<T>(distributed_object.my_node());
55 : }
56 :
57 : /*!
58 : * \ingroup ParallelGroup
59 : * \brief Number of processing elements on the given node.
60 : */
61 : template <typename T, typename R, typename DistribObject>
62 1 : T procs_on_node(const R node_index, const DistribObject& distributed_object) {
63 : return static_cast<T>(
64 : distributed_object.procs_on_node(static_cast<int>(node_index)));
65 : }
66 :
67 : /*!
68 : * \ingroup ParallelGroup
69 : * \brief The local index of my processing element on my node.
70 : * This is in the interval 0, ..., procs_on_node(my_node()) - 1.
71 : */
72 : template <typename T, typename DistribObject>
73 1 : T my_local_rank(const DistribObject& distributed_object) {
74 : return static_cast<T>(distributed_object.my_local_rank());
75 : }
76 :
77 : /*!
78 : * \ingroup ParallelGroup
79 : * \brief %Index of first processing element on the given node.
80 : */
81 : template <typename T, typename R, typename DistribObject>
82 1 : T first_proc_on_node(const R node_index,
83 : const DistribObject& distributed_object) {
84 : return static_cast<T>(
85 : distributed_object.first_proc_on_node(static_cast<int>(node_index)));
86 : }
87 :
88 : /*!
89 : * \ingroup ParallelGroup
90 : * \brief %Index of the node for the given processing element.
91 : */
92 : template <typename T, typename R, typename DistribObject>
93 1 : T node_of(const R proc_index, const DistribObject& distributed_object) {
94 : return static_cast<T>(
95 : distributed_object.node_of(static_cast<int>(proc_index)));
96 : }
97 :
98 : /*!
99 : * \ingroup ParallelGroup
100 : * \brief The local index for the given processing element on its node.
101 : */
102 : template <typename T, typename R, typename DistribObject>
103 1 : T local_rank_of(const R proc_index, const DistribObject& distributed_object) {
104 : return static_cast<T>(
105 : distributed_object.local_rank_of(static_cast<int>(proc_index)));
106 : }
107 : } // namespace Parallel
|