diff --git a/src/mpi_interface/MPI_Interface.cpp b/src/mpi_interface/MPI_Interface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d8741ab1aab1ae66aeaf43c41642132d324bcbeb --- /dev/null +++ b/src/mpi_interface/MPI_Interface.cpp @@ -0,0 +1,14 @@ +MPI_Interface::MPI_Interface() : boost::mpi::communicator() +{} + +std::array<int, 2> MPI_Interface::get_start_end_from_list(int size, int start) +{ + int els_per_rank = size / size(); + int remaineder = size % size(); + + std::array<int, 2> start_end; + start_end[0] = start + els_per_rank * rank() + std::min(rank(), remaineder); + start_end[1] = start + els_per_rank * (rank() + 1) + std::min(rank() + 1, remaineder); + + return start_end; +} diff --git a/src/mpi_interface/MPI_Interface.hpp b/src/mpi_interface/MPI_Interface.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7654105fb5460082fc2735cf772311c43d563d46 --- /dev/null +++ b/src/mpi_interface/MPI_Interface.hpp @@ -0,0 +1,41 @@ +#ifndef SISSO_MPI_INTERFACE +#define SISSO_MPI_INTERFACE + +#include <boost/mpi.hpp> +#include <array> + +extern boost::mpi::environment env; +namespace mpi = boost::mpi; + +// Augment the boost mpi communicator class with some other useful data +/** + * @brief Augment the boost MPI communicator class with some other useful data + * @details MPI communicator used to transfer data throughout the cell. + * + */ +class MPI_Interface : public boost::mpi::communicator +{ +public: + /** + * @brief Constructor for the MPI_Interface + */ + MPI_Interface(); + + std::array<int, 2> get_start_end_from_list(int size, int start); + + /** + * @brief Unique int tag generator + * + * @param[in] procSend sending process + * @param[in] procRecv receiving process + * @param[in] maxOffest number of different communication processes possible between two processes within the same operation + * @param[in] offest the assigned offset corresponding to a single communication within the same operation + * + * @return A unique tag to send information between two processes + */ + int cantorTagGen(unsigned int procSend, unsigned int procRecv, unsigned int maxOffest, unsigned int offest) { return (int((procSend + procRecv) * (procSend + procSend +1) / 2) + procRecv) * maxOffest + offest; } + + +}; + +#endif \ No newline at end of file