vt 1.6.0
(Virtual Transport)
Loading...
Searching...
No Matches
active.h
Go to the documentation of this file.
1/*
2//@HEADER
3// *****************************************************************************
4//
5// active.h
6// DARMA/vt => Virtual Transport
7//
8// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
9// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
10// Government retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are met:
14//
15// * Redistributions of source code must retain the above copyright notice,
16// this list of conditions and the following disclaimer.
17//
18// * Redistributions in binary form must reproduce the above copyright notice,
19// this list of conditions and the following disclaimer in the documentation
20// and/or other materials provided with the distribution.
21//
22// * Neither the name of the copyright holder nor the names of its
23// contributors may be used to endorse or promote products derived from this
24// software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36// POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact darma@sandia.gov
39//
40// *****************************************************************************
41//@HEADER
42*/
43
44#if !defined INCLUDED_VT_MESSAGING_ACTIVE_H
45#define INCLUDED_VT_MESSAGING_ACTIVE_H
46
47#include <cstdint>
48#include <memory>
49#include <mpi.h>
50
51#include "vt/config.h"
60#include "vt/event/event.h"
65#include "vt/elm/elm_id.h"
66#include "vt/elm/elm_lb_data.h"
69
70#if vt_check_enabled(trace_enabled)
72#endif
73
74#include <type_traits>
75#include <tuple>
76#include <vector>
77#include <unordered_map>
78#include <limits>
79#include <stack>
80
81namespace vt {
82
84using PtrLenPairType = std::tuple<std::byte*, ByteType>;
85
88 std::function<void(PtrLenPairType data, ActionType deleter)>;
89
90} /* end namespace vt */
91
92namespace vt {
93
94struct StrongNodeType { };
96
97namespace messaging {
98
100
101using MPI_TagType = int;
102
103static constexpr TagType const PutPackedTag =
104 std::numeric_limits<TagType>::max();
105
106enum class MPITag : MPI_TagType {
109
110 // Size-class active message tags
111 ActiveMsgS = 11, // <= 512 bytes
112 ActiveMsgM = 12, // <= 2048 bytes
113 ActiveMsgL = 13, // <= 8192 bytes
114 ActiveMsgXL = 14 // <= 32768 bytes
115};
116
117static constexpr TagType const starting_direct_buffer_tag = 1000;
118static constexpr MsgSizeType const max_pack_direct_size = 512;
119
126 int nchunks = 0;
127 std::byte* user_buf = nullptr;
130 NodeType sender = uninitialized_destination;
131 PriorityType priority = no_priority;
132 bool is_user_buf = false;
133
135 int in_nchunks, std::byte* in_user_buf, ContinuationDeleterType in_cont,
136 ActionType in_dealloc_user_buf, NodeType node,
137 PriorityType in_priority, bool in_is_user_buf
138 ) : nchunks(in_nchunks), user_buf(in_user_buf), cont(in_cont),
139 dealloc_user_buf(in_dealloc_user_buf), sender(node),
140 priority(in_priority), is_user_buf(in_is_user_buf)
141 { }
142
143 template <typename Serializer>
144 void serialize(Serializer& s) {
145 s | nchunks
146 | user_buf
147 | cont
149 | sender
150 | priority
151 | is_user_buf;
152 }
153};
154
162 std::byte* in_buf, MsgSizeType in_probe_bytes, NodeType in_sender
163 ) : buf(in_buf), probe_bytes(in_probe_bytes), sender(in_sender),
164 valid(true)
165 { }
166
167 template <typename Serializer>
168 void serialize(Serializer& s) {
169 s | buf
171 | sender
172 | valid;
173 }
174
175 std::byte* buf = nullptr;
177 NodeType sender = uninitialized_destination;
178 bool valid = false;
179};
180
187
189 std::byte* in_buf, MsgSizeType in_probe_bytes, NodeType in_sender,
190 MPI_Request in_req = MPI_REQUEST_NULL
191 ) : InProgressBase(in_buf, in_probe_bytes, in_sender),
192 req(in_req)
193 { }
194
195 bool test(int& num_mpi_tests) {
196 VT_ALLOW_MPI_CALLS; // MPI_Test
197
198 int flag = 0;
199 MPI_Status stat;
200 MPI_Test(&req, &flag, &stat);
201 num_mpi_tests++;
202 return flag;
203 }
204
205private:
206 MPI_Request req = MPI_REQUEST_NULL;
207};
208
216 std::byte* in_buf, MsgSizeType in_probe_bytes, NodeType in_sender,
217 std::vector<MPI_Request> in_reqs, std::byte* const in_user_buf,
218 ActionType in_dealloc_user_buf,
220 PriorityType in_priority
221 ) : InProgressBase{in_buf, in_probe_bytes, in_sender},
222 user_buf(in_user_buf), dealloc_user_buf(in_dealloc_user_buf),
223 next(in_next), priority(in_priority), reqs(std::move(in_reqs))
224 { }
225
226 bool test(int& num_mpi_tests) {
227 int flag = 0;
228 MPI_Status stat;
229 for ( ; cur < reqs.size(); cur++) {
230 VT_ALLOW_MPI_CALLS; // MPI_Test
231
232 MPI_Test(&reqs[cur], &flag, &stat);
233 num_mpi_tests++;
234
235 if (flag == 0) {
236 return false;
237 }
238 }
239
240 return true;
241 }
242
243 template <typename Serializer>
244 void serialize(Serializer& s) {
245 s | user_buf
247 | next
248 | priority
249 | cur
250 | reqs;
251 }
252
253 std::byte* user_buf = nullptr;
256 PriorityType priority = no_priority;
257
258private:
259 std::size_t cur = 0;
260 std::vector<MPI_Request> reqs;
261};
262
270
274
276 MessageType const& in_buffered_msg, NodeType const& in_from_node,
277 ActionType in_cont
278 ) : buffered_msg(in_buffered_msg), from_node(in_from_node), cont(in_cont)
279 { }
280
281 template <typename Serializer>
282 void serialize(Serializer& s) {
283 s | buffered_msg
284 | from_node
285 | cont;
286 }
287};
288
289// forward-declare for header
290struct MultiMsg;
291
330 using CountType = int32_t;
334 using UserSendFnType = std::function<void(SendFnType)>;
335 using ContainerPendingType = std::unordered_map<TagType,PendingRecvType>;
336 using ReadyHanTagType = std::tuple<HandlerType, TagType>;
339
344
348 virtual ~ActiveMessenger();
349
350 std::string name() override { return "ActiveMessenger"; }
351
352 void startup() override;
353 void initialize() override;
354
364 template <typename MsgPtrT>
365 void markAsTermMessage(MsgPtrT const msg);
366
372 template <typename MsgPtrT>
373 void markAsLocationMessage(MsgPtrT const msg);
374
380 template <typename MsgPtrT>
381 void markAsSerialMsgMessage(MsgPtrT const msg);
382
388 template <typename MsgPtrT>
389 void markAsCollectionMessage(MsgPtrT const msg);
390
397 template <typename MsgT>
398 void setEpochMessage(MsgT* msg, EpochType epoch);
399
407 template <typename MsgT>
408 void setTagMessage(MsgT* msg, TagType tag);
409
411 HandlerType const handler, ByteType serialized_msg_size, bool is_bcast
412 );
413
414 // With serialization, the correct method is resolved via SFINAE.
415 // This also includes additional guards to detect ambiguity.
416 template <typename MsgT>
418 NodeType dest,
419 HandlerType han,
421 TagType tag
422 );
423
424 // All messages that do NOT define their own serialization policy
425 // and do NOT define their own serialization function are required
426 // to be byte-transmittable. This covers basic byte-copyable
427 // messages directly inheriting from ActiveMsg. ActivMsg implements
428 // a serialize function which is implicitly inherited..
429 template <
430 typename MsgT,
431 std::enable_if_t<true
432 and not ::vt::messaging::msg_defines_serialize_mode<MsgT>::value,
433 int
434 > = 0
435 >
437 NodeType dest,
438 HandlerType han,
440 TagType tag
441 ) {
442#ifndef vt_quirked_serialize_method_detection
443 static_assert(
444 not ::vt::messaging::has_own_serialize<MsgT>,
445 "Message prohibiting serialization must not have a serialization function."
446 );
447#endif
448 return sendMsgCopyableImpl<MsgT>(dest, han, msg, tag);
449 }
450
451 // Serializable and serialization required on this type.
452 template <
453 typename MsgT,
454 std::enable_if_t<true
455 and ::vt::messaging::msg_defines_serialize_mode<MsgT>::value
456 and ::vt::messaging::msg_serialization_mode<MsgT>::required,
457 int
458 > = 0
459 >
461 NodeType dest,
462 HandlerType han,
464 TagType tag
465 ) {
466#ifndef vt_quirked_serialize_method_detection
467 static_assert(
468 ::vt::messaging::has_own_serialize<MsgT>,
469 "Message requiring serialization must have a serialization function."
470 );
471#endif
472 return sendMsgSerializableImpl<MsgT>(dest, han, msg, tag);
473 }
474
475 // Serializable, but support is only for derived types.
476 // This type will still be sent using byte-copy serialization.
477 template <
478 typename MsgT,
479 std::enable_if_t<true
480 and ::vt::messaging::msg_defines_serialize_mode<MsgT>::value
481 and ::vt::messaging::msg_serialization_mode<MsgT>::supported,
482 int
483 > = 0
484 >
486 NodeType dest,
487 HandlerType han,
489 TagType tag
490 ) {
491#ifndef vt_quirked_serialize_method_detection
492 static_assert(
493 ::vt::messaging::has_own_serialize<MsgT>,
494 "Message supporting serialization must have a serialization function."
495 );
496#endif
497 return sendMsgCopyableImpl<MsgT>(dest, han, msg, tag);
498 }
499
500 // Messaged marked as prohibiting serialization cannot define
501 // a serialization function and must be sent via byte-transmission.
502 template <
503 typename MsgT,
504 std::enable_if_t<true
505 and ::vt::messaging::msg_defines_serialize_mode<MsgT>::value
506 and ::vt::messaging::msg_serialization_mode<MsgT>::prohibited,
507 int
508 > = 0
509 >
511 NodeType dest,
512 HandlerType han,
514 TagType tag
515 ) {
516#ifndef vt_quirked_serialize_method_detection
517 static_assert(
518 not ::vt::messaging::has_own_serialize<MsgT>,
519 "Message prohibiting serialization must not have a serialization function."
520 );
521#endif
522 return sendMsgCopyableImpl<MsgT>(dest, han, msg, tag);
523 }
524
525 template <typename MsgT>
527 NodeType dest,
528 HandlerType han,
530 TagType tag
531 );
532
559
576 template <typename MsgT>
577 [[deprecated("size must be set in makeMessageSz, use regular sendMsg")]]
579 NodeType dest,
580 HandlerType han,
582 ByteType msg_size,
583 TagType tag = no_tag
584 );
585
598 template <typename MsgT>
600 NodeType dest,
601 HandlerType han,
603 TagType tag = no_tag
604 );
605
620 template <typename MsgT>
622 NodeType dest,
623 HandlerType han,
625 TagType tag = no_tag
626 );
627
629
630 /*
631 *----------------------------------------------------------------------------
632 * End Basic Active Message Send with Pre-Registered Handler
633 *----------------------------------------------------------------------------
634 */
635
661
677 template <typename MsgT, ActiveTypedFnType<MsgT>* f>
680 ByteType msg_size,
681 bool deliver_to_sender = true,
682 TagType tag = no_tag
683 );
684
696 template <typename MsgT, ActiveTypedFnType<MsgT>* f>
699 bool deliver_to_sender = true,
700 TagType tag = no_tag
701 );
702
714 template <auto f>
716 MsgPtrThief<typename FuncTraits<decltype(f)>::MsgT> msg,
717 bool deliver_to_sender = true,
718 TagType tag = no_tag
719 ) {
720 using MsgT = typename FuncTraits<decltype(f)>::MsgT;
721 return broadcastMsg<MsgT, f>(msg, deliver_to_sender, tag);
722 }
723
735 template <typename MsgT, ActiveTypedFnType<MsgT>* f>
737 NodeType dest,
739 TagType tag = no_tag
740 );
741
753 template <auto f>
755 NodeType dest,
756 MsgPtrThief<typename FuncTraits<decltype(f)>::MsgT> msg,
757 TagType tag = no_tag
758 ) {
759 using MsgT = typename FuncTraits<decltype(f)>::MsgT;
760 return sendMsg<MsgT, f>(dest, msg, tag);
761 }
762
771 template <auto f, typename... Params>
772 PendingSendType send(Node dest, Params&&... params) {
773 using Tuple = typename FuncTraits<decltype(f)>::TupleType;
774 using MsgT = ParamMsg<Tuple>;
775 auto msg = vt::makeMessage<MsgT>();
776 msg->setParams(std::forward<Params>(params)...);
778 return sendMsg<MsgT>(dest.get(), han, msg, no_tag);
779 }
780
788 template <auto f, typename... Params>
789 PendingSendType broadcast(Params&&... params) {
790 using Tuple = typename FuncTraits<decltype(f)>::TupleType;
791 using MsgT = ParamMsg<Tuple>;
792 auto msg = vt::makeMessage<MsgT>();
793 msg->setParams(std::forward<Params>(params)...);
795 constexpr bool deliver_to_sender = true;
796 return broadcastMsg<MsgT>(han, msg, deliver_to_sender, no_tag);
797 }
798
815 template <typename MsgT, ActiveTypedFnType<MsgT>* f>
816 [[deprecated("size must be set in makeMessageSz, use regular sendMsg")]]
818 NodeType dest,
820 ByteType msg_size,
821 TagType tag = no_tag
822 );
823
836 template <typename MsgT, ActiveTypedFnType<MsgT>* f>
839 TagType tag = no_tag
840 );
841
855 template <typename MsgT, ActiveTypedFnType<MsgT>* f>
857 NodeType dest,
859 TagType tag = no_tag
860 );
861
863
864 /*
865 *----------------------------------------------------------------------------
866 * End Send Message Active Function (type-safe handler)
867 *----------------------------------------------------------------------------
868 */
869
901
913 template <ActiveFnType* f, typename MsgT>
916 bool deliver_to_sender = true,
917 TagType tag = no_tag
918 );
919
931 template <ActiveFnType* f, typename MsgT>
933 NodeType dest,
935 TagType tag = no_tag
936 );
937
939
940 /*
941 *----------------------------------------------------------------------------
942 * End Send Message BASIC Active Function (deprecated?)
943 *----------------------------------------------------------------------------
944 */
945
974
986 template <
987 typename FunctorT,
988 typename MsgT
989 >
992 bool deliver_to_sender = true,
993 TagType tag = no_tag
994 );
995
1007 template <typename FunctorT>
1010 bool deliver_to_sender = true,
1011 TagType tag = no_tag
1012 );
1013
1026 template <
1027 typename FunctorT,
1028 typename MsgT = typename util::FunctorExtractor<FunctorT>::MessageType
1029 >
1032 TagType tag = no_tag
1033 );
1034
1046 template <typename FunctorT,typename MsgT>
1048 NodeType dest,
1050 TagType tag = no_tag
1051 );
1052
1064 template <typename FunctorT>
1066 NodeType dest,
1068 TagType tag = no_tag
1069 );
1070
1084 template <
1085 typename FunctorT,
1086 typename MsgT = typename util::FunctorExtractor<FunctorT>::MessageType
1087 >
1089 NodeType dest,
1091 TagType tag = no_tag
1092 );
1093
1095
1096 /*
1097 *----------------------------------------------------------------------------
1098 * End Send Message Functor Variants
1099 *----------------------------------------------------------------------------
1100 */
1101
1141
1154 template <typename MsgT>
1156 HandlerType han,
1158 bool deliver_to_sender = true,
1159 TagType tag = no_tag
1160 );
1161
1174 template <typename MsgT>
1176 NodeType dest,
1177 HandlerType han,
1179 UserSendFnType send_payload_fn
1180 );
1181
1193 template <typename MsgT, ActiveTypedFnType<MsgT>* f>
1195 NodeType dest,
1197 UserSendFnType send_payload_fn
1198 );
1199
1213 template <typename MsgT>
1215 HandlerType han,
1217 TagType tag = no_tag
1218 );
1219
1221
1222 /*
1223 *----------------------------------------------------------------------------
1224 * End Send Data Message
1225 *----------------------------------------------------------------------------
1226 */
1227
1244 MessageType* msg, MsgSizeType size, std::byte* ptr, MsgSizeType ptr_bytes
1245 );
1246
1258 PtrLenPairType const& ptr, NodeType const& dest, TagType const& tag
1259 );
1260
1271 std::tuple<EventType, int> sendDataMPI(
1272 PtrLenPairType const& ptr, NodeType const& dest, TagType const& tag
1273 );
1274
1288 int nchunks, PriorityType priority, TagType const& tag,
1289 NodeType const& node, ContinuationDeleterType next = nullptr
1290 );
1291
1303 bool recvDataMsg(
1304 int nchunks, TagType const& tag, NodeType const& node,
1305 ContinuationDeleterType next = nullptr
1306 );
1307
1321 bool recvDataMsg(
1322 int nchunks, PriorityType priority, TagType const& tag,
1323 NodeType const& sender, bool const& enqueue,
1324 ContinuationDeleterType next = nullptr
1325 );
1326
1343 bool recvDataMsgBuffer(
1344 int nchunks, std::byte* const user_buf, PriorityType priority, TagType const& tag,
1345 NodeType const& node = uninitialized_destination, bool const& enqueue = true,
1346 ActionType dealloc_user_buf = nullptr,
1347 ContinuationDeleterType next = nullptr, bool is_user_buf = false
1348 );
1349
1365 bool recvDataMsgBuffer(
1366 int nchunks, std::byte* const user_buf, TagType const& tag,
1367 NodeType const& node = uninitialized_destination, bool const& enqueue = true,
1368 ActionType dealloc_user_buf = nullptr,
1369 ContinuationDeleterType next = nullptr, bool is_user_buf = false
1370 );
1371
1387 void recvDataDirect(
1388 int nchunks, std::byte* const buf, TagType const tag, NodeType const from,
1389 MsgSizeType len, PriorityType prio, ActionType dealloc = nullptr,
1390 ContinuationDeleterType next = nullptr, bool is_user_buf = false
1391#if MPI_VERSION >= 3
1392 , MPI_Message first_msg = MPI_MESSAGE_NULL, MsgSizeType first_chunk_bytes = 0
1393#endif
1394 );
1395
1405 void recvDataDirect(
1406 int nchunks, TagType const tag, NodeType const from,
1408 );
1409
1422 );
1423
1431
1438 bool tryProcessDataMsgRecv();
1439
1448 int progress(TimeType current_time) override;
1449
1463 void processActiveMsg(
1464 MsgSharedPtr<BaseMsgType> const& base, NodeType const& sender,
1465 bool insert, ActionType cont = nullptr
1466 );
1467
1478 MsgSharedPtr<BaseMsgType> const& base, NodeType const& from_node,
1479 bool insert, ActionType cont
1480 );
1481
1494 NodeType const& dest, MsgSharedPtr<BaseMsgType> const& base,
1495 MsgSizeType const& msg_size, TagType const& send_tag
1496 );
1497
1508 NodeType const& dest, MsgSharedPtr<BaseMsgType> const& base
1509 );
1510
1524 NodeType const& dest, MsgSharedPtr<BaseMsgType> const& base,
1525 MsgSizeType const& msg_size, TagType const& send_tag
1526 );
1527
1538 inline void pushEpoch(EpochType const& epoch);
1539
1554 inline EpochType popEpoch(EpochType const& epoch = no_epoch);
1555
1562 inline EpochType getEpoch() const;
1563
1573 template <typename MsgT>
1574 inline EpochType getEpochContextMsg(MsgT* msg);
1575
1585 template <typename MsgT>
1587
1601 template <typename MsgT>
1602 inline EpochType setupEpochMsg(MsgT* msg);
1603
1612 template <typename MsgT>
1613 inline EpochType setupEpochMsg(MsgSharedPtr<MsgT> const& msg);
1614
1620 void registerAsyncOp(std::unique_ptr<AsyncOp> op);
1621
1631 void blockOnAsyncOp(std::unique_ptr<AsyncOp> op);
1632
1633 template <typename SerializerT>
1634 void serialize(SerializerT& s) {
1635 s | pending_recvs_
1640 | this_node_
1643 | amPollCount
1648 | dmPollCount
1652 | tdRecvCount
1653 | tdSentCount;
1654
1655 # if vt_check_enabled(trace_enabled)
1656 s | trace_irecv
1657 | trace_isend
1658 | trace_irecv_polling_am
1659 | trace_irecv_polling_dm
1660 | trace_asyncop;
1661 # endif
1662 }
1663
1664private:
1674
1682
1689 static void chunkedMultiMsg(MultiMsg* msg);
1690
1697
1704
1710 bool testPendingAsyncOps();
1711
1716
1721
1730 NodeType const dest, MsgSharedPtr<BaseMsgType> const& base,
1731 MsgSizeType const msg_size
1732 );
1733
1740
1749 struct Slot {
1750 int cap = 0;
1752 std::byte* buf = nullptr;
1753 MPI_Request req = MPI_REQUEST_NULL;
1754 bool posted = false;
1755 };
1756
1757 void setup(ActiveMessenger* self);
1758 bool progress(ActiveMessenger* self);
1759
1760 static constexpr int num_caps_ = 4;
1761 static constexpr int caps_[num_caps_] = {512, 2048, 8192, 32768};
1762 private:
1763 std::vector<Slot> slots_;
1764 static constexpr MPI_TagType tags_[num_caps_] = {
1765 static_cast<MPI_TagType>(MPITag::ActiveMsgS),
1766 static_cast<MPI_TagType>(MPITag::ActiveMsgM),
1767 static_cast<MPI_TagType>(MPITag::ActiveMsgL),
1768 static_cast<MPI_TagType>(MPITag::ActiveMsgXL)
1769 };
1770 static constexpr int slots_per_class_ = 4;
1771
1772 void postSlot(ActiveMessenger* self, Slot& s);
1773 public:
1774 // Cleanup outstanding posted receives and buffers to avoid leaks at shutdown
1775 void cleanup();
1776 };
1777
1778public:
1785 return std::make_tuple(
1788 );
1789 }
1790
1791private:
1792# if vt_check_enabled(trace_enabled)
1793 trace::UserEventIDType trace_irecv = trace::no_user_event_id;
1794 trace::UserEventIDType trace_isend = trace::no_user_event_id;
1795 trace::UserEventIDType trace_irecv_polling_am = trace::no_user_event_id;
1796 trace::UserEventIDType trace_irecv_polling_dm = trace::no_user_event_id;
1797 trace::UserEventIDType trace_asyncop = trace::no_user_event_id;
1798# endif
1799
1801 TagType cur_direct_buffer_tag_ = starting_direct_buffer_tag;
1805 NodeType this_node_ = uninitialized_destination;
1806
1807private:
1808 // Diagnostic counter gauge combos for sent counts/bytes
1811
1812 // Diagnostic counters for recv counts/bytes
1815
1816 // Diagnostic counters for posted irecv counts/bytes
1819
1820 // Diagnostic counters for counting various actions
1827
1828 // Diagnostic counters for counting forwarded messages
1830
1831private:
1834 MPI_Comm comm_ = MPI_COMM_NULL;
1835
1836 // Active receive broker instance
1838};
1839
1840}} // end namespace vt::messaging
1841
1842namespace vt {
1843
1845
1847
1848} // end namespace vt
1849
1851
1852#endif /*INCLUDED_VT_MESSAGING_ACTIVE_H*/
PendingSendType broadcastMsg(MsgPtrThief< MsgT > msg, bool deliver_to_sender=true, TagType tag=no_tag)
Broadcast a message with a type-safe handler.
PendingSendType sendMsg(NodeType dest, MsgPtrThief< MsgT > msg, TagType tag=no_tag)
Send a message with a type-safe handler.
PendingSendType broadcastMsg(MsgPtrThief< MsgT > msg, bool deliver_to_sender=true, TagType tag=no_tag)
Broadcast a message.
PendingSendType sendMsgAuto(NodeType dest, MsgPtrThief< MsgT > msg, TagType tag=no_tag)
Send a message.
PendingSendType broadcastMsgAuto(MsgPtrThief< MsgT > msg, TagType tag=no_tag)
Broadcast a message.
PendingSendType sendMsg(NodeType dest, MsgPtrThief< MsgT > msg, TagType tag=no_tag)
Send a message with a type-safe handler.
PendingSendType sendMsg(NodeType dest, HandlerType han, MsgPtrThief< MsgT > msg, TagType tag=no_tag)
Send a message with a pre-registered handler.
Definition active.impl.h:199
PendingSendType sendMsgSz(NodeType dest, HandlerType han, MsgPtrThief< MsgT > msg, ByteType msg_size, TagType tag=no_tag)
Send a message with a pre-registered handler.
Definition active.impl.h:210
PendingSendType sendMsgAuto(NodeType dest, HandlerType han, MsgPtrThief< MsgT > msg, TagType tag=no_tag)
Send a message with a pre-registered handler.
Definition active.impl.h:222
PendingSendType broadcast(Params &&... params)
Broadcast parameters to a handler in a message.
Definition active.h:789
PendingSendType broadcastMsg(MsgPtrThief< MsgT > msg, bool deliver_to_sender=true, TagType tag=no_tag)
Broadcast a message.
Definition active.impl.h:250
PendingSendType sendMsg(NodeType dest, MsgPtrThief< typename FuncTraits< decltype(f)>::MsgT > msg, TagType tag=no_tag)
Send a message (message type not required).
Definition active.h:754
PendingSendType send(Node dest, Params &&... params)
Send parameters to a handler in a message.
Definition active.h:772
PendingSendType broadcastMsgAuto(MsgPtrThief< MsgT > msg, TagType tag=no_tag)
Broadcast a message.
Definition active.impl.h:300
PendingSendType broadcastMsgSz(MsgPtrThief< MsgT > msg, ByteType msg_size, bool deliver_to_sender=true, TagType tag=no_tag)
Broadcast a message with an explicit size.
Definition active.impl.h:233
PendingSendType broadcastMsg(MsgPtrThief< typename FuncTraits< decltype(f)>::MsgT > msg, bool deliver_to_sender=true, TagType tag=no_tag)
Broadcast a message (message type not required).
Definition active.h:715
#define VT_ALLOW_MPI_CALLS
Definition mpi_access.h:52
Definition reduce_scope.h:265
HandlerType makeAutoHandlerParam()
runtime::component::meter::CounterGauge< CounterDefaultType, GaugeDefaultType > CounterGauge
Default diagnostic counter/gauge combo.
Definition diagnostic_meter.h:110
runtime::component::meter::Counter< CounterDefaultType > Counter
Default diagnostic counter for counting a value over time.
Definition diagnostic_meter.h:95
Definition epoch.h:51
Definition active.cc:62
MPITag
Definition active.h:106
@ ActiveMsgS
Definition active.h:111
@ ActiveMsgL
Definition active.h:113
@ DataMsgTag
Definition active.h:108
@ ActiveMsgTag
Definition active.h:107
@ ActiveMsgXL
Definition active.h:114
@ ActiveMsgM
Definition active.h:112
int MPI_TagType
Definition active.h:101
uint32_t TraceEventIDType
Definition trace_common.h:62
int64_t UserEventIDType
Definition trace_common.h:65
Definition activefn.h:51
int32_t TagType
Used to hold an tag, e.g., on messages or reduces.
Definition types_type.h:73
int64_t MsgSizeType
Used for hold the size of a message.
Definition types_type.h:101
messaging::ActiveMsg< Envelope > ShortMessage
Alias to the shortest message available with no epoch or tag allowed.
Definition message.h:211
std::function< void()> ActionType
Used for generically store an action to perform.
Definition types_type.h:125
uint64_t ByteType
Used to store some number of bytes.
Definition types_type.h:83
messaging::ActiveMessenger Active
Definition active.h:1844
std::tuple< std::byte *, ByteType > PtrLenPairType
A pair of a std::byte* and number of bytes (length) for sending data.
Definition active.h:84
uint64_t EventType
Used to hold a local/remote event to wait for completion.
Definition types_type.h:69
MsgPtr< MsgT > makeMessage(Args &&... args)
Create a new message.
Definition shared_message.impl.h:116
TimeTypeWrapper TimeType
Definition timing_type.h:176
PhysicalResourceType NodeType
Used to hold the current node/rank or the number of nodes.
Definition types_type.h:57
int64_t HandlerType
Used to hold a handler ID which identifier a function pointer/context.
Definition types_type.h:63
Strong< NodeType, uninitialized_destination, StrongNodeType > Node
Definition active.h:95
util::strong::detail::Strong< T, init_val, Tag > Strong
Type-alias for strong types.
Definition strong_type.h:195
uint16_t PriorityType
Used for hold the priority of a message.
Definition types_type.h:113
messaging::ActiveMessenger * theMsg()
Definition runtime_get.cc:103
epoch::EpochType EpochType
The strong epoch type for holding a epoch for termination detection.
Definition epoch_type.h:118
std::function< void(PtrLenPairType data, ActionType deleter)> ContinuationDeleterType
A continuation function with an allocated pointer with a deleter function.
Definition active.h:87
Definition fntraits.h:390
Definition handler.h:96
Definition active.h:94
A general identifier for a task context. The id is unique in the system.
Definition elm_id.h:67
Definition elm_lb_data.h:59
EventRecord EventRecordType
Definition event.h:89
Active receive broker that keeps a pool of pre-posted Irecv slots per size-class tag to drain unexpec...
Definition active.h:1748
static constexpr int slots_per_class_
Definition active.h:1770
bool progress(ActiveMessenger *self)
Definition active.cc:1377
static constexpr MPI_TagType tags_[num_caps_]
Definition active.h:1764
void setup(ActiveMessenger *self)
Definition active.cc:1356
static constexpr int caps_[num_caps_]
Definition active.h:1761
void cleanup()
Definition active.cc:1426
void postSlot(ActiveMessenger *self, Slot &s)
Definition active.cc:1323
static constexpr int num_caps_
Definition active.h:1760
std::vector< Slot > slots_
Definition active.h:1763
Core component of VT used to send messages.
Definition active.h:327
auto getRankLBData()
Get the rank-based LB data along with element ID for rank-based work.
Definition active.h:1784
void markAsCollectionMessage(MsgPtrT const msg)
Mark a message as a collection message.
Definition active.impl.h:92
std::function< SendInfo(PtrLenPairType, NodeType, TagType)> SendFnType
Definition active.h:333
diagnostic::Counter amPollCount
Definition active.h:1823
void processActiveMsg(MsgSharedPtr< BaseMsgType > const &base, NodeType const &sender, bool insert, ActionType cont=nullptr)
Process an incoming active message.
Definition active.cc:998
virtual ~ActiveMessenger()
Definition active.cc:170
bool testPendingActiveMsgAsyncRecv()
Test pending MPI request for active message receives.
Definition active.cc:1289
void recordLBDataCommForSend(NodeType const dest, MsgSharedPtr< BaseMsgType > const &base, MsgSizeType const msg_size)
Record LB's data for sending a message.
Definition active.cc:967
void startup() override
Empty default overridden startup method.
Definition active.cc:153
void finishPendingActiveMsgAsyncRecv(InProgressIRecv *irecv)
Called when a VT-MPI message has been received.
Definition active.cc:1221
static MPI_TagType selectActiveTag(MsgSizeType size)
Select an active message tag based on the size of the message.
Definition active.cc:217
RequestHolder< AsyncOpWrapper > in_progress_ops
Definition active.h:1804
diagnostic::Counter tdRecvCount
Definition active.h:1826
PendingSend PendingSendType
Definition active.h:338
std::unordered_map< TagType, PendingRecvType > ContainerPendingType
Definition active.h:335
void registerAsyncOp(std::unique_ptr< AsyncOp > op)
Register a async operation that needs polling.
Definition active.cc:1459
void handleChunkedMultiMsg(MultiMsg *msg)
Handle a control message that coordinates multiple payloads arriving that constitute a contiguous pay...
Definition active.cc:320
diagnostic::CounterGauge amForwardCounterGauge
Definition active.h:1829
std::string name() override
Get the name of the component.
Definition active.h:350
ActiveMessenger::PendingSendType sendMsgCopyableImpl(NodeType dest, HandlerType han, MsgSharedPtr< MsgT > &msg, TagType tag)
Definition active.impl.h:147
NodeType this_node_
Definition active.h:1805
RequestHolder< InProgressDataIRecv > in_progress_data_irecv
Definition active.h:1803
std::function< void(SendFnType)> UserSendFnType
Definition active.h:334
int progress(TimeType current_time) override
Call into the progress engine.
Definition active.cc:1446
void setEpochMessage(MsgT *msg, EpochType epoch)
Set the epoch in the envelope of a message.
Definition active.impl.h:101
diagnostic::CounterGauge dmPostedCounterGauge
Definition active.h:1818
EpochType getEpoch() const
Pop an epoch off the stack.
Definition active.impl.h:468
bool tryProcessIncomingActiveMsg()
Poll MPI to discover an incoming message with a handler.
Definition active.cc:1032
diagnostic::Counter amHandlerCount
Definition active.h:1821
ShortMessage MessageType
Definition active.h:329
trace::TraceEventIDType makeTraceCreationSend(HandlerType const handler, ByteType serialized_msg_size, bool is_bcast)
Definition active.cc:175
ContainerPendingType pending_recvs_
Definition active.h:1800
EpochType setupEpochMsg(MsgT *msg)
Set the epoch on a message.
Definition active.impl.h:506
void finishPendingDataMsgAsyncRecv(InProgressDataIRecv *irecv)
Called when a VT-MPI message has been received.
Definition active.cc:921
BufferedActiveMsg BufferedMsgType
Definition active.h:328
elm::ElementLBData bare_handler_lb_data_
Definition active.h:1833
diagnostic::CounterGauge amSentCounterGauge
Definition active.h:1809
diagnostic::Counter tdSentCount
Definition active.h:1825
diagnostic::CounterGauge dmRecvCounterGauge
Definition active.h:1814
void recvDataDirect(int nchunks, std::byte *const buf, TagType const tag, NodeType const from, MsgSizeType len, PriorityType prio, ActionType dealloc=nullptr, ContinuationDeleterType next=nullptr, bool is_user_buf=false)
Receive data from MPI in multiple chunks.
Definition active.cc:810
diagnostic::CounterGauge dmSentCounterGauge
Definition active.h:1810
std::tuple< HandlerType, TagType > ReadyHanTagType
Definition active.h:336
SendInfo sendData(PtrLenPairType const &ptr, NodeType const &dest, TagType const &tag)
Send raw bytes to a node.
Definition active.cc:543
TagType cur_direct_buffer_tag_
Definition active.h:1801
void prepareActiveMsgToRun(MsgSharedPtr< BaseMsgType > const &base, NodeType const &from_node, bool insert, ActionType cont)
Prepare an active message to run by building a RunnableNew.
Definition active.cc:1167
bool recvDataMsg(int nchunks, TagType const &tag, NodeType const &node, ContinuationDeleterType next=nullptr)
Receive data as bytes from a node.
Definition active.cc:654
EpochType getEpochContextMsg(MsgT *msg)
Get the epoch for a message based on the current context so an subsequent operation on it can be safe...
Definition active.impl.h:473
bool testPendingAsyncOps()
Test pending general asynchronous events.
Definition active.cc:1313
int32_t CountType
Definition active.h:330
EventType doMessageSend(MsgSharedPtr< BaseMsgType > &msg)
Low-level send of a message, handler and other control data should be set already.
Definition active.cc:456
ActiveMessenger::PendingSendType sendMsgImpl(NodeType dest, HandlerType han, MsgSharedPtr< MsgT > &msg, TagType tag)
Definition active.h:436
void serialize(SerializerT &s)
Definition active.h:1634
elm::ElementIDStruct bare_handler_dummy_elm_id_for_lb_data_
Definition active.h:1832
EventType sendMsgBytes(NodeType const &dest, MsgSharedPtr< BaseMsgType > const &base, MsgSizeType const &msg_size, TagType const &send_tag)
Send message as low-level bytes after packing put bytes if needed.
Definition active.cc:413
ActiveMessenger()
Definition active.cc:64
void setTagMessage(MsgT *msg, TagType tag)
Set the tag in the envelope of a message.
Definition active.impl.h:106
bool recvDataMsgBuffer(int nchunks, std::byte *const user_buf, PriorityType priority, TagType const &tag, NodeType const &node=uninitialized_destination, bool const &enqueue=true, ActionType dealloc_user_buf=nullptr, ContinuationDeleterType next=nullptr, bool is_user_buf=false)
Receive data as bytes with a buffer and priority.
Definition active.cc:700
diagnostic::Counter dmPollCount
Definition active.h:1824
void pushEpoch(EpochType const &epoch)
Push an epoch on the stack.
Definition active.impl.h:460
HandlerManager HandlerManagerType
Definition active.h:337
void initialize() override
Empty default overridden initialize method.
Definition active.cc:149
EventType sendMsgMPI(NodeType const &dest, MsgSharedPtr< BaseMsgType > const &base, MsgSizeType const &msg_size, TagType const &send_tag)
Send already-packed message bytes with MPI using multiple sends if necessary.
Definition active.cc:342
MPI_Comm comm_
Definition active.h:1834
void markAsTermMessage(MsgPtrT const msg)
Mark a message as a termination message.
Definition active.impl.h:63
ActiveRecvBroker active_broker_
Definition active.h:1837
MsgSizeType packMsg(MessageType *msg, MsgSizeType size, std::byte *ptr, MsgSizeType ptr_bytes)
Pack a message, used by the system.
Definition active.cc:194
std::tuple< EventType, int > sendDataMPI(PtrLenPairType const &ptr, NodeType const &dest, TagType const &tag)
Send raw bytes to a node with potentially multiple sends.
Definition active.cc:581
void blockOnAsyncOp(std::unique_ptr< AsyncOp > op)
Block the current task's execution on an pollable async operation until it completes.
Definition active.cc:1463
PendingRecv PendingRecvType
Definition active.h:331
ActiveMessenger::PendingSendType sendMsgSerializableImpl(NodeType dest, HandlerType han, MsgSharedPtr< MsgT > &msg, TagType tag)
Definition active.impl.h:111
void markAsSerialMsgMessage(MsgPtrT const msg)
Mark a message as a serialization control message.
Definition active.impl.h:83
diagnostic::Counter bcastsSentCount
Definition active.h:1822
void markAsLocationMessage(MsgPtrT const msg)
Mark a message as a location message.
Definition active.impl.h:74
bool testPendingDataMsgAsyncRecv()
Test pending MPI request for data message receives.
Definition active.cc:1301
static void chunkedMultiMsg(MultiMsg *msg)
Handle a control message; immediately calls handleChunkedMultiMsg.
Definition active.cc:316
diagnostic::CounterGauge amPostedCounterGauge
Definition active.h:1817
RequestHolder< InProgressIRecv > in_progress_active_msg_irecv
Definition active.h:1802
event::AsyncEvent::EventRecordType EventRecordType
Definition active.h:332
EventType sendMsgBytesWithPut(NodeType const &dest, MsgSharedPtr< BaseMsgType > const &base)
Send message as low-level bytes that is already packed.
Definition active.cc:225
diagnostic::CounterGauge amRecvCounterGauge
Definition active.h:1813
MPI_TagType allocateNewTag()
Allocate a new, unused tag.
Definition active.cc:532
bool tryProcessDataMsgRecv()
Poll MPI for raw data messages.
Definition active.cc:661
bool recvDataMsgPriority(int nchunks, PriorityType priority, TagType const &tag, NodeType const &node, ContinuationDeleterType next=nullptr)
Receive data as bytes from a node with a priority.
Definition active.cc:647
Holds a buffered active message, used internally.
Definition active.h:268
MsgSharedPtr< BaseMsgType > MessageType
Definition active.h:269
NodeType from_node
Definition active.h:272
BufferedActiveMsg(MessageType const &in_buffered_msg, NodeType const &in_from_node, ActionType in_cont)
Definition active.h:275
MessageType buffered_msg
Definition active.h:271
ActionType cont
Definition active.h:273
void serialize(Serializer &s)
Definition active.h:282
InProgressBase(std::byte *in_buf, MsgSizeType in_probe_bytes, NodeType in_sender)
Definition active.h:161
std::byte * buf
Definition active.h:175
bool valid
Definition active.h:178
MsgSizeType probe_bytes
Definition active.h:176
NodeType sender
Definition active.h:177
void serialize(Serializer &s)
Definition active.h:168
An in-progress pure data MPI_Irecv watched by the runtime.
Definition active.h:214
std::vector< MPI_Request > reqs
Definition active.h:260
ContinuationDeleterType next
Definition active.h:255
PriorityType priority
Definition active.h:256
bool test(int &num_mpi_tests)
Definition active.h:226
std::size_t cur
Definition active.h:259
ActionType dealloc_user_buf
Definition active.h:254
InProgressDataIRecv(std::byte *in_buf, MsgSizeType in_probe_bytes, NodeType in_sender, std::vector< MPI_Request > in_reqs, std::byte *const in_user_buf, ActionType in_dealloc_user_buf, ContinuationDeleterType in_next, PriorityType in_priority)
Definition active.h:215
void serialize(Serializer &s)
Definition active.h:244
std::byte * user_buf
Definition active.h:253
An in-progress MPI_Irecv watched by the runtime.
Definition active.h:186
InProgressIRecv(std::byte *in_buf, MsgSizeType in_probe_bytes, NodeType in_sender, MPI_Request in_req=MPI_REQUEST_NULL)
Definition active.h:188
bool test(int &num_mpi_tests)
Definition active.h:195
MPI_Request req
Definition active.h:206
Helper to unify 'stealing' message ownership.
Definition smart_ptr.h:313
Definition smart_ptr.h:99
Definition active.cc:299
Definition param_msg.h:150
An pending receive event.
Definition active.h:125
ActionType dealloc_user_buf
Definition active.h:129
bool is_user_buf
Definition active.h:132
ContinuationDeleterType cont
Definition active.h:128
NodeType sender
Definition active.h:130
int nchunks
Definition active.h:126
void serialize(Serializer &s)
Definition active.h:144
PriorityType priority
Definition active.h:131
std::byte * user_buf
Definition active.h:127
PendingRecv(int in_nchunks, std::byte *in_user_buf, ContinuationDeleterType in_cont, ActionType in_dealloc_user_buf, NodeType node, PriorityType in_priority, bool in_is_user_buf)
Definition active.h:134
A pending send (or other similar operation) that is delayed until this holder goes out of scope.
Definition pending_send.h:70
Holds a set of pending MPI Irecvs to poll for completion.
Definition request_holder.h:69
Returned from a data send to be used to receive the data.
Definition send_info.h:56
Component class for a generic, pollable VT runtime module, CRTP'ed over the component's actual type....
Definition component.h:161
MessageT MessageType
Definition functor.h:77
T & get()
Get reference.
Definition strong_type.h:153