14#include "arcane/utils/ApplicationInfo.h"
15#include "arcane/utils/NullThreadMng.h"
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/ValueConvert.h"
19#include "arcane/utils/NotImplementedException.h"
20#include "arcane/utils/ArgumentException.h"
21#include "arcane/utils/FatalErrorException.h"
22#include "arcane/utils/CommandLineArguments.h"
24#include "arcane/parallel/IStat.h"
26#include "arccore/message_passing_mpi/internal/MpiAdapter.h"
27#include "arcane/parallel/mpi/MpiParallelMng.h"
28#include "arcane/parallel/mpi/MpiParallelDispatch.h"
29#include "arcane/parallel/mpi/MpiErrorHandler.h"
31#include "arcane/core/FactoryService.h"
32#include "arcane/core/IApplication.h"
33#include "arcane/core/ParallelSuperMngDispatcher.h"
35#include "arcane/impl/SequentialParallelSuperMng.h"
49class MpiParallelSuperMng
50:
public ParallelSuperMngDispatcher
55 ~MpiParallelSuperMng()
override;
58 void build()
override;
98 static void _ErrorHandler(MPI_Comm*,
int*, ...);
106: m_application(sbi.application())
107, m_thread_mng(nullptr)
109, m_is_parallel(false)
112, m_nb_local_sub_domain(1)
113, m_mpi_main_communicator(MPI_COMM_NULL)
114, m_main_communicator(MPI_COMM_NULL)
115, m_machine_communicator(MPI_COMM_NULL)
117, m_datatype_list(nullptr)
127~MpiParallelSuperMng()
132 delete m_datatype_list;
138 catch (
const Exception& ex) {
143 m_error_handler.removeHandler();
164void MpiParallelSuperMng::
168 char*** argv =
nullptr;
170 Request::setNullRequest(
Request(0,
nullptr, MPI_REQUEST_NULL));
171 Communicator::setNullCommunicator(
Communicator(MPI_COMM_NULL));
174 argc = app_args.commandLineArgc();
175 argv = app_args.commandLineArgv();
179 int thread_wanted = MPI_THREAD_SERIALIZED;
180 int thread_provided = 0;
183#ifndef ARCANE_USE_MPC
185 MPI_Query_thread(&thread_provided);
187 thread_provided = MPI_THREAD_MULTIPLE;
190 if (thread_provided < thread_wanted) {
193 MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
195 app->
traceMng()->
info() <<
"WARNING: MPI thread level provided!=wanted ("
196 << thread_provided <<
"!=" << thread_wanted <<
")";
203void MpiParallelSuperMng::
204_ErrorHandler(MPI_Comm* comm,
int* error_code, ...)
208 char error_buf[MPI_MAX_ERROR_STRING + 1];
212 MPI_Error_string(e, error_buf, &error_len);
213 error_buf[error_len] =
'\0';
214 error_buf[MPI_MAX_ERROR_STRING] =
'\0';
218 ARCANE_FATAL(
"Error in MPI call code={0} msg={1}", *error_code, error_buf);
240 MPI_Comm mpi_machine_communicator = MPI_COMM_NULL;
241 MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &mpi_machine_communicator);
245#ifndef ARCANE_USE_MPC
250 tm->
info() <<
"MPI has non blocking collective";
251 tm->
info() <<
"MPI: sizeof(MPI_Count)=" <<
sizeof(MPI_Count);
253 tm->
info() <<
"MPI: init_time (seconds)=" << (end_time - start_time);
259 auto astat = m_stat->toArccoreStat();
262 auto c = createBuiltInDispatcher<Byte>(tm,
nullptr, m_adapter, m_datatype_list);
263 auto i32 = createBuiltInDispatcher<Int32>(tm,
nullptr, m_adapter, m_datatype_list);
264 auto i64 = createBuiltInDispatcher<Int64>(tm,
nullptr, m_adapter, m_datatype_list);
265 auto r = createBuiltInDispatcher<Real>(tm,
nullptr, m_adapter, m_datatype_list);
266 _setDispatchers(c, i32, i64, r);
276 tm->
debug() <<
"[MpiParallelSuperMng::internalCreateWorldParallelMng]";
280 MPI_Comm comm = MPI_COMM_NULL;
283 MPI_Comm machine_comm = MPI_COMM_NULL;
288 MPI_Comm_rank(comm, &rank);
289 MPI_Comm_size(comm, &nb_rank);
291 bool is_parallel = nb_rank > 1;
294 bi.is_parallel = is_parallel;
297 bi.timer_mng =
nullptr;
298 bi.thread_mng = m_thread_mng;
299 bi.mpi_lock =
nullptr;
301 tm->
debug() <<
"[MpiParallelSuperMng::internalCreateWorldParallelMng] pm->build()";
313 m_application->traceMng()->info() <<
"MpiParallelSuperMng: rank " <<
m_rank <<
" calling MPI_Abort";
335class MpiSequentialParallelSuperMng
336:
public SequentialParallelSuperMng
345 ~MpiSequentialParallelSuperMng()
override
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ARCANE_SERVICE_INTERFACE(ainterface)
Macro to declare an interface when registering a service.
const CommandLineArguments & commandLineArguments() const
Command line arguments.
Exception when an argument is invalid.
virtual const ApplicationInfo & applicationInfo() const =0
Executable information.
virtual ITraceMng * traceMng() const =0
Trace manager.
Interface of a thread manager.
virtual TraceMessage info()=0
Stream for an information message.
virtual TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium)=0
Stream for a debug message.
Communicator for message exchange.
void destroy()
Destroys the instance. It should no longer be used afterward.
Manages the MPI_Datatypes associated with Arcane types.
Message interface for the Type.
bool isParallel() const override
Returns true if the execution is parallel.
void initialize() override
Initializes the instance.
Int32 m_rank
MPI rank in the global communicator of this process.
Int32 m_nb_local_sub_domain
Number of local sub-domains.
Int32 commSize() const override
Returns the total number of processes used.
Integer nbLocalSubDomain() override
Number of subdomains to create locally.
IThreadMng * threadMng() const override
Thread manager.
Int32 commRank() const override
Returns the process number (between 0 and nbProcess()-1).
MP::Communicator m_machine_communicator
MPI Machine Communicator.
Integer masterIORank() const override
Rank of the instance managing input/output (for which isMasterIO() is true).
void barrier() override
Parallelism manager for all allocated resources.
MP::Communicator m_main_communicator
MPI Communicator.
MPI_Comm m_mpi_main_communicator
MPI Communicator.
Ref< IParallelMng > internalCreateWorldParallelMng(Int32 local_rank) override
Creates a parallelism manager for all allocated cores.
Int32 traceRank() const override
Rank of this instance for traces.
bool isMasterIO() const override
Returns true if the instance is a master I/O manager.
IApplication * application() const override
Returns the main manager.
Int32 m_nb_rank
Number of MPI processes in the global communicator.
void tryAbort() override
Attempts to abort.
bool m_is_parallel
Statistics.
void build() override
Constructs the instance members.
void * getMPICommunicator() override
Address of the MPI communicator associated with this manager.
Parallel::Communicator communicator() const override
MPI communicator associated with this manager.
IApplication * m_application
Main manager.
void build() override
Build-level construction of the service.
Thread manager in single-threaded mode.
Statistics on parallelism.
Reference to an instance.
void build() override
Build-level construction of the service.
IApplication * application() const override
Returns the main manager.
Structure containing the information to create a service.
#define ARCANE_REGISTER_SERVICE(aclass, a_service_property,...)
Macro for registering a service.
IStat * createDefaultStat()
Creates a default instance.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Ref< TrueType > createRef(Args &&... args)
Creates an instance of type TrueType with arguments Args and returns a reference to it.
ARCANE_MPI_EXPORT void arcaneInitializeMPI(int *argc, char ***argv, int wanted_thread_level)
ARCANE_MPI_EXPORT bool arcaneIsAcceleratorAwareMPI()
Indicates if the current MPI runtime supports accelerators.
Int32 Integer
Type representing an integer.
@ ST_Application
The service is used at the application level.
double Real
Type representing a real number.
ARCANE_MPI_EXPORT void arcaneFinalizeMPI()
std::int32_t Int32
Signed integer type of 32 bits.
Info to construct an MpiParallelMng.