From 071cbecfc456f48eae76a9e5d0ace2708b31b33c Mon Sep 17 00:00:00 2001 From: Thomas Purcell <purcell@fhi-berlin.mpg.de> Date: Sat, 9 May 2020 11:00:28 +0200 Subject: [PATCH] Add MPI intraface class Start parallelzationo --- src/mpi_interface/MPI_Interface.cpp | 14 ++++++++++ src/mpi_interface/MPI_Interface.hpp | 41 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/mpi_interface/MPI_Interface.cpp create mode 100644 src/mpi_interface/MPI_Interface.hpp diff --git a/src/mpi_interface/MPI_Interface.cpp b/src/mpi_interface/MPI_Interface.cpp new file mode 100644 index 00000000..d8741ab1 --- /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 00000000..7654105f --- /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 -- GitLab