Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
MpiNode Class Reference

#include <xmipp_mpi.h>

Public Member Functions

 MpiNode (int &argc, char **&argv)
 
 ~MpiNode ()
 
 MpiNode (const MpiNode &)=delete
 
MpiNodeoperator= (const MpiNode &)=delete
 
bool isMaster () const
 
void barrierWait ()
 
template<typename T >
void gatherMetadatas (T &MD, const FileName &rootName)
 

Public Attributes

size_t rank
 
size_t size
 
size_t active
 

Protected Member Functions

size_t getActiveNodes ()
 

Detailed Description

Class to wrapp some MPI common calls in an work node.

Definition at line 47 of file xmipp_mpi.h.

Constructor & Destructor Documentation

◆ MpiNode() [1/2]

MpiNode::MpiNode ( int &  argc,
char **&  argv 
)

Definition at line 144 of file xmipp_mpi.cpp.

145 {
146  MPI_Init(&argc, &argv);
147  int irank, isize;
148  MPI_Comm_rank(MPI_COMM_WORLD, &irank);
149  MPI_Comm_size(MPI_COMM_WORLD, &isize);
150  rank=irank;
151  size=isize;
152  //comm = new MPI_Comm;
153  //MPI_Comm_dup(MPI_COMM_WORLD, comm);
154  active = 1;
155  //activeNodes = size;
156 }
size_t size
Definition: xmipp_mpi.h:52
size_t active
Definition: xmipp_mpi.h:52
size_t rank
Definition: xmipp_mpi.h:52

◆ ~MpiNode()

MpiNode::~MpiNode ( )

Definition at line 158 of file xmipp_mpi.cpp.

159 {
160  //active = 0;
161  //updateComm();
162  //std::cerr << "Send Finalize to: " << rank << std::endl;
163  MPI_Finalize();
164 }

◆ MpiNode() [2/2]

MpiNode::MpiNode ( const MpiNode )
delete

Member Function Documentation

◆ barrierWait()

void MpiNode::barrierWait ( )

Wait on a barrier for the other MPI nodes

Definition at line 171 of file xmipp_mpi.cpp.

172 {
173  MPI_Barrier(MPI_COMM_WORLD);
174 }

◆ gatherMetadatas()

template<typename T >
template void MpiNode::gatherMetadatas< MetaDataDb > ( T &  MD,
const FileName rootName 
)

Gather metadatas

Wait for all workers write results

Definition at line 200 of file xmipp_mpi.cpp.

201 {
202  if (size == 1)
203  return;
204 
205  FileName fn;
206 
207  if (!isMaster()) //workers just write down partial results
208  {
209  fn = formatString("%s_node%d.xmd", rootname.c_str(), rank);
210  MD.write(fn);
211  }
213  barrierWait();
214  if (isMaster()) //master should collect and join workers results
215  {
216  MetaDataDb mdAll(MD), mdSlave;
217  for (size_t nodeRank = 1; nodeRank < size; nodeRank++)
218  {
219  fn = formatString("%s_node%d.xmd", rootname.c_str(), nodeRank);
220  mdSlave.read(fn);
221  //make sure file is not empty
222  if (!mdSlave.isEmpty())
223  mdAll.unionAll(mdSlave);
224  //Remove blockname
225  fn = fn.removeBlockName();
226  remove(fn.c_str());
227  }
228  //remove first metadata
229  fn = formatString("%s_node%d.xmd", rootname.c_str(), 1);
230  fn = fn.removeBlockName();
231  remove(fn.c_str());
232  MD = T(mdAll);
233  }
234 }
size_t size
Definition: xmipp_mpi.h:52
void barrierWait()
Definition: xmipp_mpi.cpp:171
virtual bool isEmpty() const
size_t rank
Definition: xmipp_mpi.h:52
FileName removeBlockName() const
String formatString(const char *format,...)
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override
bool isMaster() const
Definition: xmipp_mpi.cpp:166

◆ getActiveNodes()

size_t MpiNode::getActiveNodes ( )
protected

Update the MPI communicator to connect the currently active nodes Calculate the number of still active nodes

◆ isMaster()

bool MpiNode::isMaster ( ) const

Check if the node is master

Definition at line 166 of file xmipp_mpi.cpp.

167 {
168  return rank == 0;
169 }
size_t rank
Definition: xmipp_mpi.h:52

◆ operator=()

MpiNode& MpiNode::operator= ( const MpiNode )
delete

Member Data Documentation

◆ active

size_t MpiNode::active

Definition at line 52 of file xmipp_mpi.h.

◆ rank

size_t MpiNode::rank

Definition at line 52 of file xmipp_mpi.h.

◆ size

size_t MpiNode::size

Definition at line 52 of file xmipp_mpi.h.


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