Xmipp  v3.23.11-Nereus
Classes | Public Member Functions | List of all members
ProgRecFourierMpiStarPU Class Reference

#include <mpi_reconstruct_fourier_starpu.h>

Inheritance diagram for ProgRecFourierMpiStarPU:
Inheritance graph
[legend]
Collaboration diagram for ProgRecFourierMpiStarPU:
Collaboration graph
[legend]

Classes

struct  DistributedBatchProvider
 

Public Member Functions

void defineParams () override
 
void readParams () override
 
void read (int argc, char **argv, bool reportErrors=true) override
 
int tryRun () override
 
void run () override
 
 ~ProgRecFourierMpiStarPU () override
 
- Public Member Functions inherited from ProgRecFourierStarPU
 ProgRecFourierStarPU ()
 
void show () const override
 
void setIO (const FileName &fn_in, const FileName &fn_out) override
 
- Public Member Functions inherited from ProgReconsBase
virtual ~ProgReconsBase ()
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Additional Inherited Members

- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 
- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Static Protected Member Functions inherited from ProgRecFourierStarPU
static void prepareMetaData (const FileName &fn_in, MetaDataVec &SF)
 
static uint32_t computeBatchCount (const Params &params, const MetaData &SF)
 
static void prepareConstants (const Params &params, const MetaData &SF, const FileName &fn_sym, ComputeConstants &constants)
 
static void initStarPU ()
 
static ComputeStarPUResult computeStarPU (const Params &params, const MetaData &SF, const ComputeConstants &computeConstants, BatchProvider &batches, bool verbose)
 
static void shutdownStarPU ()
 
static void postProcessAndSave (const Params &params, const ComputeConstants &computeConstants, const FileName &fn_out, std::complex< float > ***tempVolume, float ***tempWeights)
 
- Protected Attributes inherited from ProgRecFourierStarPU
FileName fn_in
 
FileName fn_out
 
FileName fn_sym
 
struct ProgRecFourierStarPU::Params params
 
MetaDataVec SF
 
struct ProgRecFourierStarPU::ComputeConstants computeConstants
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

MPI extension of ProgRecFourierStarPU. MPI should already be initialized externally. (This is done by runReconstructFourierMpiStarPU function)

At least two program instances are needed - one master and at least one worker (though any real speedup is expected only with multiple workers). It is expected, but not required, that the master will run on the same machine as one of the workers, as it uses minimal processing power.

All program instances, no matter their role, should have the access to identical input files (through network storage, manual copy, etc.).

First worker (i.e. second global rank) will write out the result.

Definition at line 52 of file mpi_reconstruct_fourier_starpu.h.

Constructor & Destructor Documentation

◆ ~ProgRecFourierMpiStarPU()

ProgRecFourierMpiStarPU::~ProgRecFourierMpiStarPU ( )
override

MPI shutdown

Definition at line 439 of file mpi_reconstruct_fourier_starpu.cpp.

439  {
440  if (mpiInitialized) {
441  LOG_MPI("Finalizing MPI");
442  CHECK_MPI(MPI_Finalize());
443  }
444 }
#define CHECK_MPI(operationWithReturnCode)
#define LOG_MPI(COUT)

Member Function Documentation

◆ defineParams()

void ProgRecFourierMpiStarPU::defineParams ( )
overridevirtual

Specify supported command line arguments

Reimplemented from ProgRecFourierStarPU.

Definition at line 49 of file mpi_reconstruct_fourier_starpu.cpp.

49  {
51  addParamsLine(" [--mpiDistribute <pc=0.3>] : Ratio [0,1] describing how many batches should be initially distributed.");
52  addParamsLine(" : Use less for more heterogeneous group of computers, more for more homogeneous group.");
53  addParamsLine(" [--mpiPrefetch <batches=25>] : How many batches should be in the processing pipeline at all times.");
54  addParamsLine(" : Higher numbers could be faster with faster and/or more homogeneous computers.");
55  addParamsLine(" : Very low numbers will have severe performance implications.");
56 }
void addParamsLine(const String &line)

◆ read()

void ProgRecFourierMpiStarPU::read ( int  argc,
char **  argv,
bool  reportErrors = true 
)
overridevirtual

Read with MPI Initialization

Reimplemented from XmippProgram.

Definition at line 409 of file mpi_reconstruct_fourier_starpu.cpp.

