OpenMPCD
ImplementationDetails/MPI.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Implements functionality of `OpenMPCD::MPI`.
4  */
5 
6 #ifndef OPENMPCD_IMPLEMENTATION_MPI_HPP
7 #define OPENMPCD_IMPLEMENTATION_MPI_HPP
8 
9 #include <OpenMPCD/MPI.hpp>
10 
11 #include <OpenMPCD/Exceptions.hpp>
12 
13 #include <limits>
14 
15 namespace OpenMPCD
16 {
17 
18 template<typename T>
20  T* const buffer, const std::size_t count, const std::size_t root) const
21 {
22  #ifdef OPENMPCD_DEBUG
23  if(count != 0 && buffer == NULL)
25 
26  if(root >= getNumberOfProcesses())
28  #endif
29 
30  if(count == 0)
31  return;
32 
33  const int ret =
34  MPI_Bcast(buffer, count * sizeof(T), MPI_BYTE, root, MPI_COMM_WORLD);
35  if(ret != MPI_SUCCESS)
36  OPENMPCD_THROW(Exception, "`MPI_Bcast`");
37 }
38 
39 } //namespace OpenMPCD
40 
41 #endif //OPENMPCD_IMPLEMENTATION_MPI_HPP
Exceptions.hpp
OPENMPCD_THROW
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
Definition: Exceptions.hpp:22
MPI.hpp
OpenMPCD::MPI::getNumberOfProcesses
std::size_t getNumberOfProcesses() const
Returns the total number of processes.
Definition: MPI.cpp:79
OpenMPCD::Exception
The base exception class for OpenMPCD.
Definition: Exceptions.hpp:37
OpenMPCD::OutOfBoundsException
Exception for out-of-bounds access.
Definition: Exceptions.hpp:112
OpenMPCD::MPI::broadcast
void broadcast(T *const buffer, const std::size_t count, const std::size_t root) const
Implements the MPI_BCAST functionality.
Definition: ImplementationDetails/MPI.hpp:19
OpenMPCD::NULLPointerException
NULL-pointer exception.
Definition: Exceptions.hpp:96