1
+ // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and
2
+ // other Axom Project Developers. See the top-level LICENSE file for details.
3
+ //
4
+ // SPDX-License-Identifier: (BSD-3-Clause)
5
+
6
+ /* !
7
+ *******************************************************************************
8
+ * \file NonBlockingRootCommunicator.hpp
9
+ *
10
+ * \brief This file contains the class definition of the
11
+ * NonBlockingRootCommunicator.
12
+ *******************************************************************************
13
+ */
14
+
15
+ #ifndef NONBLOCKINGROOTCOMMUNICATOR_HPP
16
+ #define NONBLOCKINGROOTCOMMUNICATOR_HPP
17
+
18
+ #include " axom/lumberjack/Lumberjack.hpp"
19
+ #include " axom/lumberjack/Communicator.hpp"
20
+
21
+ namespace axom
22
+ {
23
+ namespace lumberjack
24
+ {
25
+ /* !
26
+ *******************************************************************************
27
+ * \class NonBlockingRootCommunicator
28
+ *
29
+ * \brief Based off of RootCommunicator. This communicator pushes
30
+ messages from any rank to root non-collectively, if any messages are sent.
31
+ *******************************************************************************
32
+ */
33
+ class NonBlockingRootCommunicator : public axom ::lumberjack::Communicator
34
+ {
35
+ public:
36
+ /* !
37
+ *****************************************************************************
38
+ * \brief Called to initialize the Communicator.
39
+ *
40
+ * This performs any setup work the Communicator needs before doing any work.
41
+ * It is required that this is called before using the Communicator.
42
+ *
43
+ * \param [in] comm The MPI Communicator
44
+ * \param [in] ranksLimit Limit on how many ranks are individually tracked per
45
+ * Message.
46
+ *****************************************************************************
47
+ */
48
+ void initialize (MPI_Comm comm, int ranksLimit);
49
+
50
+ /* !
51
+ *****************************************************************************
52
+ * \brief Called to finalize the Communicator.
53
+ *
54
+ * This performs any cleanup work the Communicator needs to do before going
55
+ * away.It is required that this is the last function called by the
56
+ * Communicator.
57
+ *****************************************************************************
58
+ */
59
+ void finalize ();
60
+
61
+ /* !
62
+ *****************************************************************************
63
+ * \brief Returns the MPI rank of this node
64
+ *****************************************************************************
65
+ */
66
+ int rank ();
67
+
68
+ /* !
69
+ *****************************************************************************
70
+ * \brief Sets the rank limit.
71
+ *
72
+ * This is the limit on how many ranks generated a given message are
73
+ * individually tracked per Message. After the limit has been reached, only
74
+ * the Message::rankCount is incremented.
75
+ *
76
+ * \param [in] value Limits how many ranks are tracked per Message.
77
+ *****************************************************************************
78
+ */
79
+ void ranksLimit (int value);
80
+
81
+ /* !
82
+ *****************************************************************************
83
+ * \brief Returns the rank limit.
84
+ *
85
+ * This is the limit on how many ranks generated a given message are
86
+ * individually tracked per Message. After the limit has been reached, only
87
+ * the Message::rankCount is incremented.
88
+ *****************************************************************************
89
+ */
90
+ int ranksLimit ();
91
+
92
+ /* !
93
+ *****************************************************************************
94
+ * \brief Function used by the Lumberjack class to indicate how many
95
+ * individual pushes fully flush all currently held Message classes to the
96
+ * root node. The Communicator class's tree structure dictates this.
97
+ *****************************************************************************
98
+ */
99
+ int numPushesToFlush ();
100
+
101
+ /* !
102
+ *****************************************************************************
103
+ * \brief This pushes all messages to the root node.
104
+ *
105
+ * All messages are pushed to the root node. This is the same as
106
+ * RootCommunicator::pushMessagesFully for this Communicator.
107
+ *
108
+ * \param [in] packedMessagesToBeSent All of this rank's Message classes
109
+ * packed into a single buffer.
110
+ * \param [in,out] receivedPackedMessages Received packed message buffers from
111
+ * this nodes children.
112
+ *****************************************************************************
113
+ */
114
+ void push (const char * packedMessagesToBeSent,
115
+ std::vector<const char *>& receivedPackedMessages);
116
+
117
+ /* !
118
+ *****************************************************************************
119
+ * \brief Function used by the Lumberjack to indicate whether this node should
120
+ * be outputting messages. Only the root node outputs messages.
121
+ *****************************************************************************
122
+ */
123
+ bool isOutputNode ();
124
+
125
+ private:
126
+ MPI_Comm m_mpiComm;
127
+ int m_mpiCommRank;
128
+ int m_mpiCommSize;
129
+ int m_ranksLimit;
130
+ };
131
+
132
+ } // end namespace lumberjack
133
+ } // end namespace axom
134
+
135
+ #endif
0 commit comments