|
ADS-IDAC Engine 5.0.0
|
MPI server that manages the DET task queue and client dispatch. More...
#include <Server.h>
Classes | |
| struct | RestartTask |
| A metadata-only restart task: the data stays on the source client. More... | |
Public Member Functions | |
| Server (int rank, int viz_port=0) | |
Set up the client table and, when viz_port is nonzero, start the visualization server; also runs Scheduler::initiationForSimulation(). More... | |
| ~Server () | |
| Defined in Server.cpp (VisualizationServer complete type required) More... | |
| void | Shutdown () |
| Send client_shutdown to every client rank and stop the visualization server. Under –merge=now each client runs its self-merge in its shutdown handler and then waits in the MPI barrier that merge_outputs() enters, so merge_outputs() must follow. More... | |
| void | Simulation () |
| Main server loop: poll for messages, dispatch tasks, until the tree is complete. More... | |
| void | merge_outputs () |
| Merge per-rank Output/ directories into the shared project Output/. More... | |
| int | getSequencesCompleted () const |
| Number of sequences completed, including those restored from a resumed checkpoint. More... | |
| bool | stoppedAtCheckpoint () const |
| True when the run ended at a checkpoint (–checkpoint-stop, the interrupt menu's checkpoint option, or its exit option after an interval checkpoint was written). The outputs are then intermediate: –merge=defer must not skip the inline merge, and PE nodes keep their natural IDs. More... | |
| int | find_next_free_client_round_robin () |
| Claim the next free client, round-robin from next_candidate. The returned client is marked busy and num_free_clients is decremented. More... | |
| void | dispatch_available_tasks () |
| Make one pass over the task queue. More... | |
| int | find_free_client_except (int exclude_rank) |
Claim the next free client via round-robin, skipping exclude_rank. More... | |
| void | write_checkpoint () |
Gather held branch data from every client and write <checkpoint_dir>/checkpoint_seq_<sequences_completed>.dat. More... | |
| void | dispatch_resume_tasks () |
| Load the –resume checkpoint and dispatch its pending tasks. More... | |
Private Member Functions | |
| bool | dispatch_one_resume_task () |
| Dispatch the last task of resume_pending_ to a free client. More... | |
Private Attributes | |
| bool | checkpoint_pending_ = false |
| Checkpoint requested, waiting for clients to drain. More... | |
| bool | stopped_at_checkpoint_ = false |
| Run ended at a checkpoint: outputs are intermediate. More... | |
| int | num_free_clients |
| Number of currently idle clients. More... | |
| int | num_queue {0} |
| Unused (the queue depth is tasks_queue.size()) More... | |
| int | rank |
| This process rank (always 0) More... | |
| int | sequence_counter_ = 1 |
| Next sequence ID to assign (0 is the initial sequence) More... | |
| int | sequences_completed_ = 0 |
| Total sequences finished so far. More... | |
| int | last_checkpoint_seq_ = -1 |
| Sequence count at the last checkpoint written from the message path (-1 = none) More... | |
| std::map< int, int > | resume_source_refs_ |
| Undispatched resume tasks per checkpoint source blob. More... | |
| int | next_candidate = 1 |
| Round-robin pointer (starts at rank 1) More... | |
| std::queue< RestartTask > | tasks_queue |
| Pending metadata-only restart tasks. More... | |
| std::unique_ptr< int[]> | clients_busy |
| Per-client busy flag (0=free, 1=busy) More... | |
| MPI_Status | status_server {} |
| std::ofstream | occupancy_log_ |
| double | occupancy_t0_ = 0.0 |
| MPI_Wtime() when the log was opened [s]. More... | |
| int | last_queue_ = -1 |
| last logged depth, to suppress no-op rows More... | |
| int | last_busy_ = -1 |
| last logged busy-worker count More... | |
| std::shared_ptr< TreeState > | viz_state_ |
| std::unique_ptr< VisualizationServer > | viz_server_ |
| int | viz_port_ = 0 |
| std::unordered_map< int, int > | rank_current_sequence_ |
| rank -> sequence_id being run More... | |
| std::unique_ptr< DETCheckpoint > | resume_ckpt_ |
| Loaded –resume checkpoint (null in a fresh run) More... | |
| std::vector< PendingBranch > | resume_pending_ |
| Undispatched tasks; consumed from the back, index-aligned with resume_ckpt_->task_restart_states. More... | |
MPI server that manages the DET task queue and client dispatch.
Runs on rank 0 only, single-threaded (the optional visualization HTTP server runs in its own thread and shares only TreeState). Call order used by parallelexec::parallel_init: construct, Simulation(), Shutdown(), then merge_outputs() unless the merge is deferred.
|
explicit |
Set up the client table and, when viz_port is nonzero, start the visualization server; also runs Scheduler::initiationForSimulation().
| rank | MPI rank (always 0 for server). |
| viz_port | Port for visualization HTTP server (0=disabled). |
Definition at line 50 of file Server.cpp.
References clients_busy, g_sim, Scheduler::initiationForSimulation(), PG::log, next_candidate, num_free_clients, rank, PG::size, SimulationContext::SScheduler, viz_port_, viz_server_, and viz_state_.
|
default |
Defined in Server.cpp (VisualizationServer complete type required)
| void Server::dispatch_available_tasks | ( | ) |
Make one pass over the task queue.
A task whose source client is busy goes back to the end of the queue. Otherwise the source is told to send the held data to another free client (client_send_to_peer) or, if no other client is free, to run the branch itself (client_run_held). Stops when no client is free. Logs a "[MEM]" line with the server RSS after every pass.
Definition at line 406 of file Server.cpp.
References Server::RestartTask::branch_index, PG::client_run_held, PG::client_send_to_peer, clients_busy, find_free_client_except(), get_rss_mb(), Server::RestartTask::local_id, PG::log, num_free_clients, Server::RestartTask::parent_sequence_id, rank, rank_current_sequence_, Server::RestartTask::sequence_id, Server::RestartTask::source_rank, and tasks_queue.
Referenced by Simulation().
|
private |
Dispatch the last task of resume_pending_ to a free client.
Sends the task's RestartNodeInfo (with its restart blob attached for the send only), the merged BranchRecord, the sequence id and the branch index with tag client_restart_run, and frees the source blob once its last task is dispatched. A task with no restart state is logged and dropped.
Definition at line 1106 of file Server.cpp.
References PG::client_restart_run, clients_busy, find_next_free_client_round_robin(), PG::log, num_free_clients, rank, rank_current_sequence_, resume_ckpt_, resume_pending_, resume_source_refs_, and sequence_counter_.
Referenced by dispatch_resume_tasks(), and Simulation().
| void Server::dispatch_resume_tasks | ( | ) |
Load the –resume checkpoint and dispatch its pending tasks.
Calls MPI_Abort if the configuration fingerprint differs or if the project Output/PE already holds a finalized (sequentially renamed) run. Overrides –compress-queue to the checkpoint's setting, restores the sequence counters, derives the branch-ID epoch for this run, and sends one task per free client; the rest are dispatched from Simulation() as clients free up, ahead of queued tasks.
Definition at line 1002 of file Server.cpp.
References SimConfig::compress_queue, SimulationContext::config, SimulationContext::config_fingerprint, dispatch_one_resume_task(), e, g_sim, Scheduler::getPEDirectory(), DETCheckpoint::load(), PG::log, num_free_clients, rank, resume_ckpt_, SimConfig::resume_file, resume_pending_, resume_source_refs_, sequence_counter_, sequences_completed_, SimulationContext::SScheduler, and viz_state_.
Referenced by Simulation().
| int Server::find_free_client_except | ( | int | exclude_rank | ) |
Claim the next free client via round-robin, skipping exclude_rank.
Definition at line 391 of file Server.cpp.
References clients_busy, next_candidate, num_free_clients, and PG::size.
Referenced by dispatch_available_tasks().
| int Server::find_next_free_client_round_robin | ( | ) |
Claim the next free client, round-robin from next_candidate. The returned client is marked busy and num_free_clients is decremented.
Definition at line 376 of file Server.cpp.
References clients_busy, next_candidate, num_free_clients, and PG::size.
Referenced by dispatch_one_resume_task(), and Simulation().
|
inline |
Number of sequences completed, including those restored from a resumed checkpoint.
Definition at line 110 of file Server.h.
References sequences_completed_.
| void Server::merge_outputs | ( | ) |
Merge per-rank Output/ directories into the shared project Output/.
Reads "../rank_N/Output/" relative to the rank_0 working directory. –merge=now (default): enters an MPI barrier with the clients, which have renamed their ES/KPS files into place and staged logs as parts/<name>.rank_N; the server renames the remaining per-file PE nodes in ascending rank order (highest rank wins a name collision), concatenates the parts in rank order and deletes them. –merge=serial: the server copies every file itself. –merge=defer reaches this function only after a checkpoint stop; the server then renames and concatenates everything itself, with no barrier. In every mode it rebuilds ES_summary.txt and, unless the run stopped at a checkpoint, renumbers the PE nodes sequentially. Logs "Merged N sequences, M PE nodes into
<dir> in X s (rename|serial copy)". A file that can be neither renamed nor copied is logged and skipped.
Definition at line 460 of file Server.cpp.
References adsidac::pe::aggregate_basename(), SimConfig::aggregate_pe_output, adsidac::merge::build_es_summary(), adsidac::pe::collect(), SimulationContext::config, e, adsidac::pe::finalize_sequential(), g_sim, Scheduler::getESDirectory(), Scheduler::getKPSDirectory(), Scheduler::getOutputDirectory(), Scheduler::getPEDirectory(), PG::log, SimConfig::merge_mode, rank, adsidac::pe::rewrite_sequential(), PG::size, SimulationContext::SScheduler, and stopped_at_checkpoint_.
| void Server::Shutdown | ( | ) |
Send client_shutdown to every client rank and stop the visualization server. Under –merge=now each client runs its self-merge in its shutdown handler and then waits in the MPI barrier that merge_outputs() enters, so merge_outputs() must follow.
Definition at line 77 of file Server.cpp.
References PG::client_shutdown, PG::log, PG::size, and viz_server_.
| void Server::Simulation | ( | ) |
Main server loop: poll for messages, dispatch tasks, until the tree is complete.
Initializes the plant, control panel, procedures and crew modules (the server deserializes crew snapshots), installs the SIGUSR1 (checkpoint request) and SIGINT (interrupt menu) handlers, opens the occupancy log if –occupancy-log is set, then either resumes (–resume) or sends client_simulate_this for sequence 0. Polls with MPI_Iprobe and a 1 ms sleep. Returns when the queue and the resume list are empty, every client is free and no checkpoint is pending; after a checkpoint written under –checkpoint-stop; or when the user picks "exit" in the interrupt menu. A checkpoint is written only once every client is idle, so it waits for the longest running sequence.
Definition at line 86 of file Server.cpp.
References SimulationContext::Action_Taker, SimulationContext::All_procedure, SimConfig::checkpoint_dir, SimConfig::checkpoint_interval, checkpoint_pending_, SimConfig::checkpoint_stop, PG::client_peer_assign, PG::client_simulate_this, clients_busy, SimulationContext::config, SimulationContext::Decision_Maker, Operator::diagnosis_matrix, dispatch_available_tasks(), dispatch_one_resume_task(), dispatch_resume_tasks(), find_next_free_client_round_robin(), g_sim, get_rss_mb(), Scheduler::getProjectDirectory(), SimulationContext::Indicator, Operator::initiationForSimulation(), ConvertToString::initiationForSimulation(), Procedures::initiationForSimulation(), SystemModule::initiationForSimulation(), Operator::knowledge_base, last_busy_, last_checkpoint_seq_, last_queue_, PG::log, mpi_checkpoint_requested, mpi_sigint_handler(), mpi_sigint_received, mpi_sigusr1_handler(), num_free_clients, sim::Operator::OAT, SimConfig::occupancy_log, occupancy_log_, occupancy_t0_, sim::Operator::ODM, SimulationContext::Plant, rank, rank_current_sequence_, ControlPanel::readInfoFromFile(), SimConfig::resume_file, resume_pending_, sequence_counter_, SequenceOutputData::sequence_id, sequences_completed_, PG::server_branch_meta, PG::server_done_simulating, PG::server_done_with_report, PG::server_output_data, PG::server_send_complete, adsidac::set_shared_control_panel(), adsidac::set_shared_diagnosis_matrix(), adsidac::set_shared_kb(), adsidac::set_shared_procedures(), show_mpi_interrupt_menu(), PG::size, Server::RestartTask::source_rank, SimulationContext::SScheduler, status_server, stopped_at_checkpoint_, tasks_queue, SimulationContext::Translator, viz_state_, and write_checkpoint().
|
inline |
True when the run ended at a checkpoint (–checkpoint-stop, the interrupt menu's checkpoint option, or its exit option after an interval checkpoint was written). The outputs are then intermediate: –merge=defer must not skip the inline merge, and PE nodes keep their natural IDs.
Definition at line 116 of file Server.h.
References stopped_at_checkpoint_.
| void Server::write_checkpoint | ( | ) |
Gather held branch data from every client and write <checkpoint_dir>/checkpoint_seq_<sequences_completed>.dat.
The caller must ensure every client is idle (each one answers the client_checkpoint request from its message loop). Merges the gathered BranchRecords into one record keyed by cluster identity, carries over tasks of a resumed checkpoint that are still undispatched, and prints "Resume with: --resume=<path>" on stdout. Write failures are reported by DETCheckpoint::save() on stderr and do not stop the run.
Definition at line 612 of file Server.cpp.
References BranchCluster::all_branch, DETCheckpoint::branch_center_blob, BranchRecord::branch_cluster, PendingBranch::branch_index, DETCheckpoint::branch_record_blobs, SimConfig::checkpoint_dir, PendingBranch::cid, DETCheckpoint::cid_source, PG::client_checkpoint, DETCheckpoint::completed_reports, DETCheckpoint::compress_queue, SimConfig::compress_queue, SimulationContext::config, DETCheckpoint::config_fingerprint, SimulationContext::config_fingerprint, g_sim, BranchRecord::getIDOfRecentGeneratedES(), PG::log, DETCheckpoint::max_branch_id, PendingBranch::parent_sequence_id, DETCheckpoint::pending_tasks, rank, DETCheckpoint::restart_states, resume_ckpt_, resume_pending_, DETCheckpoint::save(), DETCheckpoint::sequence_counter, sequence_counter_, PendingBranch::sequence_id, DETCheckpoint::sequences_completed, sequences_completed_, BranchRecord::setIDOfRecentGeneratedBranch(), BranchRecord::setIDOfRecentGeneratedBranchCluster(), BranchRecord::setIDOfRecentGeneratedES(), PG::size, DETCheckpoint::source_blobs, DETCheckpoint::task_restart_states, tasks_queue, and viz_state_.
Referenced by Simulation().
|
private |
Checkpoint requested, waiting for clients to drain.
Definition at line 158 of file Server.h.
Referenced by Simulation().
|
private |
Per-client busy flag (0=free, 1=busy)
Definition at line 179 of file Server.h.
Referenced by dispatch_available_tasks(), dispatch_one_resume_task(), find_free_client_except(), find_next_free_client_round_robin(), Server(), and Simulation().
|
private |
|
private |
Sequence count at the last checkpoint written from the message path (-1 = none)
Definition at line 165 of file Server.h.
Referenced by Simulation().
|
private |
last logged depth, to suppress no-op rows
Definition at line 192 of file Server.h.
Referenced by Simulation().
|
private |
Round-robin pointer (starts at rank 1)
Definition at line 167 of file Server.h.
Referenced by find_free_client_except(), find_next_free_client_round_robin(), and Server().
|
private |
Number of currently idle clients.
Definition at line 160 of file Server.h.
Referenced by dispatch_available_tasks(), dispatch_one_resume_task(), dispatch_resume_tasks(), find_free_client_except(), find_next_free_client_round_robin(), Server(), and Simulation().
|
private |
Unused (the queue depth is tasks_queue.size())
|
private |
Definition at line 190 of file Server.h.
Referenced by Simulation().
|
private |
MPI_Wtime() when the log was opened [s].
Definition at line 191 of file Server.h.
Referenced by Simulation().
|
private |
This process rank (always 0)
Definition at line 162 of file Server.h.
Referenced by dispatch_available_tasks(), dispatch_one_resume_task(), dispatch_resume_tasks(), merge_outputs(), Server(), Simulation(), and write_checkpoint().
|
private |
rank -> sequence_id being run
Definition at line 199 of file Server.h.
Referenced by dispatch_available_tasks(), dispatch_one_resume_task(), and Simulation().
|
private |
Loaded –resume checkpoint (null in a fresh run)
Definition at line 202 of file Server.h.
Referenced by dispatch_one_resume_task(), dispatch_resume_tasks(), and write_checkpoint().
|
private |
Undispatched tasks; consumed from the back, index-aligned with resume_ckpt_->task_restart_states.
Definition at line 203 of file Server.h.
Referenced by dispatch_one_resume_task(), dispatch_resume_tasks(), Simulation(), and write_checkpoint().
|
private |
Undispatched resume tasks per checkpoint source blob.
Definition at line 166 of file Server.h.
Referenced by dispatch_one_resume_task(), and dispatch_resume_tasks().
|
private |
Next sequence ID to assign (0 is the initial sequence)
Definition at line 163 of file Server.h.
Referenced by dispatch_one_resume_task(), dispatch_resume_tasks(), Simulation(), and write_checkpoint().
|
private |
Total sequences finished so far.
Definition at line 164 of file Server.h.
Referenced by dispatch_resume_tasks(), getSequencesCompleted(), Simulation(), and write_checkpoint().
|
private |
Definition at line 180 of file Server.h.
Referenced by Simulation().
|
private |
Run ended at a checkpoint: outputs are intermediate.
Definition at line 159 of file Server.h.
Referenced by merge_outputs(), Simulation(), and stoppedAtCheckpoint().
|
private |
Pending metadata-only restart tasks.
Definition at line 178 of file Server.h.
Referenced by dispatch_available_tasks(), Simulation(), and write_checkpoint().
|
private |
Definition at line 197 of file Server.h.
Referenced by Server(), and Shutdown().
|
private |
Definition at line 196 of file Server.h.
Referenced by dispatch_resume_tasks(), Server(), Simulation(), and write_checkpoint().