Commit faecab4e authored by Shashank Saxena's avatar Shashank Saxena Committed by Gerhard Bräunlich
Browse files

Add runtime exception to qcmesh::mpi::all_scatter

parent 52db7c61
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -20,10 +20,19 @@
#include <boost/mpi/nonblocking.hpp>
#include <boost/mpi/request.hpp>
#include <boost/mpi/status.hpp>
#include <stdexcept>
#include <vector>

namespace qcmesh::mpi {

/**
 * @brief Exception class thrown when an input vector has less than `mpi_size`
 * items.
 */
struct MpiSizeException : std::runtime_error {
  using std::runtime_error::runtime_error;
};

/**
 * @brief Similar to boost::mpi::scatter, but scatters from / to all processes.
 *
@@ -42,8 +51,13 @@ void all_scatter(const std::vector<T> &in_values, std::vector<T> &out_values) {
  auto mpi_requests = std::vector<boost::mpi::request>{};
  mpi_requests.reserve(n_requests);

  if (in_values.size() < mpi_size)
    throw MpiSizeException{
        "in_values does not have size equal to the number of procs"};

  if (out_values.size() < mpi_size)
    out_values.resize(mpi_size);
    throw MpiSizeException{
        "out_values does not have size equal to the number of procs"};

  constexpr int TAG = 0;
  for (std::size_t i_proc = 0; i_proc < mpi_size; i_proc++)