Commit dc431542 authored by COULAUD Olivier's avatar COULAUD Olivier
Browse files

Add mechanism to duplicate the communicator

parent 77becf8c
#ifndef SCALFMM_UTILS_PARALLEL_MANAGER_HPP
#define SCALFMM_UTILS_PARALLEL_MANAGER_HPP
#include <iostream>
#include "scalfmm/config/scalfmm-config.hpp"
#ifdef SCALFMM_USE_MPI
#include <inria/algorithm/distributed/mpi.hpp>
......@@ -72,9 +75,9 @@ class parallel_manager
///
/// \param in_communicator MPI communicator
///
parallel_manager(const int num_threads, MPI_Comm in_communicator)
parallel_manager(const int num_threads, MPI_Comm in_communicator, bool duplicated=false)
: m_number_threads(num_threads) {
this->init(in_communicator);
this->init(in_communicator, duplicated);
#ifdef _OPENMP
omp_set_num_threads(num_threads);
#endif
......@@ -99,7 +102,7 @@ class parallel_manager
///
/// \param in_communicator MPI communicator
///
void init( MPI_Comm in_communicator)
void init( MPI_Comm in_communicator, bool duplicated=false)
{
int provided;
int error = MPI_Query_thread(&provided);
......@@ -110,7 +113,7 @@ class parallel_manager
MPI_Finalize();
std::exit(EXIT_FAILURE);
}
m_communicator = inria::mpi::communicator(in_communicator);
m_communicator = inria::mpi::communicator(in_communicator, duplicated);
m_number_processes = m_communicator.size();
m_process_id = m_communicator.rank();
}
......@@ -142,6 +145,8 @@ class parallel_manager
void end()
{
std::clog << " para::end" << std::endl;
#ifdef SCALFMM_USE_MPI
m_communicator.barrier();
......
......@@ -214,9 +214,13 @@ namespace inria
communicator& operator=(const communicator&) = default;
communicator& operator=(communicator&&) = default;
communicator(MPI_Comm comm)
: raw_comm(comm)
communicator(MPI_Comm comm, bool duplicated=false)
{
if (duplicated) {
MPI_Comm_dup(comm, &raw_comm);
} else {
raw_comm = comm;
}
}
operator MPI_Comm() const { return raw_comm; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment