SST 16.0.0
Structural Simulation Toolkit
rankSyncParallelSkip.h
1// Copyright 2009-2026 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2026, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_SYNC_RANKSYNCPARALLELSKIP_H
13#define SST_CORE_SYNC_RANKSYNCPARALLELSKIP_H
14
15#include "sst/core/sst_mpi.h"
16#include "sst/core/sst_types.h"
17#include "sst/core/sync/syncManager.h"
18#include "sst/core/threadsafe.h"
19
20#include <atomic>
21#include <cstdint>
22#include <map>
23#include <string>
24
25namespace SST {
26
27class RankSyncQueue;
28class TimeConverter;
29
30namespace Profile {
32};
33
34class RankSyncParallelSkip : public RankSync
35{
36public:
37 /** Create a new Sync object which fires with a specified period */
38 explicit RankSyncParallelSkip(RankInfo num_ranks);
39 RankSyncParallelSkip() {} // For serialization
40 virtual ~RankSyncParallelSkip();
41
42 /** Register a Link which this Sync Object is responsible for */
43 ActivityQueue* registerLink(const RankInfo& to_rank, const RankInfo& from_rank, Link* link) override;
44 void execute(int thread) override;
45
46 /** Cause an exchange of Untimed Data to occur */
47 void exchangeLinkUntimedData(int thread, std::atomic<int>& msg_count) override;
48 /** Finish link configuration */
49 void finalizeLinkConfigurations() override;
50 /** Prepare for complete() stage */
51 void prepareForComplete() override;
52
53 /** Set signals to exchange during sync */
54 void setSignals(int end, int usr, int alrm) override;
55 /** Return exchanged signals after sync */
56 bool getSignals(int& end, int& usr, int& alrm) override;
57
58 /** Set interactive flags to exchange during sync */
59 // Separated enter_interactive from from shutdown since they may be needed separately
60 void setShutdownFlags(bool enter_shutdown, Simulation::ShutdownMode_t shutdown_mode) override;
61 void setCkptFlag(bool generate_ckpt) override;
62 void setFlags(bool enter_interactive, bool enter_shutdown, Simulation::ShutdownMode_t shutdown_mode) override;
63 /** Return exchanged interactive flags after sync */
64 void getShutdownFlags(bool& enter_shutdown, Simulation::ShutdownMode_t& shutdown_mode) override;
65 void getCkptFlag(bool& generate_ckpt) override;
66 void getFlags(bool& enter_interactive, bool& enter_shutdown, Simulation::ShutdownMode_t& shutdown_mode) override;
67 /** Clear interactive flags before next run */
68 void clearFlags() override;
69
70 SimTime_t getNextSyncTime() override { return myNextSyncTime; }
71
72 void setRestartTime(SimTime_t time) override;
73
74 uint64_t getDataSize() const override;
75
76 void setProfileToolList(Profile::SyncProfileToolList* profile_tools) override;
77
78private:
79 static SimTime_t myNextSyncTime;
80
81 // Function that actually does the exchange during run
82 void exchange_master(int thread);
83 void exchange_slave(int thread);
84
85 struct comm_send_pair : public SST::Core::Serialization::serializable
86 {
87 RankInfo to_rank;
88 RankSyncQueue* squeue; // RankSyncQueue
89 char* sbuf;
90 uint32_t remote_size;
91
92 void serialize_order(SST::Core::Serialization::serializer& ser) override
93 {
94 SST_SER(to_rank);
95 // squeue - empty so recreate on restart
96 // sbuf - empty so recreate on restart
97 // remote_size - don't need
98 }
99 ImplementSerializable(comm_send_pair)
100 };
101
102 struct comm_recv_pair : public SST::Core::Serialization::serializable
103 {
104 uint32_t remote_rank;
105 uint32_t local_thread;
106 char* rbuf; // receive buffer
107 std::vector<Activity*> activity_vec;
108 uint32_t local_size;
109 bool recv_done;
110#ifdef SST_CONFIG_HAVE_MPI
111 MPI_Request req;
112#endif
113 void serialize_order(SST::Core::Serialization::serializer& ser) override
114 {
115 SST_SER(remote_rank);
116 SST_SER(local_thread);
117 // activity_vec - empty so recreate on restart
118 // rbuf - empty so recreate on restart
119 // recv_done - don't need
120 // req - don't need
121 }
122 ImplementSerializable(comm_recv_pair)
123 };
124
125 using comm_send_map_t = std::map<RankInfo, comm_send_pair>;
126 using comm_recv_map_t = std::map<RankInfo, comm_recv_pair>;
127 // using link_map_t = std::map<LinkId_t, Link*>;
128 using link_map_t = std::map<std::string, uintptr_t>;
129
130 // TimeConverter* period;
131 comm_send_map_t comm_send_map;
132 comm_recv_map_t comm_recv_map;
133 link_map_t link_map;
134
135 double mpiWaitTime;
136 double deserializeTime;
137
138 int* recv_count;
139 int send_count;
140
141 std::atomic<int32_t> remaining_deser;
146
147 void deserializeMessage(comm_recv_pair* msg);
148
149 Core::ThreadSafe::Barrier serializeReadyBarrier;
150 Core::ThreadSafe::Barrier slaveExchangeDoneBarrier;
151 Core::ThreadSafe::Barrier allDoneBarrier;
152
153 Profile::SyncProfileToolList* profile_tools_ = nullptr;
154
156 static int sig_end_;
157 static int sig_usr_;
158 static int sig_alrm_;
159 static std::atomic<bool> enter_interactive_;
160 static std::atomic<bool> enter_shutdown_;
161 static std::atomic<unsigned> shutdown_mode_;
162 static std::atomic<bool> generate_ckpt_;
163};
164
165} // namespace SST
166
167#endif // SST_CORE_SYNC_RANKSYNCPARALLELSKIP_H
Base Class for a queue of Activities.
Definition activityQueue.h:22
Definition serializable.h:25
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Definition threadsafe.h:50
Definition threadsafe.h:169
Definition threadsafe.h:138
Definition threadsafe.h:278
Definition syncProfileTool.h:145
Definition rankInfo.h:24
void getShutdownFlags(bool &enter_shutdown, Simulation::ShutdownMode_t &shutdown_mode) override
Return exchanged interactive flags after sync.
Definition rankSyncParallelSkip.cc:188
ActivityQueue * registerLink(const RankInfo &to_rank, const RankInfo &from_rank, Link *link) override
Register a Link which this Sync Object is responsible for.
Definition rankSyncParallelSkip.cc:88
void finalizeLinkConfigurations() override
Finish link configuration.
Definition rankSyncParallelSkip.cc:133
bool getSignals(int &end, int &usr, int &alrm) override
Return exchanged signals after sync.
Definition rankSyncParallelSkip.cc:155
void setSignals(int end, int usr, int alrm) override
Set signals to exchange during sync.
Definition rankSyncParallelSkip.cc:147
void setShutdownFlags(bool enter_shutdown, Simulation::ShutdownMode_t shutdown_mode) override
Set interactive flags to exchange during sync.
Definition rankSyncParallelSkip.cc:164
void clearFlags() override
Clear interactive flags before next run.
Definition rankSyncParallelSkip.cc:219
void exchangeLinkUntimedData(int thread, std::atomic< int > &msg_count) override
Cause an exchange of Untimed Data to occur.
Definition rankSyncParallelSkip.cc:467
void prepareForComplete() override
Prepare for complete() stage.
Definition rankSyncParallelSkip.cc:143
RankSyncParallelSkip(RankInfo num_ranks)
Create a new Sync object which fires with a specified period.
Definition rankSyncParallelSkip.cc:49
Definition syncQueue.h:62
A class to convert between a component's view of time and the core's view of time.
Definition timeConverter.h:31