5#ifndef PARALLELGLOBAL_H
6#define PARALLELGLOBAL_H
8#include "../Global/SimulationContext.h"
19#include <boost/serialization/vector.hpp>
20#include <boost/serialization/string.hpp>
33namespace fs = std::filesystem;
44 std::ifstream stat(
"/proc/self/status");
46 while (std::getline(stat, line)) {
47 if (line.rfind(
"VmRSS:", 0) == 0) {
48 std::istringstream iss(line.substr(6));
54#elif defined(__APPLE__)
55 struct mach_task_basic_info info;
56 mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
57 if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
58 (task_info_t)&info, &count) == KERN_SUCCESS)
59 return static_cast<long>(info.resident_size / (1024 * 1024));
76 int max_dst = LZ4_compressBound(
size);
77 std::vector<char> out(
sizeof(int32_t) + max_dst);
79 std::memcpy(out.data(), &orig,
sizeof(int32_t));
80 int comp_sz = LZ4_compress_default(data, out.data() +
sizeof(int32_t),
size, max_dst);
81 out.resize(
sizeof(int32_t) + comp_sz);
92 std::memcpy(&orig, data,
sizeof(int32_t));
93 std::vector<char> out(orig);
94 int n = LZ4_decompress_safe(data +
sizeof(int32_t), out.data(),
size - (
int)
sizeof(int32_t), orig);
95 if (n < 0 || n != orig) {
98 std::cerr <<
"FATAL: LZ4 decompression failed (got " << n <<
", expected "
99 << orig <<
" bytes) — restart buffer is corrupt or was written "
100 <<
"with a different --compress-queue setting." << std::endl;
109 for (
auto& entry : fs::directory_iterator(
".", ec)) {
110 auto fname = entry.path().filename().string();
111 if (fname.size() > 4 && fname.substr(0, 4) ==
"fort" && fname !=
"fort.13")
112 fs::remove(entry.path(), ec);
124 template<
class Archive>
139 template<
class Archive>
151 template<
class Archive>
163 template<
class Archive>
void secini_()
Security initialization callback.
std::vector< char > lz4_compress(const char *data, int size)
LZ4-compress a buffer with a 4-byte original-size header.
void initiationforrestart_()
Initialize restart mode for next sequence.
void interfc_()
Called every RELAP5 timestep from dtstep.f. Triggers crew/diagnosis decisions.
bool should_use_memory_restart()
Decide whether to use memory mode for this restart operation. memory_limit_mb == 0 → unlimited (alway...
bool viz_outputs_any()
True if any viz output streaming is enabled.
std::string restart_path(const std::string &name)
Get restart file path (shm or local).
void setrnode_()
Set restart node information in r5pars_.
std::vector< char > lz4_decompress(const char *data, int size)
LZ4-decompress a buffer that has a 4-byte original-size header.
long get_rss_mb()
Get current process RSS in MB (Linux + macOS, returns 0 elsewhere).
void restartforanewsequence_()
Find next unexplored branch, generate indeck.i restart input.
void actonce_()
Execute crew actions once per transient.
void actte_()
Execute crew actions at each timestep.
void cleanup_fort_temps()
Clean up Fortran temporary files (fort*) left by RELAP5.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
Parallel globals namespace — MPI rank/size and message tag definitions.
bool log
Enable/disable rank-specific logging.
@ client_send_to_peer
Server -> Client A: send held data to another client.
@ server_branch_meta
Client A -> Server: branch metadata only (rank-local branch id + num_branches)
@ server_branch_this
Unused placeholder (occupies tag value 0)
@ client_run_held
Server -> Client A: run task using own held data.
@ client_peer_assign
Server -> Client A: peer assignment list for direct sends.
@ client_shutdown
Server -> Client: no more work, shut down.
@ server_done_simulating
Client -> Server: empty completion signal, client is free. The server handles it; Client....
@ server_done_with_report
Client -> Server: sequence completed with SequenceReport payload.
@ client_debug_resume
Unused (no sender or handler)
@ server_send_complete
Client -> Server: data send finished, client is free again.
@ client_simulate_this
Server -> Client: run the initial (first) sequence.
@ client_restart_run
Server -> Client: run a pending task of a resumed checkpoint with server-provided data.
@ client_peer_restart
Client A -> Client B: direct peer-to-peer restart data.
@ client_checkpoint
Server -> Client: send held_data for checkpoint gather.
@ server_output_data
Client -> Server: SequenceOutputData (before report)
int size
Total number of MPI processes.
int rank
MPI rank of this process.
Per-sequence output payload sent from client to server via MPI.
void serialize(Archive &ar, unsigned int)
std::vector< SequenceOutputEvent > events
SequenceOutputEndState end_state
Lightweight end state record (extracted from BranchEndState).
std::string consequence_description
void serialize(Archive &ar, unsigned int)
Lightweight PE event record (extracted from AnalysisInfoContainerUnit).
void serialize(Archive &ar, unsigned int)
int pe_id
associated_branch_ID → PE_N
Report sent by client when a sequence completes (for DET visualization).
double branch_time
Sim time when parent branched to create this sequence.
int parent_sequence_id
-1 for root (sequence 0)
int num_branches_generated
Children spawned during this sequence.
void serialize(Archive &ar, unsigned int)
double end_time
Sim time at completion.
int worker_rank
Which MPI rank ran it.
std::string shm_prefix
Path prefix for memory-restart files: "/dev/shm/adsidac_<pid>_" when /dev/shm exists,...
long memory_limit_mb
–memory-limit [MB]: 0 = unlimited; >0 = keep a restart buffer in memory only while process RSS is bel...
bool viz_output_end_states
Stream end states to viz server (–viz-outputs=es or all)
bool viz_output_events
Stream PE events to viz server (–viz-outputs=events or all)
bool memory_restart
In-memory restart. parseOptions() sets it to !–no-memory-restart, so it is TRUE in every run unless –...