409  {
410  // Not using XmippMpiProgram, because it is unnecessarily complicated for this use-case
411  // and does not initialize MPI with thread support, which is required
412  LOG_MPI("Initializing MPI");
413  int providedThreadSupport;
414  CHECK_MPI(MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &providedThreadSupport));
415  mpiInitialized = true;
416  LOG_MPI("MPI initialized with thread level " << providedThreadSupport);
417 
418  if (providedThreadSupport < MPI_THREAD_SERIALIZED) {
419  std::cerr << "MPI implementation does not support MPI_THREAD_SERIALIZED concurrency level, which is required. Provided level is " << providedThreadSupport << '\n';
420  REPORT_ERROR(ERR_NOT_IMPLEMENTED, "Could not initialize MPI");
421  }
422 
423  XmippProgram::read(argc, argv, reportErrors);
424 }
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
virtual void read(int argc, const char **argv, bool reportErrors=true)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
int argc
Original command line arguments.
Definition: xmipp_program.h:86
#define CHECK_MPI(operationWithReturnCode)
const char ** argv
Definition: xmipp_program.h:87
#define LOG_MPI(COUT)

◆ readParams()

void ProgRecFourierMpiStarPU::readParams ( )
overridevirtual

Read arguments from command line

Reimplemented from ProgRecFourierStarPU.

Definition at line 58 of file mpi_reconstruct_fourier_starpu.cpp.

58  {
60 
61  percentOfJobsDistributedByDefault = static_cast<float>(getDoubleParam("--mpiDistribute"));
62  preferredBatchesInPipeline = static_cast<uint32_t>(getIntParam("--mpiPrefetch"));
63 }
double getDoubleParam(const char *param, int arg=0)
int getIntParam(const char *param, int arg=0)

◆ run()

void ProgRecFourierMpiStarPU::run ( )
overridevirtual

Run the image processing. Method will load data, process them and store result to final destination.

Reimplemented from ProgRecFourierStarPU.

Definition at line 65 of file mpi_reconstruct_fourier_starpu.cpp.

65  {
66  int rank, size;
67  CHECK_MPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
68  CHECK_MPI(MPI_Comm_size(MPI_COMM_WORLD, &size));
69 
70  {// Implementation of tip 6 from https://www.open-mpi.org/faq/?category=debugging
71  // Set this env variable to the rank which is to be debugged
72  char* rankStr = getenv("XMIPP_MPI_DEBUG_RANK");
73  int rankToBlock = rankStr == nullptr ? -1 : atoi(rankStr);
74 
75  if (rankToBlock == rank) {
76  volatile /* so it isn't optimized out */ int i = 0;
77  char hostname[256];
78  gethostname(hostname, sizeof(hostname));
79  printf("PID %d on %s ready for attach\n", getpid(), hostname);
80  fflush(stdout);
81 
82  // After attaching with debugger, set i to arbitrary non-zero value to continue
83  // gdb> set var i = 7
84  while (0 == i)
85  sleep(1);
86  }
87  }
88 
89  if (size < 2) {
90  if (rank == 0) {
91  REPORT_ERROR(ERR_ARG_DEPENDENCE, "This MPI implementation needs at least two instances");
92  } else {
93  // no need to report error from all nodes at the same time
94  return;
95  }
96  }
97 
98  MPI_Comm workComm;
99  // Rest of the code in this file assumes, that world rank 0 is master and other ranks are simply shifted by 1 to form workComm.
100  // This code does that, but any modification must take this requirement into account.
101  CHECK_MPI(MPI_Comm_split(MPI_COMM_WORLD, rank == 0 ? MPI_UNDEFINED : 0, 0, &workComm));
102 
103  const int workerCount = size - 1;
104 
105  if (workComm == MPI_COMM_NULL) {
106  runMaster(workerCount);
107  } else {
108  int workerRank;
109  CHECK_MPI(MPI_Comm_rank(workComm, &workerRank));
110  runWorker(workComm, workerCount, workerRank);
111  }
112 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Error with some arguments dependencies.
Definition: xmipp_error.h:115
#define i
#define CHECK_MPI(operationWithReturnCode)

◆ tryRun()

int ProgRecFourierMpiStarPU::tryRun ( )
overridevirtual

try with MPI abort

Reimplemented from XmippProgram.

Definition at line 426 of file mpi_reconstruct_fourier_starpu.cpp.

426  {
427  // Based on XmippMpiProgram::tryRun()
428  try {
429  if (doRun)
430  this->run();
431  } catch (XmippError &xe) {
432  std::cerr << xe;
433  errorCode = xe.__errno;
434  MPI_Abort(MPI_COMM_WORLD, xe.__errno);
435  }
436  return errorCode;
437 }

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