SST  14.1.0
StructuralSimulationToolkit
rankSyncParallelSkip.h
1 // Copyright 2009-2024 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-2024, 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_types.h"
16 #include "sst/core/sync/syncManager.h"
17 #include "sst/core/threadsafe.h"
18 #include "sst/core/warnmacros.h"
19 
20 #include <map>
21 
22 #ifdef SST_CONFIG_HAVE_MPI
23 DISABLE_WARN_MISSING_OVERRIDE
24 #include <mpi.h>
25 REENABLE_WARNING
26 #endif
27 
28 namespace SST {
29 
30 class RankSyncQueue;
31 class TimeConverter;
32 
34 {
35 public:
36  /** Create a new Sync object which fires with a specified period */
37  RankSyncParallelSkip(RankInfo num_ranks);
38  RankSyncParallelSkip() {} // For serialization
39  virtual ~RankSyncParallelSkip();
40 
41  /** Register a Link which this Sync Object is responsible for */
43  registerLink(const RankInfo& to_rank, const RankInfo& from_rank, const std::string& name, 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  SimTime_t getNextSyncTime() override { return myNextSyncTime; }
59 
60  void setRestartTime(SimTime_t time) override;
61 
62  uint64_t getDataSize() const override;
63 
64 private:
65  static SimTime_t myNextSyncTime;
66 
67  // Function that actually does the exchange during run
68  void exchange_master(int thread);
69  void exchange_slave(int thread);
70 
71  struct comm_send_pair : public SST::Core::Serialization::serializable
72  {
73  RankInfo to_rank;
74  RankSyncQueue* squeue; // RankSyncQueue
75  char* sbuf;
76  uint32_t remote_size;
77 
78  void serialize_order(SST::Core::Serialization::serializer& ser) override
79  {
80  ser& to_rank;
81  // squeue - empty so recreate on restart
82  // sbuf - empty so recreate on restart
83  // remote_size - don't need
84  }
85  ImplementSerializable(comm_send_pair)
86  };
87 
88  struct comm_recv_pair : public SST::Core::Serialization::serializable
89  {
90  uint32_t remote_rank;
91  uint32_t local_thread;
92  char* rbuf; // receive buffer
93  std::vector<Activity*> activity_vec;
94  uint32_t local_size;
95  bool recv_done;
96 #ifdef SST_CONFIG_HAVE_MPI
97  MPI_Request req;
98 #endif
99  void serialize_order(SST::Core::Serialization::serializer& ser) override
100  {
101  ser& remote_rank;
102  ser& local_thread;
103  // activity_vec - empty so recreate on restart
104  // rbuf - empty so recreate on restart
105  // recv_done - don't need
106  // req - don't need
107  }
108  ImplementSerializable(comm_recv_pair)
109  };
110 
111  typedef std::map<RankInfo, comm_send_pair> comm_send_map_t;
112  typedef std::map<RankInfo, comm_recv_pair> comm_recv_map_t;
113  // typedef std::map<LinkId_t, Link*> link_map_t;
114  typedef std::map<std::string, uintptr_t> link_map_t;
115 
116  // TimeConverter* period;
117  comm_send_map_t comm_send_map;
118  comm_recv_map_t comm_recv_map;
119  link_map_t link_map;
120 
121  double mpiWaitTime;
122  double deserializeTime;
123 
124  int* recv_count;
125  int send_count;
126 
127  std::atomic<int32_t> remaining_deser;
132 
133  void deserializeMessage(comm_recv_pair* msg);
134 
135  Core::ThreadSafe::Barrier serializeReadyBarrier;
136  Core::ThreadSafe::Barrier slaveExchangeDoneBarrier;
137  Core::ThreadSafe::Barrier allDoneBarrier;
138 
140  static int sig_end_;
141  static int sig_usr_;
142  static int sig_alrm_;
143 };
144 
145 } // namespace SST
146 
147 #endif // SST_CORE_SYNC_RANKSYNCPARALLELSKIP_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
Definition: syncManager.h:39
Definition: action.cc:18
Definition: rankSyncParallelSkip.h:33
bool getSignals(int &end, int &usr, int &alrm) override
Return exchanged signals after sync.
Definition: rankSyncParallelSkip.cc:157
Definition: serializable.h:24
ActivityQueue * registerLink(const RankInfo &to_rank, const RankInfo &from_rank, const std::string &name, Link *link) override
Register a Link which this Sync Object is responsible for.
Definition: rankSyncParallelSkip.cc:92
void finalizeLinkConfigurations() override
Finish link configuration.
Definition: rankSyncParallelSkip.cc:135
void prepareForComplete() override
Prepare for complete() stage.
Definition: rankSyncParallelSkip.cc:145
void setSignals(int end, int usr, int alrm) override
Set signals to exchange during sync.
Definition: rankSyncParallelSkip.cc:149
Definition: rankInfo.h:21
Definition: threadsafe.h:121
Definition: threadsafe.h:253
Definition: syncQueue.h:50
void exchangeLinkUntimedData(int thread, std::atomic< int > &msg_count) override
Cause an exchange of Untimed Data to occur.
Definition: rankSyncParallelSkip.cc:398
Base Class for a queue of Activities.
Definition: activityQueue.h:21
Definition: threadsafe.h:47
Definition: threadsafe.h:152