← Documentation
ADS-IDAC Engine 5.0.0
Client Class Reference

MPI worker client that executes simulation sequences. More...

#include <Client.h>

Collaboration diagram for Client:
[legend]

Classes

struct  HeldBranchData
 Data held locally for deferred peer-to-peer transfer. More...
 

Public Member Functions

 Client (int rank)
 Create the solver, initialize the engine modules and redirect the scheduler's output directories to <cwd>/Output/ (the working directory is already rank_N/). Procedures are initialized before the crew. More...
 
int Work ()
 Main client work loop: receive tasks, execute, report back. More...
 
void parallel_restartforanewsequence_ (int branch_index)
 Install the received branch tree as the global one and prepare the restart of one branch alternative. More...
 
void execute_relap ()
 Run one sequence on this client's solver: sets the thermo cache mode from the configuration, enables the in-memory restart buffer and calls solver_->runSequence(). Blocks until the sequence ends. More...
 
int getNextLocalBranchID ()
 Increment and return the rank-local branch-point counter. The value names restart transfer files and is the local id the server uses to refer to data held on this client. More...
 
void hold_branch_data (int cid, std::shared_ptr< RestartNodeInfo > rinfo, BranchRecord &br, const std::string &path, int refs)
 Store branch data for deferred peer transfer or a later self-run. More...
 
void restore_relap_state (const std::string &file_path, bool clear_buf)
 Restore the solver state from restart_info_'s buffer or a restart file. More...
 
void complete_sequence (int seq_id)
 Post-sequence completion: write the sequence's ES, KPS, analysis and PE node files, send SequenceOutputData when –viz-outputs is set, then send the SequenceReport (server_done_with_report) that marks this client free. More...
 

Public Attributes

int parent_seq_id_ = -1
 Parent sequence ID for current run (received from server) More...
 
double branch_time_ = 0.0
 Sim time when parent branched to create this sequence. More...
 
int branches_this_seq_ = 0
 Count of branching events during current sequence. More...
 
MPI_Status status_client {}
 Status of the message being handled by Work() More...
 

Private Member Functions

bool ensure_base_cache ()
 Load <project>/restart_base.bin if not already resident; false if unavailable. More...
 
void restore_buffer (std::vector< char > raw)
 Splice the base on if raw lacks it (MPI_Abort if impossible), then solver_->restore() More...
 
void self_merge_outputs ()
 

Private Attributes

int rank
 MPI rank of this client. More...
 
int local_branch_counter_
 Per-client branch-point counter (see getNextLocalBranchID) More...
 
std::unique_ptr< ThermalHydraulicSolver > solver_
 Per-rank solver instance. More...
 
AdsidacCallback callback_
 Per-rank callback instance. More...
 
std::shared_ptr< RestartNodeInfo > restart_info_
 Snapshot of the task being started (immutable after creation) More...
 
std::shared_ptr< BranchRecord > branch_center_
 Branch record of the task being started (consumed by parallel_restartforanewsequence_) More...
 
KeyParameterHistory KPS
 Unused; sequences record into g_sim.KPS. More...
 
std::unordered_map< int, HeldBranchData > held_data_
 Rank-local branch-point id -> data held for deferred peer sends and self-runs. More...
 
std::vector< char > base_cache_
 [header][complete restart base], cached once per rank. More...
 

Detailed Description

MPI worker client that executes simulation sequences.

One instance per client process, single-threaded. parallelexec stores a pointer to it in the global g_client so AdsidacCallback can reach it.

Definition at line 42 of file Client.h.

Constructor & Destructor Documentation

◆ Client()

Member Function Documentation

◆ complete_sequence()

void Client::complete_sequence ( int  seq_id)

Post-sequence completion: write the sequence's ES, KPS, analysis and PE node files, send SequenceOutputData when –viz-outputs is set, then send the SequenceReport (server_done_with_report) that marks this client free.

Parameters
seq_idGlobal sequence ID assigned by the server.

Definition at line 184 of file Client.cpp.

References branch_time_, branches_this_seq_, extract_sequence_outputs(), PG::log, log_seq_fingerprint_mpi(), parent_seq_id_, rank, save_sequence_outputs(), SequenceReport::sequence_id, PG::server_done_with_report, PG::server_output_data, solver_, and viz_outputs_any().

Referenced by Work().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensure_base_cache()

bool Client::ensure_base_cache ( )
private

Load <project>/restart_base.bin if not already resident; false if unavailable.

Definition at line 120 of file Client.cpp.

References base_cache_, read_file_verified(), and restart_base_path().

Referenced by restore_buffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute_relap()

void Client::execute_relap ( )

Run one sequence on this client's solver: sets the thermo cache mode from the configuration, enables the in-memory restart buffer and calls solver_->runSequence(). Blocks until the sequence ends.

