Pakman
MPIWorkerHandler Class Reference

#include <MPIWorkerHandler.h>

Inheritance diagram for MPIWorkerHandler:
Collaboration diagram for MPIWorkerHandler:

Public Member Functions

 MPIWorkerHandler (const Command &simulator, const std::string &input_string)
 
virtual ~MPIWorkerHandler () override
 
virtual bool isDone () override
 
- Public Member Functions inherited from AbstractWorkerHandler
 AbstractWorkerHandler (const Command &simulator, const std::string &input_string)
 
virtual ~AbstractWorkerHandler ()=default
 
std::string getOutput ()
 
int getErrorCode ()
 

Static Public Member Functions

static void terminateStatic ()
 

Additional Inherited Members

- Protected Attributes inherited from AbstractWorkerHandler
const Command m_simulator
 
const std::string m_input_string
 
std::string m_output_buffer
 
int m_error_code = -1
 

Detailed Description

A class for representing MPI Workers.

MPI Workers are spawned using the MPI function MPI_Comm_spawn. This is necessary when the simulator is built using MPI internally because then it could clash with the Pakman when using the MPIMaster.

As opposed to the ForkedWorkerHandler, the MPI child process is not terminated after each simulation. Rather, the MPI Worker stays alive to accept more simulation tasks. Each simulation task is represented by a new instance of MPIWorkerHandler. Only when terminateStatic() is called will the MPI Worker process be terminated.

Definition at line 23 of file MPIWorkerHandler.h.

Constructor & Destructor Documentation

◆ MPIWorkerHandler()

MPIWorkerHandler::MPIWorkerHandler ( const Command simulator,
const std::string &  input_string 
)

Construct from simulator string and input string.

If MPIWorkerHandler has not been constructed before, the constructor will spawn an MPI process that communicates with MPIWorkerHandler via the intercommunicator created by MPI_Comm_spawn. This MPI child process will continue to run after this object is destroyed.

If MPIWorkerHandler has been constructed before, the MPIWorkerHandler will communicate with the already existing MPI child process.

In both cases, the input string is then sent to the MPI Worker via standard MPI functions on the intercommunicator.

Parameters
simulatorcommand to run simulation.
input_stringinput string to simulator.

Definition at line 15 of file MPIWorkerHandler.cc.

◆ ~MPIWorkerHandler()

MPIWorkerHandler::~MPIWorkerHandler ( )
overridevirtual

Destructor.

The destructor waits for the MPI Worker to finish its simulation task and send its output string and error code if it has not yet done so.

We assume that the MPI child process does not exit after sending its results, but rather stays alive to accept further simulation tasks.

Definition at line 28 of file MPIWorkerHandler.cc.

Member Function Documentation

◆ isDone()

bool MPIWorkerHandler::isDone ( )
overridevirtual
Returns
whether Worker has finished.

Probe intercommunicator for message and receive message if it is ready.

Implements AbstractWorkerHandler.

Definition at line 34 of file MPIWorkerHandler.cc.

◆ terminateStatic()

void MPIWorkerHandler::terminateStatic ( )
static

Terminate Workers remaining after their Managers have terminated.

Since the Managers can only call terminate() on busy Workers, any remaining idle Workers need to be explicitly terminated, else they stall the termination of the entire program.

Definition at line 85 of file MPIWorkerHandler.cc.


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