← Documentation
ADS-IDAC Engine 5.0.0
Server.h
Go to the documentation of this file.
1
14
15#ifndef SERVER_H
16#define SERVER_H
17#include <mpi.h>
18#include <memory>
19#include <mutex>
20#include <queue>
21#include <vector>
22#include <map>
23#include <unordered_map>
24#include <fstream>
25
26struct DETCheckpoint;
27struct PendingBranch;
28#include "ParallelUtilities.h"
29#include "ParallelGlobal.h"
30#include <filesystem>
31
33
39struct TreeState {
40 std::mutex mu;
41 std::vector<SequenceReport> completed;
42 std::map<int, SequenceOutputData> output_data;
43 int total_clients = 0;
45 int queue_depth = 0;
47 long memory_mb = 0;
48 double start_time = 0.0;
49};
50
51namespace fs = std::filesystem;
52
53using PU = ParallelUtilities;
54
62class Server {
63public:
68 explicit Server(int rank, int viz_port = 0);
70
75 void Shutdown();
76
89 void Simulation();
90
106 void merge_outputs();
107
111
117
122
131
134 int find_free_client_except(int exclude_rank);
135
145 void write_checkpoint();
146
156
157private:
158 bool checkpoint_pending_ = false;
161 int num_queue{0};
162 int rank;
166 std::map<int, int> resume_source_refs_;
168
170 struct RestartTask {
176 };
177
178 std::queue<RestartTask> tasks_queue;
179 std::unique_ptr<int[]> clients_busy;
180 MPI_Status status_server{};
181
182 // Occupancy trace (--occupancy-log, default off). Wall-clock speedup cannot
183 // distinguish a slow scheduler from an empty queue; this records which one
184 // it is. CSV columns: elapsed_s, queue_depth, busy_workers, total_workers,
185 // sequences_completed. The file is truncated at start and a row is written
186 // on change rather than on a timer: queue depth and busy count are step
187 // functions that only move at events, so change-logging is lossless and a
188 // periodic sample would just alias it. If the file cannot be opened the
189 // run continues without it (a warning is logged).
190 std::ofstream occupancy_log_;
191 double occupancy_t0_ = 0.0;
192 int last_queue_ = -1;
193 int last_busy_ = -1;
194
195 // Visualization state
196 std::shared_ptr<TreeState> viz_state_;
197 std::unique_ptr<VisualizationServer> viz_server_;
198 int viz_port_ = 0;
199 std::unordered_map<int, int> rank_current_sequence_;
200
201 // Resume state: the loaded checkpoint and its tasks not yet dispatched
202 std::unique_ptr<DETCheckpoint> resume_ckpt_;
203 std::vector<PendingBranch> resume_pending_;
204
215};
216
217#endif //SERVER_H
ParallelUtilities PU
Definition: Client.h:35
Shared declarations for MPI parallel execution: message tags, utilities, Fortran callbacks.
Static MPI utility functions — colored logging, Boost object serialization over MPI.
MPI server that manages the DET task queue and client dispatch.
Definition: Server.h:62
void merge_outputs()
Merge per-rank Output/ directories into the shared project Output/.
Definition: Server.cpp:460
bool dispatch_one_resume_task()
Dispatch the last task of resume_pending_ to a free client.
Definition: Server.cpp:1106
std::shared_ptr< TreeState > viz_state_
Definition: Server.h:196
std::unordered_map< int, int > rank_current_sequence_
rank -> sequence_id being run
Definition: Server.h:199
int next_candidate
Round-robin pointer (starts at rank 1)
Definition: Server.h:167
bool stoppedAtCheckpoint() const
True when the run ended at a checkpoint (–checkpoint-stop, the interrupt menu's checkpoint option,...
Definition: Server.h:116
void Shutdown()
Send client_shutdown to every client rank and stop the visualization server. Under –merge=now each cl...
Definition: Server.cpp:77
std::queue< RestartTask > tasks_queue
Pending metadata-only restart tasks.
Definition: Server.h:178
Server(int rank, int viz_port=0)
Set up the client table and, when viz_port is nonzero, start the visualization server; also runs Sche...
Definition: Server.cpp:50
int rank
This process rank (always 0)
Definition: Server.h:162
std::unique_ptr< DETCheckpoint > resume_ckpt_
Loaded –resume checkpoint (null in a fresh run)
Definition: Server.h:202
int find_next_free_client_round_robin()
Claim the next free client, round-robin from next_candidate. The returned client is marked busy and n...
Definition: Server.cpp:376
~Server()
Defined in Server.cpp (VisualizationServer complete type required)
int sequence_counter_
Next sequence ID to assign (0 is the initial sequence)
Definition: Server.h:163
int find_free_client_except(int exclude_rank)
Claim the next free client via round-robin, skipping exclude_rank.
Definition: Server.cpp:391
void Simulation()
Main server loop: poll for messages, dispatch tasks, until the tree is complete.
Definition: Server.cpp:86
std::map< int, int > resume_source_refs_
Undispatched resume tasks per checkpoint source blob.
Definition: Server.h:166
int num_queue
Unused (the queue depth is tasks_queue.size())
Definition: Server.h:161
void dispatch_available_tasks()
Make one pass over the task queue.
Definition: Server.cpp:406
int getSequencesCompleted() const
Number of sequences completed, including those restored from a resumed checkpoint.
Definition: Server.h:110
int viz_port_
Definition: Server.h:198
int num_free_clients
Number of currently idle clients.
Definition: Server.h:160
int last_busy_
last logged busy-worker count
Definition: Server.h:193
std::ofstream occupancy_log_
Definition: Server.h:190
double occupancy_t0_
MPI_Wtime() when the log was opened [s].
Definition: Server.h:191
int last_queue_
last logged depth, to suppress no-op rows
Definition: Server.h:192
bool stopped_at_checkpoint_
Run ended at a checkpoint: outputs are intermediate.
Definition: Server.h:159
int last_checkpoint_seq_
Sequence count at the last checkpoint written from the message path (-1 = none)
Definition: Server.h:165
void write_checkpoint()
Gather held branch data from every client and write <checkpoint_dir>/checkpoint_seq_<sequences_comple...
Definition: Server.cpp:612
MPI_Status status_server
Definition: Server.h:180
int sequences_completed_
Total sequences finished so far.
Definition: Server.h:164
bool checkpoint_pending_
Checkpoint requested, waiting for clients to drain.
Definition: Server.h:158
std::vector< PendingBranch > resume_pending_
Undispatched tasks; consumed from the back, index-aligned with resume_ckpt_->task_restart_states.
Definition: Server.h:203
void dispatch_resume_tasks()
Load the –resume checkpoint and dispatch its pending tasks.
Definition: Server.cpp:1002
std::unique_ptr< int[]> clients_busy
Per-client busy flag (0=free, 1=busy)
Definition: Server.h:179
std::unique_ptr< VisualizationServer > viz_server_
Definition: Server.h:197
Lightweight HTTP server serving a D3.js DET visualization page. Runs in a background thread alongside...
Complete state of a dynamic event tree run at a sequence boundary.
Definition: DETCheckpoint.h:45
One unexplored branch recorded in a checkpoint.
Definition: DETCheckpoint.h:25
A metadata-only restart task: the data stays on the source client.
Definition: Server.h:170
int sequence_id
Assigned sequence number.
Definition: Server.h:173
int local_id
Rank-local branch-point ID, the key of the data held on the source client.
Definition: Server.h:172
int parent_sequence_id
Sequence that branched to create this task.
Definition: Server.h:175
int source_rank
Client that holds the branch data.
Definition: Server.h:171
int branch_index
Which alternative branch to run (1..N-1)
Definition: Server.h:174
Shared state between MPI server loop and visualization HTTP server.
Definition: Server.h:39
int queue_depth
Queued metadata-only tasks.
Definition: Server.h:45
std::map< int, SequenceOutputData > output_data
seq_id -> output data (PE events, end states)
Definition: Server.h:42
int sequences_completed
Mirror of Server::sequences_completed_.
Definition: Server.h:44
double start_time
MPI_Wtime() at server construction [s].
Definition: Server.h:48
std::vector< SequenceReport > completed
One report per finished sequence, in arrival order.
Definition: Server.h:41
int total_clients
Worker count (MPI size - 1)
Definition: Server.h:43
long memory_mb
Server (rank 0) RSS [MB].
Definition: Server.h:47
int num_free_clients
Idle workers.
Definition: Server.h:46
std::mutex mu
Guards all other members.
Definition: Server.h:40