Definition at line 675 of file Client.cpp.

References callback_, SimulationContext::config, g_sim, solver_, and SimConfig::thermo_cache_mode.

Referenced by Work().

Here is the caller graph for this function:

◆ getNextLocalBranchID()

int Client::getNextLocalBranchID ( )
inline

Increment and return the rank-local branch-point counter. The value names restart transfer files and is the local id the server uses to refer to data held on this client.

Definition at line 81 of file Client.h.

References local_branch_counter_.

Referenced by AdsidacCallback::onBranchingPoint().

Here is the caller graph for this function:

◆ hold_branch_data()

void Client::hold_branch_data ( int  cid,
std::shared_ptr< RestartNodeInfo >  rinfo,
BranchRecord &  br,
const std::string &  path,
int  refs 
)

Store branch data for deferred peer transfer or a later self-run.

Parameters
cidKey of the entry. The caller passes the rank-local id from getNextLocalBranchID(), which the server sends back in client_send_to_peer and client_run_held.
rinfoSnapshot to hold (shared, not copied).
brBranch record; deep-copied via copyBranchRecord.
pathRestart transfer file path for this branch point.
refsNumber of queued tasks that will consume the entry; it is erased when the count reaches zero.

Definition at line 684 of file Client.cpp.

References held_data_, PG::log, and rank.

Referenced by AdsidacCallback::onBranchingPoint().

Here is the caller graph for this function:

◆ parallel_restartforanewsequence_()

void Client::parallel_restartforanewsequence_ ( int  branch_index)

Install the received branch tree as the global one and prepare the restart of one branch alternative.

