14#include "arcane/parallel/thread/SharedMemoryParallelSuperMng.h"
16#include "arcane/utils/ApplicationInfo.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/NotImplementedException.h"
19#include "arcane/utils/FatalErrorException.h"
20#include "arcane/utils/ArgumentException.h"
21#include "arcane/utils/ValueConvert.h"
22#include "arcane/utils/IThreadMng.h"
23#include "arcane/utils/TraceClassConfig.h"
24#include "arcane/utils/ITraceMng.h"
25#include "arcane/utils/IThreadImplementation.h"
26#include "arcane/utils/Mutex.h"
28#include "arcane/parallel/IStat.h"
30#include "arcane/parallel/thread/SharedMemoryParallelMng.h"
31#include "arcane/parallel/thread/SharedMemoryParallelDispatch.h"
32#include "arcane/parallel/thread/SharedMemoryMessageQueue.h"
33#include "arcane/parallel/thread/internal/SharedMemoryThreadMng.h"
34#include "arcane/parallel/thread/internal/SharedMemoryMachineShMemWinBaseInternalCreator.h"
36#include "arcane/core/FactoryService.h"
37#include "arcane/core/IApplication.h"
38#include "arcane/core/ParallelSuperMngDispatcher.h"
39#include "arcane/core/ApplicationBuildInfo.h"
40#include "arcane/core/AbstractService.h"
41#include "arcane/core/ServiceBuilder.h"
43#include "arcane/core/IMainFactory.h"
57class SharedMemoryParallelMngContainer
63 MP::Communicator mpi_comm,
65 ~SharedMemoryParallelMngContainer()
override;
75 Int32 m_nb_local_rank;
78 Mutex* m_internal_create_mutex =
nullptr;
86 MP::Communicator m_communicator;
92SharedMemoryParallelMngContainer::
94 MP::Communicator mpi_comm,
97, m_nb_local_rank(nb_local_rank)
99, m_sub_factory_builder(factory)
100, m_communicator(mpi_comm)
107SharedMemoryParallelMngContainer::
108~SharedMemoryParallelMngContainer()
110 if (m_thread_barrier)
112 delete m_message_queue;
114 delete m_all_dispatchers;
115 delete m_internal_create_mutex;
116 delete m_window_creator;
122void SharedMemoryParallelMngContainer::
125 m_message_queue =
new SharedMemoryMessageQueue();
126 m_message_queue->init(m_nb_local_rank);
129 m_thread_barrier->
init(m_nb_local_rank);
131 m_all_dispatchers =
new SharedMemoryAllDispatcher();
132 m_all_dispatchers->resize(m_nb_local_rank);
134 m_internal_create_mutex =
new Mutex();
136 m_window_creator =
new SharedMemoryMachineShMemWinBaseInternalCreator(m_nb_local_rank, m_thread_barrier);
145 if (local_rank < 0 || local_rank >= m_nb_local_rank)
147 local_rank, m_nb_local_rank);
154 build_info.rank = local_rank;
155 build_info.nb_rank = m_nb_local_rank;
156 build_info.trace_mng = tm;
157 build_info.thread_mng = m_thread_mng;
159 build_info.world_parallel_mng =
nullptr;
160 build_info.message_queue = m_message_queue;
161 build_info.thread_barrier = m_thread_barrier;
162 build_info.all_dispatchers = m_all_dispatchers;
163 build_info.sub_builder_factory = m_sub_factory_builder;
165 build_info.window_creator = m_window_creator;
169 build_info.communicator = m_communicator;
180class SharedMemoryParallelMngContainerFactory
195 ARCANE_UNUSED(machine_comm);
216SharedMemoryParallelSuperMng::
225SharedMemoryParallelSuperMng::
226SharedMemoryParallelSuperMng(
const ServiceBuildInfo& sbi, MP::Communicator comm,
228: m_application(sbi.application())
230, m_is_parallel(false)
231, m_communicator(comm)
234 m_has_mpi_init = has_mpi_init;
240SharedMemoryParallelSuperMng::
241~SharedMemoryParallelSuperMng()
261 ARCANE_FATAL(
"Can not create SharedMemoryParallelSuperMng because threads are disabled");
265 if (!m_has_mpi_init) {
266 Request::setNullRequest(Request(0,
nullptr, 0));
273 ARCANE_FATAL(
"Number of shared memory sub-domains is not defined");
276 app_tm->
info() <<
"SharedMemoryParallelSuperMng: nb_local_sub_domain=" << n;
279 String service_name =
"SharedMemoryParallelMngContainerFactory";
294 if (local_rank < 0 || local_rank >= max_rank)
296 local_rank, max_rank);
300 if (local_rank == 0) {
305 tm =
m_application->createAndInitializeTraceMng(app_tm, String::fromNumber(local_rank));
328 ARCANE_UNUSED(send_buf);
329 ARCANE_UNUSED(process_id);
338 ARCANE_UNUSED(send_buf);
339 ARCANE_UNUSED(process_id);
348 ARCANE_UNUSED(send_buf);
349 ARCANE_UNUSED(process_id);
358 ARCANE_UNUSED(send_buf);
359 ARCANE_UNUSED(process_id);
368 return m_container->m_thread_mng;
377 return m_container->m_nb_local_rank;
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#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.
AbstractService(const ServiceBuildInfo &)
Constructor from a ServiceBuildInfo.
Exception when an argument is invalid.
Interface for an 'IParallelMng' container factory.
Interface of the parallelism manager for a subdomain.
virtual void build()=0
Constructs the instance.
Abstract class of the parallelism supervisor.
virtual Ref< IParallelMng > internalCreateWorldParallelMng(Int32 local_rank)=0
Creates a parallelism manager for all allocated cores.
Interface of a barrier between threads.
virtual void destroy()=0
Destroys the barrier.
virtual void init(Integer nb_thread)=0
Initializes the barrier for nb_thread.
Interface of a thread manager.
virtual TraceMessage info()=0
Stream for an information message.
Communicator for message exchange.
Interface of a message queue with threads.
Container for shared memory message manager information.
Ref< IParallelMng > _createParallelMng(Int32 local_rank, ITraceMng *tm) override
Creates the IParallelMng for the local rank local_rank.
IApplication * m_application
Main manager.
Thread-based parallelism manager.
Parallelism supervisor using threads.
Ref< IParallelMng > internalCreateWorldParallelMng(Int32 local_rank) override
Creates a parallelism manager for all allocated cores.
void build() override
Constructs the instance members.
bool m_is_parallel
Statistics.
void broadcast(ByteArrayView send_buf, Int32 rank) override
Sends an array of values to all processes This operation synchronizes the value array send_buf across...
IApplication * m_application
Main manager.
void * getMPICommunicator() override
Address of the MPI communicator associated with this manager.
Parallel::Communicator communicator() const override
MPI communicator associated with this manager.
Int32 nbLocalSubDomain() override
Number of subdomains to create locally.
IThreadMng * threadMng() const override
Thread manager.
void tryAbort() override
Attempts to abort.
void initialize() override
Initializes the instance.
InstanceType * get() const
Associated instance or nullptr if none.
Reference to an instance.
IApplication * application() const
Access to the associated IApplication.
Structure containing the information to create a service.
Utility class for instantiating a service of a given interface.
Ref< InterfaceType > createReference(const String &name, eServiceBuilderProperties properties=SB_None)
Creates an instance implementing the InterfaceType interface.
Service creation properties.
Unicode character string.
#define ARCANE_REGISTER_SERVICE(aclass, a_service_property,...)
Macro for registering a service.
Declarations of types and methods used by message exchange mechanisms.
IStat * createDefaultStat()
Creates a default instance.
ArrayView< Int64 > Int64ArrayView
C equivalent of a 1D array of 64-bit integers.
bool arcaneHasThread()
True if arcane is compiled with thread support AND they are active.
ArrayView< Byte > ByteArrayView
C equivalent of a 1D array of characters.
@ ST_Application
The service is used at the application level.
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
ArrayView< Real > RealArrayView
C equivalent of a 1D array of reals.
std::int32_t Int32
Signed integer type of 32 bits.
Info to construct a SharedMemoryParallelMng.