Pakman
PakmanMPIWorker Class Reference

#include <PakmanMPIWorker.hpp>

Public Member Functions

 PakmanMPIWorker (std::function< int(int argc, char **argv, const std::string &input_string, std::string &output_string)> simulator)
 
 ~PakmanMPIWorker ()=default
 
int run (int argc, char *argv[])
 

Static Public Attributes

static constexpr int PAKMAN_EXIT_SUCCESS = 0
 
static constexpr int PAKMAN_EXIT_FAILURE = 1
 

Detailed Description

A class for implementing Pakman MPI Workers.

Since MPI simulators cannot be forked directly when using MPIMaster, the MPI function MPI_Comm_spawn is used instead to spawn MPI Workers. As a consequence, the communication between Pakman and MPI Workers does not happen through system pipes, but through the MPI intercommunicator obtained with MPI_Comm_get_parent.

Most importantly, the MPI simulator can no longer be considered a black box at the systems-level. Instead, the simulator must be implemented as a function or function object in C++ (see pakman_mpi_worker.h for C), and passed to the constructor of this class. The run() method will then communicate with Pakman and execute the simulator function to perform the received simulation tasks.

Note that MPI_Init() should be called before calling run(). Also, after run() returns, MPI_Finalize() should be called.

For more information, see Implementing an MPI simulator.

Definition at line 31 of file PakmanMPIWorker.hpp.

Constructor & Destructor Documentation

◆ PakmanMPIWorker()

PakmanMPIWorker::PakmanMPIWorker ( std::function< int(int argc, char **argv, const std::string &input_string, std::string &output_string)>  simulator)

Constructor from simulator function.

The simulator function must accept four arguments;

  • argc number of command-line arguments.
  • argv array of command-line arguments.
  • input_string input to simulator.
  • output_string output from simulator.

In addition, the simulator function must return an error code.

Parameters
simulatorsimulator function

Definition at line 104 of file PakmanMPIWorker.hpp.

◆ ~PakmanMPIWorker()

PakmanMPIWorker::~PakmanMPIWorker ( )
default

Default destructor does nothing.

Member Function Documentation

◆ run()

int PakmanMPIWorker::run ( int  argc,
char *  argv[] 
)

Run the Pakman MPI Worker with the given simulator function.

Parameters
argcnumber of command-line arguments.
argvarray of command-line arguments.
Returns
exit code.

Definition at line 111 of file PakmanMPIWorker.hpp.

Member Data Documentation

◆ PAKMAN_EXIT_FAILURE

constexpr int PakmanMPIWorker::PAKMAN_EXIT_FAILURE = 1
static

Exit code indicating Worker encountered an error.

Definition at line 67 of file PakmanMPIWorker.hpp.

◆ PAKMAN_EXIT_SUCCESS

constexpr int PakmanMPIWorker::PAKMAN_EXIT_SUCCESS = 0
static

Exit code indicating Worker ran successfully.

Definition at line 64 of file PakmanMPIWorker.hpp.


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