Writes indeck.i in the working directory (card 103 = the target cluster's restart count), moves the clusters of branch_center_ into g_sim.Branch_center, raises the branch-ID counter to at least g_sim.id_epoch_base + rank * 100000, marks every cluster other than the target as fully explored, shares restart_info_ into g_sim.restart_info, sets g_sim.fresh_restart and clears the key parameter history and the analysis records. restart_info_ and branch_center_ must be set; the target cluster must exist in branch_center_.

Parameters
branch_indexIndex of the alternative within its cluster (1..N-1; index 0 is the branch the donor continues itself).

Definition at line 602 of file Client.cpp.

References SimulationContext::Aux_info, SimulationContext::Branch_center, branch_center_, BranchRecord::branch_cluster, AnalysisInfoContainer::clearAnalysisInfoContainerForRestart(), KeyParameterHistory::clearKeyParameterHistory(), BranchRecord::findBrnachCluster(), SimulationContext::fresh_restart, g_sim, BranchRecord::getIDOfRecentGeneratedBranch(), BranchCluster::getNCountForRestartRELAP5(), SimulationContext::id_epoch_base, SimulationContext::KPS, PG::log, rank, SimulationContext::restart_info, restart_info_, BranchCluster::setCurrentBranchNum(), BranchRecord::setIDOfMotherBranch(), BranchRecord::setIDOfMotherCluster(), BranchRecord::setIDOfRecentGeneratedBranch(), BranchRecord::setIDOfRecentGeneratedBranchCluster(), BranchRecord::setIDOfRecentGeneratedES(), and BranchRecord::setRecentUnconditionalBranchProbability().

Referenced by Work().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore_buffer()

void Client::restore_buffer ( std::vector< char >  raw)
private

Splice the base on if raw lacks it (MPI_Abort if impossible), then solver_->restore()

Definition at line 130 of file Client.cpp.

References base_cache_, ensure_base_cache(), adsidac::extract_header_and_base(), adsidac::has_complete_restart(), rank, restart_base_path(), solver_, and adsidac::splice_base().

Referenced by restore_relap_state().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore_relap_state()

void Client::restore_relap_state ( const std::string &  file_path,
bool  clear_buf 
)

Restore the solver state from restart_info_'s buffer or a restart file.

The buffer is used when it is non-empty, otherwise file_path is read. The data is LZ4-decompressed first when –compress-queue is on, and a transfer without the restart base gets the cached base spliced on. Calls MPI_Abort if the file cannot be read or no base is available.

Parameters
file_pathPath to restart file (used if buffer is empty).
clear_bufIf true, clear the restart buffer after restore to free memory.

Definition at line 155 of file Client.cpp.

References SimConfig::compress_queue, SimulationContext::config, g_sim, lz4_decompress(), read_file_verified(), restart_info_, and restore_buffer().

Referenced by Work().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ self_merge_outputs()

void Client::self_merge_outputs ( )
private

Worker self-merge (–merge=now): rename own ES/KPS files into the shared Output/ and stage the append-file sources (PE aggregate compacted first) and "err messages.txt" as parts/<name>.rank_N. Per-file PE nodes are left in place for rank 0.

Definition at line 540 of file Client.cpp.

References adsidac::pe::aggregate_basename(), adsidac::pe::compact_aggregate(), g_sim, Scheduler::getProjectDirectory(), adsidac::merge::move_file(), rank, and SimulationContext::SScheduler.

Referenced by Work().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Work()

int Client::Work ( )

Main client work loop: receive tasks, execute, report back.

Ignores SIGINT and SIGUSR1 (rank 0 handles both). Polls with MPI_Iprobe and a 1 ms sleep. Calls MPI_Abort when asked to forward held data it does not hold, or when restart data cannot be read.

Returns
0 after client_shutdown has been handled.

Definition at line 249 of file Client.cpp.

References branch_center_, branch_time_, branches_this_seq_, cleanup_fort_temps(), PG::client_checkpoint, PG::client_peer_restart, PG::client_restart_run, PG::client_run_held, PG::client_send_to_peer, PG::client_shutdown, PG::client_simulate_this, complete_sequence(), SimulationContext::config, SimulationContext::current_seq_events, execute_relap(), g_sim, Time::getTimeAtWhichThisEventHappen(), held_data_, SimulationContext::id_epoch_base, PG::log, SimConfig::merge_mode, parallel_restartforanewsequence_(), parent_seq_id_, rank, read_file_verified(), restart_info_, restore_relap_state(), self_merge_outputs(), SimulationContext::seq_restart_branch_num, SimulationContext::seq_restart_cid, SequenceReport::sequence_id, PG::server_done_with_report, PG::server_send_complete, solver_, and status_client.

Here is the call graph for this function:

Member Data Documentation

◆ base_cache_

std::vector<char> Client::base_cache_
private

[header][complete restart base], cached once per rank.

The base is byte-identical across lineages, so it is a run-wide constant. With ADS_RESTART_TRIM=1, transfers omit it and the receiver splices this back on. RELAP aborts in fabend if the first restart record it sees is not a complete one (rrestf.f), so the splice is required.

Definition at line 142 of file Client.h.

Referenced by ensure_base_cache(), and restore_buffer().

◆ branch_center_

std::shared_ptr<BranchRecord> Client::branch_center_
private

Branch record of the task being started (consumed by parallel_restartforanewsequence_)

Definition at line 132 of file Client.h.

Referenced by parallel_restartforanewsequence_(), and Work().

◆ branch_time_

double Client::branch_time_ = 0.0

Sim time when parent branched to create this sequence.

Definition at line 84 of file Client.h.

Referenced by complete_sequence(), and Work().

◆ branches_this_seq_

int Client::branches_this_seq_ = 0

Count of branching events during current sequence.

Definition at line 85 of file Client.h.

Referenced by complete_sequence(), AdsidacCallback::onBranchingPoint(), and Work().

◆ callback_

AdsidacCallback Client::callback_
private

Per-rank callback instance.

Definition at line 130 of file Client.h.

Referenced by execute_relap().

◆ held_data_

std::unordered_map<int, HeldBranchData> Client::held_data_
private

Rank-local branch-point id -> data held for deferred peer sends and self-runs.

Definition at line 134 of file Client.h.

Referenced by hold_branch_data(), and Work().

◆ KPS

KeyParameterHistory Client::KPS
private

Unused; sequences record into g_sim.KPS.

Definition at line 133 of file Client.h.

◆ local_branch_counter_

int Client::local_branch_counter_
private

Per-client branch-point counter (see getNextLocalBranchID)

Definition at line 128 of file Client.h.

Referenced by Client(), and getNextLocalBranchID().

◆ parent_seq_id_

int Client::parent_seq_id_ = -1

Parent sequence ID for current run (received from server)

Definition at line 83 of file Client.h.

Referenced by complete_sequence(), and Work().

◆ rank

int Client::rank
private

MPI rank of this client.

Definition at line 127 of file Client.h.

Referenced by Client(), complete_sequence(), hold_branch_data(), parallel_restartforanewsequence_(), restore_buffer(), self_merge_outputs(), and Work().

◆ restart_info_

std::shared_ptr<RestartNodeInfo> Client::restart_info_
private

Snapshot of the task being started (immutable after creation)

Definition at line 131 of file Client.h.

Referenced by parallel_restartforanewsequence_(), restore_relap_state(), and Work().

◆ solver_

std::unique_ptr<ThermalHydraulicSolver> Client::solver_
private

Per-rank solver instance.

Definition at line 129 of file Client.h.

Referenced by Client(), complete_sequence(), execute_relap(), restore_buffer(), and Work().

◆ status_client

MPI_Status Client::status_client {}

Status of the message being handled by Work()

Definition at line 87 of file Client.h.

Referenced by Work().


The documentation for this class was generated from the following files: