|
ADS-IDAC Engine 5.0.0
|
MPI worker client that executes simulation sequences. More...
#include <Client.h>
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... | |
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.
|
explicit |
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.
| rank | MPI rank of this client process. |
Definition at line 202 of file Client.cpp.
References SimulationContext::Action_Taker, SimulationContext::All_procedure, SimulationContext::Branch_center, SimulationContext::config, SimulationContext::Decision_Maker, Operator::diagnosis_matrix, g_sim, SimulationContext::Indicator, BranchRecord::initiationForSimulation(), Operator::initiationForSimulation(), ConvertToString::initiationForSimulation(), Procedures::initiationForSimulation(), SystemModule::initiationForSimulation(), Scheduler::initiationForSimulation(), Operator::knowledge_base, local_branch_counter_, sim::Operator::OAT, sim::Operator::ODM, SimulationContext::Plant, rank, ControlPanel::readInfoFromFile(), adsidac::set_shared_control_panel(), adsidac::set_shared_diagnosis_matrix(), adsidac::set_shared_kb(), adsidac::set_shared_procedures(), Scheduler::setESDirectory(), Scheduler::setKPSDirectory(), Scheduler::setOutputDirectory(), Scheduler::setPEDirectory(), solver_, SimConfig::solver_url, SimulationContext::SScheduler, and SimulationContext::Translator.
| 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.
| seq_id | Global 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().
|
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().
| 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().
|
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().
| 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.
| cid | Key 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. |
| rinfo | Snapshot to hold (shared, not copied). |
| br | Branch record; deep-copied via copyBranchRecord. |
| path | Restart transfer file path for this branch point. |
| refs | Number 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().
| 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_.
| branch_index | Index 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().
|
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().
| 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.
| file_path | Path to restart file (used if buffer is empty). |
| clear_buf | If 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().
|
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().
| 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.
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.
|
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().
|
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().
| 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().
| 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().
|
private |
|
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().
|
private |
|
private |
Per-client branch-point counter (see getNextLocalBranchID)
Definition at line 128 of file Client.h.
Referenced by Client(), and getNextLocalBranchID().
| 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().
|
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().
|
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().
|
private |
Per-rank solver instance.
Definition at line 129 of file Client.h.
Referenced by Client(), complete_sequence(), execute_relap(), restore_buffer(), and Work().
| MPI_Status Client::status_client {} |