Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
SequentialParallelMng.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* SequentialParallelMng.cc (C) 2000-2026 */
9/* */
10/* Management of parallelism in the sequential case. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/base/ReferenceCounter.h"
15
16#include "arccore/message_passing/PointToPointMessageInfo.h"
17
18#include "arcane/utils/Collection.h"
19#include "arcane/utils/ITraceMng.h"
20#include "arcane/utils/NotImplementedException.h"
21#include "arcane/utils/Real2.h"
22#include "arcane/utils/Real2x2.h"
23#include "arcane/utils/Real3.h"
24#include "arcane/utils/Real3x3.h"
25#include "arcane/utils/HPReal.h"
26#include "arcane/utils/NullThreadMng.h"
27#include "arcane/utils/ArgumentException.h"
28
29#include "arcane/core/IIOMng.h"
30#include "arcane/core/ISubDomain.h"
31#include "arcane/core/IApplication.h"
32#include "arcane/core/IParallelDispatch.h"
33#include "arcane/core/ParallelMngDispatcher.h"
34#include "arcane/core/ItemGroup.h"
35#include "arcane/core/IMesh.h"
36#include "arcane/core/IItemFamily.h"
37#include "arcane/core/MeshVariable.h"
38#include "arcane/core/Timer.h"
39#include "arcane/core/FactoryService.h"
40#include "arcane/core/AbstractService.h"
41#include "arcane/core/ISerializer.h"
42#include "arcane/core/internal/SerializeMessage.h"
43#include "arcane/core/internal/ParallelMngInternal.h"
44#include "arcane/core/internal/MachineShMemWinMemoryAllocator.h"
45
46#include "arcane/parallel/IStat.h"
47
48#include "arcane/impl/TimerMng.h"
49#include "arcane/impl/GetVariablesValuesParallelOperation.h"
50#include "arcane/impl/ParallelExchanger.h"
51#include "arcane/impl/ParallelTopology.h"
52#include "arcane/impl/ParallelReplication.h"
53#include "arcane/impl/SequentialParallelSuperMng.h"
54#include "arcane/impl/SequentialParallelMng.h"
55#include "arcane/impl/internal/ParallelMngUtilsFactoryBase.h"
56#include "arcane/impl/internal/VariableSynchronizer.h"
57
58#include "arccore/message_passing/RequestListBase.h"
59#include "arccore/message_passing/internal/SerializeMessageList.h"
60#include "arccore/message_passing/internal/IContigMachineShMemWinBaseInternal.h"
61#include "arccore/message_passing/internal/IMachineShMemWinBaseInternal.h"
62
63/*---------------------------------------------------------------------------*/
64/*---------------------------------------------------------------------------*/
65
66namespace Arcane
67{
70using namespace Arcane::MessagePassing;
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75extern "C++" IVariableSynchronizer*
76createNullVariableSynchronizer(IParallelMng* pm, const ItemGroup& group);
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
82: public RequestListBase
83{
84 public:
85
86 void _wait(Parallel::eWaitType wait_mode)
87 {
88 ARCANE_UNUSED(wait_mode);
89 }
90};
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
98template <class Type>
99class SequentialParallelDispatchT
100: public TraceAccessor
101, public IParallelDispatchT<Type>
102, public ITypeDispatcher<Type>
103{
104 public:
105
106 typedef Parallel::Request Request;
107 typedef Parallel::eReduceType eReduceType;
108
109 public:
110
111 SequentialParallelDispatchT(ITraceMng* tm)
112 : TraceAccessor(tm)
113 {}
114 void finalize() override {}
115
116 public:
117
118 void broadcast(ArrayView<Type> send_buf, Int32 rank) override
119 {
120 ARCANE_UNUSED(send_buf);
121 ARCANE_UNUSED(rank);
122 }
123 void broadcast(Span<Type> send_buf, Int32 rank) override
124 {
125 ARCANE_UNUSED(send_buf);
126 ARCANE_UNUSED(rank);
127 }
128 void allGather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf) override
129 {
130 recv_buf.copy(send_buf);
131 }
132 void allGather(Span<const Type> send_buf, Span<Type> recv_buf) override
133 {
134 recv_buf.copy(send_buf);
135 }
136 void gather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Int32 rank) override
137 {
138 ARCANE_UNUSED(rank);
139 recv_buf.copy(send_buf);
140 }
141 void gather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override
142 {
143 ARCANE_UNUSED(rank);
144 recv_buf.copy(send_buf);
145 }
146 void scatterVariable(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Int32 root) override
147 {
148 ARCANE_UNUSED(root);
149 recv_buf.copy(send_buf);
150 }
151 void scatterVariable(Span<const Type> send_buf, Span<Type> recv_buf, Int32 root) override
152 {
153 ARCANE_UNUSED(root);
154 recv_buf.copy(send_buf);
155 }
156 void allGatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf) override
157 {
158 gatherVariable(send_buf, recv_buf, 0);
159 }
160 void allGatherVariable(Span<const Type> send_buf, Array<Type>& recv_buf) override
161 {
162 gatherVariable(send_buf, recv_buf, 0);
163 }
164 void gatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf, Int32 rank) override
165 {
166 ARCANE_UNUSED(rank);
167 recv_buf.resize(send_buf.size());
168 ArrayView<Type> av(recv_buf);
169 av.copy(send_buf);
170 }
171 void gatherVariable(Span<const Type> send_buf, Array<Type>& recv_buf, Int32 rank) override
172 {
173 ARCANE_UNUSED(rank);
174 recv_buf.resize(send_buf.size());
175 Span<Type> av(recv_buf.span());
176 av.copy(send_buf);
177 }
178 void allToAll(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer count) override
179 {
180 ARCANE_UNUSED(count);
181 recv_buf.copy(send_buf);
182 }
183 void allToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override
184 {
185 ARCANE_UNUSED(count);
186 recv_buf.copy(send_buf);
187 }
188 void allToAllVariable(ConstArrayView<Type> send_buf,
189 Int32ConstArrayView send_count,
190 Int32ConstArrayView send_index,
191 ArrayView<Type> recv_buf,
192 Int32ConstArrayView recv_count,
193 Int32ConstArrayView recv_index) override
194 {
195 ARCANE_UNUSED(send_count);
196 ARCANE_UNUSED(recv_count);
197 ARCANE_UNUSED(send_index);
198 ARCANE_UNUSED(recv_index);
199 recv_buf.copy(send_buf);
200 }
201 void allToAllVariable(Span<const Type> send_buf,
202 ConstArrayView<Int32> send_count,
203 ConstArrayView<Int32> send_index,
204 Span<Type> recv_buf,
205 ConstArrayView<Int32> recv_count,
206 ConstArrayView<Int32> recv_index) override
207 {
208 ARCANE_UNUSED(send_count);
209 ARCANE_UNUSED(recv_count);
210 ARCANE_UNUSED(send_index);
211 ARCANE_UNUSED(recv_index);
212 recv_buf.copy(send_buf);
213 }
214 Request send(ConstArrayView<Type> send_buffer, Int32 rank, bool is_blocked) override
215 {
216 return send(Span<const Type>(send_buffer), rank, is_blocked);
217 }
218 Request send(Span<const Type> send_buffer, Int32 rank, bool is_blocked) override
219 {
220 ARCANE_UNUSED(send_buffer);
221 ARCANE_UNUSED(rank);
222 if (is_blocked)
223 throw NotSupportedException(A_FUNCINFO, "blocking send is not allowed in sequential");
224 return Request();
225 }
226 Request send(Span<const Type> send_buffer, const PointToPointMessageInfo& message) override
227 {
228 ARCANE_UNUSED(send_buffer);
229 if (message.isBlocking())
230 throw NotSupportedException(A_FUNCINFO, "blocking send is not allowed in sequential");
231 return Request();
232 }
233 Request recv(ArrayView<Type> recv_buffer, Int32 rank, bool is_blocked) override
234 {
235 return receive(Span<Type>(recv_buffer), rank, is_blocked);
236 }
237 void send(ConstArrayView<Type> send_buffer, Int32 rank) override
238 {
239 ARCANE_UNUSED(send_buffer);
240 ARCANE_UNUSED(rank);
241 throw NotSupportedException(A_FUNCINFO, "send is not allowed in sequential");
242 }
243 void recv(ArrayView<Type> recv_buffer, Int32 rank) override
244 {
245 ARCANE_UNUSED(recv_buffer);
246 ARCANE_UNUSED(rank);
247 throw NotSupportedException(A_FUNCINFO, "recv is not allowed in sequential");
248 }
249 Request receive(Span<Type> recv_buffer, Int32 rank, bool is_blocked) override
250 {
251 ARCANE_UNUSED(recv_buffer);
252 ARCANE_UNUSED(rank);
253 if (is_blocked)
254 throw NotSupportedException(A_FUNCINFO, "blocking receive is not allowed in sequential");
255 return Request();
256 }
257 Request receive(Span<Type> recv_buffer, const PointToPointMessageInfo& message) override
258 {
259 ARCANE_UNUSED(recv_buffer);
260 if (message.isBlocking())
261 throw NotSupportedException(A_FUNCINFO, "blocking receive is not allowed in sequential");
262 return Request();
263 }
264 void sendRecv(ConstArrayView<Type> send_buffer, ArrayView<Type> recv_buffer, Int32 rank) override
265 {
266 ARCANE_UNUSED(rank);
267 recv_buffer.copy(send_buffer);
268 }
269 Type allReduce(eReduceType op, Type v) override
270 {
271 ARCANE_UNUSED(op);
272 return v;
273 }
274 void allReduce(eReduceType op, ArrayView<Type> send_buf) override
275 {
276 ARCANE_UNUSED(op);
277 ARCANE_UNUSED(send_buf);
278 }
279 void allReduce(eReduceType op, Span<Type> send_buf) override
280 {
281 ARCANE_UNUSED(op);
282 ARCANE_UNUSED(send_buf);
283 }
284 Request nonBlockingAllReduce(eReduceType op, Span<const Type> send_buf, Span<Type> recv_buf) override
285 {
286 ARCANE_UNUSED(op);
287 ARCANE_UNUSED(send_buf);
288 ARCANE_UNUSED(recv_buf);
289 return Request();
290 }
291 Request nonBlockingAllGather(Span<const Type> send_buf, Span<Type> recv_buf) override
292 {
293 recv_buf.copy(send_buf);
294 return Request();
295 }
296 Request nonBlockingBroadcast(Span<Type> send_buf, Int32 rank) override
297 {
298 ARCANE_UNUSED(send_buf);
299 ARCANE_UNUSED(rank);
300 return Request();
301 }
302 Request nonBlockingGather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override
303 {
304 ARCANE_UNUSED(rank);
305 recv_buf.copy(send_buf);
306 return Request();
307 }
308 Request nonBlockingAllToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override
309 {
310 ARCANE_UNUSED(count);
311 recv_buf.copy(send_buf);
312 return Request();
313 }
314 Request nonBlockingAllToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
315 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
316 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override
317 {
318 ARCANE_UNUSED(send_count);
319 ARCANE_UNUSED(recv_count);
320 ARCANE_UNUSED(send_index);
321 ARCANE_UNUSED(recv_index);
322 recv_buf.copy(send_buf);
323 return Request();
324 }
325 Type scan(eReduceType op, Type v) override
326 {
327 ARCANE_UNUSED(op);
328 return v;
329 }
330 void scan(eReduceType op, ArrayView<Type> send_buf) override
331 {
332 ARCANE_UNUSED(op);
333 ARCANE_UNUSED(send_buf);
334 }
335 void computeMinMaxSum(Type val, Type& min_val, Type& max_val, Type& sum_val,
336 Int32& min_rank,
337 Int32& max_rank) override
338 {
339 min_val = max_val = sum_val = val;
340 min_rank = max_rank = 0;
341 }
342 void computeMinMaxSum(ConstArrayView<Type> values,
343 ArrayView<Type> min_values,
344 ArrayView<Type> max_values,
345 ArrayView<Type> sum_values,
346 ArrayView<Int32> min_ranks,
347 ArrayView<Int32> max_ranks) override
348 {
349 const Integer n = values.size();
350 for (Integer i = 0; i < n; ++i) {
351 min_values[i] = max_values[i] = sum_values[i] = values[i];
352 min_ranks[i] = max_ranks[i] = 0;
353 }
354 }
355 ITypeDispatcher<Type>* toArccoreDispatcher() override { return this; }
356};
357
358/*---------------------------------------------------------------------------*/
359/*---------------------------------------------------------------------------*/
360
361class SequentialContigMachineShMemWinBaseInternal
363{
364 public:
365
366 SequentialContigMachineShMemWinBaseInternal(Int64 sizeof_segment, Int32 sizeof_type)
367 : m_sizeof_segment(sizeof_segment)
368 , m_max_sizeof_segment(sizeof_segment)
369 , m_sizeof_type(sizeof_type)
370 , m_segment(sizeof_segment)
371 {}
372
373 ~SequentialContigMachineShMemWinBaseInternal() override = default;
374
375 public:
376
377 Int32 sizeofOneElem() const override
378 {
379 return m_sizeof_type;
380 }
381
383 {
384 return m_segment.span().subSpan(0, m_sizeof_segment);
385 }
386 Span<std::byte> segmentView(const Int32 rank) override
387 {
388 if (rank != 0) {
389 ARCANE_FATAL("Rank {0} is unavailable (Sequential)", rank);
390 }
391 return m_segment.span().subSpan(0, m_sizeof_segment);
392 }
394 {
395 return m_segment.span().subSpan(0, m_sizeof_segment);
396 }
397
399 {
400 return m_segment.constSpan().subSpan(0, m_sizeof_segment);
401 }
403 {
404 if (rank != 0) {
405 ARCANE_FATAL("Rank {0} is unavailable (Sequential)", rank);
406 }
407 return m_segment.constSpan().subSpan(0, m_sizeof_segment);
408 }
410 {
411 return m_segment.constSpan().subSpan(0, m_sizeof_segment);
412 }
413
414 void resizeSegment(const Int64 new_sizeof_segment) override
415 {
416 if (new_sizeof_segment > m_max_sizeof_segment) {
417 ARCANE_FATAL("New size of window (sum of size of all segments) is superior than the old size");
418 }
419 m_sizeof_segment = new_sizeof_segment;
420 }
421
423 {
424 return ConstArrayView<Int32>{ 1, &m_my_rank };
425 }
426
427 void barrier() const override {}
428
429 private:
430
431 Int64 m_sizeof_segment = 0;
432 Int64 m_max_sizeof_segment = 0;
433
434 Int32 m_sizeof_type = 0;
435 UniqueArray<std::byte> m_segment;
436 Int32 m_my_rank = 0;
437};
438
439/*---------------------------------------------------------------------------*/
440/*---------------------------------------------------------------------------*/
441
442class SequentialMachineShMemWinBaseInternal
444{
445 public:
446
447 SequentialMachineShMemWinBaseInternal(Int64 sizeof_segment, Int32 sizeof_type)
448 : m_sizeof_type(sizeof_type)
449 , m_segment(sizeof_segment)
450 {}
451 ~SequentialMachineShMemWinBaseInternal() override = default;
452
453 public:
454
455 Int32 sizeofOneElem() const override
456 {
457 return m_sizeof_type;
458 }
460 {
461 return ConstArrayView<Int32>{ 1, &m_my_rank };
462 }
463 void barrier() const override {}
464
466 {
467 return m_segment;
468 }
470 {
471 if (rank != 0) {
472 ARCANE_FATAL("Rank {0} is unavailable (Sequential)", rank);
473 }
474 return m_segment;
475 }
477 {
478 return m_segment;
479 }
481 {
482 if (rank != 0) {
483 ARCANE_FATAL("Rank {0} is unavailable (Sequential)", rank);
484 }
485 return m_segment;
486 }
487 void add(Span<const std::byte> elem) override
488 {
489 if (elem.size() % m_sizeof_type != 0) {
490 ARCCORE_FATAL("Sizeof elem not valid");
491 }
492 m_segment.addRange(elem);
493 }
494 void add() override {}
496 {
497 if (rank != 0) {
498 ARCANE_FATAL("Rank {0} is unavailable (Sequential)", rank);
499 }
500 if (elem.size() % m_sizeof_type != 0) {
501 ARCCORE_FATAL("Sizeof elem not valid");
502 }
503 m_segment.addRange(elem);
504 }
505 void addToAnotherSegment() override {}
506
507 void reserve(Int64 new_capacity) override
508 {
509 m_segment.reserve(new_capacity);
510 }
511 void reserve() override {}
512 void resize(Int64 new_size) override
513 {
514 m_segment.resize(new_size);
515 }
516 void resize() override {}
517 void shrink() override
518 {
519 m_segment.shrink();
520 }
521
522 private:
523
524 Int32 m_sizeof_type;
525 UniqueArray<std::byte> m_segment;
526 Int32 m_my_rank = 0;
527};
528
529/*---------------------------------------------------------------------------*/
530/*---------------------------------------------------------------------------*/
531
534{
535 public:
536
542 {
543 return makeRef(createNullVariableSynchronizer(pm, family->allItems()));
544 }
546 {
547 return makeRef(createNullVariableSynchronizer(pm, group));
548 }
549};
550
551/*---------------------------------------------------------------------------*/
552/*---------------------------------------------------------------------------*/
553
560class SequentialParallelMng
561: public ParallelMngDispatcher
562{
563 public:
564
565 class Impl;
566
567 private:
568
569 // Constructs a sequential manager.
570 SequentialParallelMng(const SequentialParallelMngBuildInfo& bi);
571
572 public:
573
574 ~SequentialParallelMng();
575
576 bool isParallel() const override { return false; }
577 Int32 commRank() const override { return 0; }
578 Int32 commSize() const override { return 1; }
579 void* getMPICommunicator() override { return m_communicator.communicatorAddress(); }
580 Parallel::Communicator communicator() const override { return m_communicator; }
581 Parallel::Communicator machineCommunicator() const override { return m_communicator; }
582 bool isThreadImplementation() const override { return false; }
583 bool isHybridImplementation() const override { return false; }
584 void setBaseObject(IBase* m);
585 ITraceMng* traceMng() const override { return m_trace.get(); }
586 IThreadMng* threadMng() const override { return m_thread_mng; }
587 ITimerMng* timerMng() const override { return m_timer_mng; }
588 IParallelMng* worldParallelMng() const override { return m_world_parallel_mng; }
589 IIOMng* ioMng() const override { return m_io_mng; }
590
591 void initialize() override;
592 bool isMasterIO() const override { return true; }
593 Int32 masterIORank() const override { return 0; }
594
595 public:
596
597 void allGather(ISerializer* send_serializer, ISerializer* recv_serializer) override
598 {
599 recv_serializer->copy(send_serializer);
600 }
601 void sendSerializer(ISerializer* values, Int32 rank) override
602 {
603 ARCANE_UNUSED(values);
604 ARCANE_UNUSED(rank);
605 }
606 Request sendSerializer(ISerializer* values, Int32 rank, ByteArray& bytes) override
607 {
608 ARCANE_UNUSED(values);
609 ARCANE_UNUSED(rank);
610 ARCANE_UNUSED(bytes);
611 return Parallel::Request();
612 }
614 {
615 ARCANE_UNUSED(rank);
616 return new SerializeMessage(0, 0, ISerializeMessage::MT_Send);
617 }
618 void recvSerializer(ISerializer* values, Int32 rank) override
619 {
620 ARCANE_UNUSED(values);
621 ARCANE_UNUSED(rank);
622 }
624 {
625 ARCANE_UNUSED(rank);
626 return new SerializeMessage(0, 0, ISerializeMessage::MT_Recv);
627 }
628
629 void broadcastString(String& str, Int32 rank) override
630 {
631 ARCANE_UNUSED(str);
632 ARCANE_UNUSED(rank);
633 }
634 void broadcastMemoryBuffer(ByteArray& bytes, Int32 rank) override
635 {
636 ARCANE_UNUSED(bytes);
637 ARCANE_UNUSED(rank);
638 }
639 void broadcastSerializer(ISerializer* values, Int32 rank) override
640 {
641 ARCANE_UNUSED(values);
642 ARCANE_UNUSED(rank);
643 }
644 MessageId probe(const PointToPointMessageInfo& message) override
645 {
646 ARCANE_UNUSED(message);
647 return MessageId();
648 }
650 {
651 ARCANE_UNUSED(message);
652 return MessageSourceInfo();
653 }
654 Request sendSerializer(const ISerializer* values, const PointToPointMessageInfo& message) override
655 {
656 ARCANE_UNUSED(values);
657 ARCANE_UNUSED(message);
658 return Parallel::Request();
659 }
660 Request receiveSerializer(ISerializer* values, const PointToPointMessageInfo& message) override
661 {
662 ARCANE_UNUSED(values);
663 ARCANE_UNUSED(message);
664 return Parallel::Request();
665 }
666
668 {
669 ARCANE_UNUSED(messages);
670 }
672 {
673 ARCANE_UNUSED(requests);
674 }
675
676 void printStats() override {}
677 void barrier() override {}
678
679 IParallelMng* sequentialParallelMng() override { return this; }
680 Ref<IParallelMng> sequentialParallelMngRef() override { return makeRef<IParallelMng>(this); }
681
682 void waitAllRequests(ArrayView<Request> requests) override
683 {
684 ARCANE_UNUSED(requests);
685 }
686
687 // The requests are necessarily already satisfied.
689 {
690 ARCANE_UNUSED(requests);
691 return UniqueArray<Integer>();
692 }
694 {
695 return waitSomeRequests(requests);
696 }
697
698 ISerializeMessageList* _createSerializeMessageList() override
699 {
701 }
702 Real reduceRank(eReduceType rt, Real v, Int32* rank)
703 {
704 Real rv = reduce(rt, v);
705 if (rank)
706 *rank = 0;
707 return rv;
708 }
718 {
719 return new ParallelExchanger(this);
720 }
722 {
723 return createNullVariableSynchronizer(this, family->allItems());
724 }
726 {
727 return createNullVariableSynchronizer(this, group);
728 }
730 {
731 ParallelTopology* t = new ParallelTopology(this);
732 t->initialize();
733 return t;
734 }
735
737 {
738 return m_replication;
739 }
740
742 {
743 delete m_replication;
744 m_replication = v;
745 }
746
748 {
750 return makeRef(r);
751 }
752
754 {
755 return m_utils_factory;
756 }
757
759 {
760 return m_stat;
761 }
762
763 void build() override;
764
766
767 IParallelMngInternal* _internalApi() override { return m_parallel_mng_internal; }
768
769 public:
770
771 static IParallelMng* create(const SequentialParallelMngBuildInfo& bi)
772 {
773 if (!bi.traceMng())
774 ARCANE_THROW(ArgumentException, "null traceMng()");
775 if (!bi.threadMng())
776 ARCANE_THROW(ArgumentException, "null threadMng()");
777 auto x = new SequentialParallelMng(bi);
778 x->build();
779 return x;
780 }
782 {
783 return makeRef(create(bi));
784 }
785
786 protected:
787
788 IParallelMng* _createSubParallelMng(Int32ConstArrayView kept_ranks) override
789 {
790 ARCANE_UNUSED(kept_ranks);
791 SequentialParallelMngBuildInfo bi(m_timer_mng, m_world_parallel_mng);
792 bi.setThreadMng(m_thread_mng);
793 bi.setTraceMng(m_trace.get());
794 bi.setCommunicator(m_communicator);
795 return create(bi);
796 }
797
798 private:
799
800 ReferenceCounter<ITraceMng> m_trace;
801 IThreadMng* m_thread_mng = nullptr;
802 ITimerMng* m_timer_mng = nullptr;
803 IParallelMng* m_world_parallel_mng = nullptr;
804 IIOMng* m_io_mng;
805 Parallel::IStat* m_stat;
806 IParallelReplication* m_replication;
807 MP::Communicator m_communicator;
808 Ref<IParallelMngUtilsFactory> m_utils_factory;
809 IParallelMngInternal* m_parallel_mng_internal = nullptr;
810};
811
812/*---------------------------------------------------------------------------*/
813/*---------------------------------------------------------------------------*/
814
815extern "C++" IIOMng*
816arcaneCreateIOMng(IParallelMng* psm);
817
818/*---------------------------------------------------------------------------*/
819/*---------------------------------------------------------------------------*/
820
821extern "C++" IParallelMng*
822arcaneCreateSequentialParallelMng(const SequentialParallelMngBuildInfo& bi)
823{
824 return SequentialParallelMng::create(bi);
825}
826extern "C++" Ref<IParallelMng>
827arcaneCreateSequentialParallelMngRef(const SequentialParallelMngBuildInfo& bi)
828{
829 return SequentialParallelMng::createRef(bi);
830}
831
832/*---------------------------------------------------------------------------*/
833/*---------------------------------------------------------------------------*/
834
836: public ParallelMngInternal
837{
838 public:
839
840 explicit Impl(SequentialParallelMng* pm)
841 : ParallelMngInternal(pm)
842 , m_alloc(makeRef(new MachineShMemWinMemoryAllocator(pm)))
843 {}
844
845 ~Impl() override = default;
846
847 public:
848
849 Int32 masterParallelIORank() const override { return 0; }
850 Int32 nbSendersToMasterParallelIO() const override { return 1; }
851
852 void initializeWindowCreator() override {}
853
855 {
856 return true;
857 }
858
860 {
861 return makeRef(new SequentialContigMachineShMemWinBaseInternal(sizeof_segment, sizeof_type));
862 }
863
865 {
866 return makeRef(new SequentialMachineShMemWinBaseInternal(sizeof_segment, sizeof_type));
867 }
868
870 {
871 return MemoryAllocationOptions{ m_alloc.get() };
872 }
874 {
875 return { 1, &m_rank };
876 }
877 void machineBarrier() override {}
878
879 private:
880
882 const Int32 m_rank = 0;
883};
884
885/*---------------------------------------------------------------------------*/
886/*---------------------------------------------------------------------------*/
887
888SequentialParallelMng::
889SequentialParallelMng(const SequentialParallelMngBuildInfo& bi)
891, m_trace(bi.traceMng())
892, m_thread_mng(bi.threadMng())
893, m_timer_mng(bi.m_timer_mng)
894, m_world_parallel_mng(bi.m_world_parallel_mng)
895, m_io_mng(nullptr)
896, m_stat(nullptr)
897, m_replication(new ParallelReplication())
898, m_communicator(bi.communicator())
900, m_parallel_mng_internal(new Impl(this))
901{
902 ARCANE_CHECK_PTR(m_trace);
903 ARCANE_CHECK_PTR(m_thread_mng);
904 if (!m_world_parallel_mng)
905 m_world_parallel_mng = this;
907 _messagePassingMng()->setCommunicator(m_communicator);
908}
909
910/*---------------------------------------------------------------------------*/
911/*---------------------------------------------------------------------------*/
912
913SequentialParallelMng::
914~SequentialParallelMng()
915{
916 delete m_parallel_mng_internal;
917 delete m_stat;
918 delete m_replication;
919 delete m_io_mng;
920}
921
922/*---------------------------------------------------------------------------*/
923/*---------------------------------------------------------------------------*/
924
925void SequentialParallelMng::
926setBaseObject(IBase* sd)
927{
928 ARCANE_UNUSED(sd);
929}
930
931/*---------------------------------------------------------------------------*/
932/*---------------------------------------------------------------------------*/
933
934namespace
935{
936 // Class to create the different dispatchers
937 class DispatchCreator
938 {
939 public:
940
941 DispatchCreator(ITraceMng* tm)
942 : m_tm(tm)
943 {}
944
945 public:
946
947 template <typename DataType> SequentialParallelDispatchT<DataType>*
948 create()
949 {
950 return new SequentialParallelDispatchT<DataType>(m_tm);
951 }
952 ITraceMng* m_tm;
953 };
954} // namespace
955
957build()
958{
959 m_io_mng = arcaneCreateIOMng(this);
960 DispatchCreator creator(m_trace.get());
961 this->createDispatchers(creator);
962}
963
964/*---------------------------------------------------------------------------*/
965/*---------------------------------------------------------------------------*/
966
969{
970 traceMng()->info() << "** ** MPI Communicator = " << getMPICommunicator();
971}
972
973/*---------------------------------------------------------------------------*/
974/*---------------------------------------------------------------------------*/
975
976/*---------------------------------------------------------------------------*/
977/*---------------------------------------------------------------------------*/
978
979// Constructs a sequential supervisor linked to the \a sm supervisor
980SequentialParallelSuperMng::
981SequentialParallelSuperMng(const ServiceBuildInfo& sbi)
982: AbstractService(sbi)
983, m_application(sbi.application())
984, m_thread_mng(new NullThreadMng())
985, m_timer_mng(nullptr)
986{
987}
988
989/*---------------------------------------------------------------------------*/
990/*---------------------------------------------------------------------------*/
991
992// Constructs a sequential supervisor linked to the \a sm supervisor
993SequentialParallelSuperMng::
994SequentialParallelSuperMng(const ServiceBuildInfo& sbi, Parallel::Communicator comm)
995: AbstractService(sbi)
996, m_application(sbi.application())
997, m_thread_mng(new NullThreadMng())
998, m_timer_mng(nullptr)
999, m_communicator(comm)
1000{
1001}
1002
1003/*---------------------------------------------------------------------------*/
1004/*---------------------------------------------------------------------------*/
1005
1006// Constructs a sequential supervisor linked to the \a sm supervisor
1007SequentialParallelSuperMng::
1008~SequentialParallelSuperMng()
1009{
1010 delete m_thread_mng;
1011}
1012
1013/*---------------------------------------------------------------------------*/
1014/*---------------------------------------------------------------------------*/
1015
1027
1028/*---------------------------------------------------------------------------*/
1029/*---------------------------------------------------------------------------*/
1030
1032build()
1033{
1034 if (!m_timer_mng) {
1035 m_owned_timer_mng = new TimerMng(traceMng());
1036 m_timer_mng = m_owned_timer_mng.get();
1037 }
1038}
1039
1040/*---------------------------------------------------------------------------*/
1041/*---------------------------------------------------------------------------*/
1042
1045{
1046 if (local_rank != 0)
1047 ARCANE_THROW(ArgumentException, "Bad local_rank '{0}' (should be 0)", local_rank);
1048
1049 SequentialParallelMngBuildInfo bi(m_timer_mng, nullptr);
1050 bi.setThreadMng(threadMng());
1051 bi.setTraceMng(traceMng());
1052 bi.setCommunicator(communicator());
1053 return SequentialParallelMng::createRef(bi);
1054}
1055
1056/*---------------------------------------------------------------------------*/
1057/*---------------------------------------------------------------------------*/
1058
1063
1064/*---------------------------------------------------------------------------*/
1065/*---------------------------------------------------------------------------*/
1066
1069
1070/*---------------------------------------------------------------------------*/
1071/*---------------------------------------------------------------------------*/
1072
1073class SequentialParallelMngBuilder
1075{
1076 public:
1077
1078 SequentialParallelMngBuilder(IApplication* app, Parallel::Communicator comm)
1079 : m_application(app)
1080 , m_thread_mng(new NullThreadMng())
1081 , m_timer_mng(new TimerMng(app->traceMng()))
1082 , m_communicator(comm)
1083 {}
1084 ~SequentialParallelMngBuilder() override
1085 {
1086 delete m_timer_mng;
1087 delete m_thread_mng;
1088 }
1089
1090 public:
1091
1092 void build() {}
1093 Ref<IParallelMng> _createParallelMng(Int32 local_rank, ITraceMng* tm) override;
1094
1095 public:
1096
1097 IApplication* m_application;
1098 IThreadMng* m_thread_mng;
1099 ITimerMng* m_timer_mng;
1100 Parallel::Communicator m_communicator;
1101};
1102
1103/*---------------------------------------------------------------------------*/
1104/*---------------------------------------------------------------------------*/
1105
1107_createParallelMng(Int32 local_rank, ITraceMng* tm)
1108{
1109 if (local_rank != 0)
1110 ARCANE_THROW(ArgumentException, "Bad local_rank '{0}' (should be 0)", local_rank);
1111
1112 SequentialParallelMngBuildInfo bi(m_timer_mng, nullptr);
1113 bi.setTraceMng(tm);
1114 bi.setThreadMng(m_thread_mng);
1115 bi.setCommunicator(m_communicator);
1116 return arcaneCreateSequentialParallelMngRef(bi);
1117}
1118
1119/*---------------------------------------------------------------------------*/
1120/*---------------------------------------------------------------------------*/
1121
1122class SequentialParallelMngContainerFactory
1123: public AbstractService
1125{
1126 public:
1127
1128 SequentialParallelMngContainerFactory(const ServiceBuildInfo& sbi)
1129 : AbstractService(sbi)
1130 , m_application(sbi.application())
1131 {}
1132
1133 public:
1134
1137 {
1138 ARCANE_UNUSED(nb_rank);
1139 ARCANE_UNUSED(machine_comm);
1140 auto x = new SequentialParallelMngBuilder(m_application, comm);
1141 x->build();
1143 }
1144
1145 private:
1146
1147 IApplication* m_application;
1148};
1149
1150/*---------------------------------------------------------------------------*/
1151/*---------------------------------------------------------------------------*/
1152
1154 ServiceProperty("SequentialParallelMngContainerFactory", ST_Application),
1156
1157/*---------------------------------------------------------------------------*/
1158/*---------------------------------------------------------------------------*/
1159
1160} // End namespace Arcane
1161
1162/*---------------------------------------------------------------------------*/
1163/*---------------------------------------------------------------------------*/
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ARCCORE_FATAL(...)
Macro throwing a FatalErrorException.
#define ARCANE_SERVICE_INTERFACE(ainterface)
Macro to declare an interface when registering a service.
#define ARCANE_REGISTER_APPLICATION_FACTORY(aclass, ainterface, aname)
Registers a factory service for the class aclass.
Base class of a service.
AbstractService(const ServiceBuildInfo &)
Constructor from a ServiceBuildInfo.
Modifiable view of an array of type T.
void copy(const U &copy_array)
Copies the array copy_array into the instance.
constexpr Integer size() const noexcept
Returns the size of the array.
Base class for 1D data vectors.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Operations to access variable values from another subdomain.
Application interface.
Interface of the base class for main arcane objects.
Definition IBase.h:32
virtual ITraceMng * traceMng() const =0
Trace manager.
Operations to access variable values from another subdomain.
Interface of the input/output manager.
Definition IIOMng.h:37
Interface of an entity family.
Definition IItemFamily.h:83
virtual ItemGroup allItems() const =0
Group of all entities.
Parallel message handling for the type Type.
Information exchange between processors.
Interface for an 'IParallelMng' container factory.
Internal part of IParallelMng.
Interface of a factory for the utility functions of IParallelMng.
Interface of the parallelism manager for a subdomain.
virtual char reduce(eReduceType rt, char v)=0
Performs a reduction of type rt on the real v and returns the value.
Interface for non-blocking collective parallel operations.
Brief information on parallel subdomain replication.
Abstract class of the parallelism supervisor.
Information on the computing core allocation topology.
virtual void copy(const ISerializer *from)=0
Copies the data from from into this instance.
Interface of a thread manager.
Definition IThreadMng.h:32
Interface of a timer manager.
Definition ITimerMng.h:50
virtual TraceMessage info()=0
Stream for an information message.
Sends values across different processors.
Interface of a variable synchronization service.
Mesh entity group.
Definition ItemGroup.h:51
Communicator for message exchange.
Class allowing the creation of a memory window for a node of computation.
Class allowing the creation of memory windows for a computing node.
Parallel message handling for the type Type.
Information about the source of a message.
Information for sending/receiving a point-to-point message.
bool isBlocking() const
Indicates if the message is blocking.
Thread manager in single-threaded mode.
Information exchange between processors.
Redirects the message management of sub-domains according to the argument type.
IMessagePassingMng * messagePassingMng() const override
Associated Arccore message passing manager.
Base class of a factory for IParallelMng utility functions.
Brief information on parallel subdomain replication.
Information on the topology for allocating computing cores.
virtual void initialize()
Initializes the instance. This operation is collective.
Reference to an instance.
Span< std::byte > segmentView() override
Method allowing the retrieval of a view of its segment.
Int32 sizeofOneElem() const override
Method allowing the retrieval of the size of an element in the window.
void resizeSegment(const Int64 new_sizeof_segment) override
Method allowing the resizing of the window segments.
Span< const std::byte > windowConstView() const override
Method allowing the retrieval of a view of the entire window.
Span< const std::byte > segmentConstView() const override
Method allowing the retrieval of a view of its segment.
ConstArrayView< Int32 > machineRanks() const override
Method allowing the retrieval of the ranks that possess a segment in the window.
Span< std::byte > segmentView(const Int32 rank) override
Method allowing the retrieval of a view of the segment of another subdomain of the node.
void barrier() const override
Method allowing waiting until all processes/threads of the node call this method to continue executio...
Span< const std::byte > segmentConstView(const Int32 rank) const override
Method allowing the retrieval of a view of the segment of another subdomain of the node.
Span< std::byte > windowView() override
Method allowing the retrieval of a view of the entire window.
Span< const std::byte > segmentConstView() const override
Method to get a view of our segment.
Span< const std::byte > segmentConstView(Int32 rank) const override
Method to get a view of the segment of another subdomain of the node.
void addToAnotherSegment(Int32 rank, Span< const std::byte > elem) override
Method to add elements into the segment of another subdomain.
void barrier() const override
Method to wait until all processes/threads of the node call this method to continue execution.
ConstArrayView< Int32 > machineRanks() const override
Method to get the ranks that possess a segment in the window.
void shrink() override
Method to reduce the reserved memory space for the segments to the minimum necessary.
void add(Span< const std::byte > elem) override
Method to add elements into our segment.
Span< std::byte > segmentView() override
Method to get a view of our segment.
void reserve(Int64 new_capacity) override
Method to reserve memory space in our segment.
Int32 sizeofOneElem() const override
Method to get the size of an element in the window.
Span< std::byte > segmentView(Int32 rank) override
Method to get a view of the segment of another subdomain of the node.
void resize(Int64 new_size) override
Method to resize our segment.
Message interface for type Type.
Ref< IParallelMng > _createParallelMng(Int32 local_rank, ITraceMng *tm) override
Creates the IParallelMng for the local rank local_rank.
Ref< IParallelMngContainer > _createParallelMngBuilder(Int32 nb_rank, Parallel::Communicator comm, Parallel::Communicator machine_comm) override
Creates a container for nb_local_rank local ranks and with communicator as the communicator.
Ref< ITransferValuesParallelOperation > createTransferValuesOperation(IParallelMng *) override
Returns an operation to transfer values between ranks.
Ref< IVariableSynchronizer > createSynchronizer(IParallelMng *pm, const ItemGroup &group) override
Returns an interface to synchronize variables on the group group.
Ref< IVariableSynchronizer > createSynchronizer(IParallelMng *pm, IItemFamily *family) override
Returns an interface to synchronize variables on the group of the family family.
Ref< IMachineShMemWinBaseInternal > createMachineShMemWinBase(Int64 sizeof_segment, Int32 sizeof_type) override
Method allowing the creation of a dynamic memory window on the node.
Ref< IContigMachineShMemWinBaseInternal > createContigMachineShMemWinBase(Int64 sizeof_segment, Int32 sizeof_type) override
Method allowing the creation of a memory window on the node.
ConstArrayView< Int32 > machineRanks() override
Method allowing retrieval of the ranks of the sub-domains of the computing node.
void machineBarrier() override
Method allowing a barrier for the sub-domains of the computing node.
void initializeWindowCreator() override
Method allowing the initialization of the windowCreator specific to the implementation.
bool isMachineShMemWinAvailable() override
Method allowing to know if shared memory mode is supported.
MemoryAllocationOptions machineShMemWinMemoryAllocator() override
Method allowing retrieval of a shared memory allocator.
Sequential mode parallelism manager.
Parallel::Communicator communicator() const override
MPI communicator associated with this manager.
ISerializeMessage * createReceiveSerializer(Int32 rank) override
Creates a non-blocking message to receive serialized data from rank rank.
IParallelNonBlockingCollective * nonBlockingCollective() const override
Interface for non-blocking collective operations.
ITransferValuesParallelOperation * createTransferValuesOperation() override
Returns an operation to transfer values between subdomains.
IThreadMng * threadMng() const override
Thread manager.
UniqueArray< Integer > testSomeRequests(ArrayView< Request > requests) override
Tests if one of the rvalues requests is complete.
Int32 commRank() const override
Rank of this instance in the communicator.
ISerializeMessage * createSendSerializer(Int32 rank) override
Creates a non-blocking message to send serialized data to rank rank.
Int32 commSize() const override
Number of instances in the communicator.
IParallelMng * sequentialParallelMng() override
Returns a sequential parallelism manager.
void build() override
Constructs the instance.
void barrier() override
Performs a barrier.
void allGather(ISerializer *send_serializer, ISerializer *recv_serializer) override
Redefines allGather here to avoid hiding the symbol in derived classes.
Parallel::Communicator machineCommunicator() const override
MPI communicator derived from the communicator communicator() gathering all processes of the compute ...
IGetVariablesValuesParallelOperation * createGetVariablesValuesOperation() override
Returns an operation to retrieve the values of a variable on the entities of another subdomain.
IParallelReplication * replication() const override
Replication information.
ITimerMng * timerMng() const override
Timer manager.
MessageId probe(const PointToPointMessageInfo &message) override
Probes if messages are available.
Ref< IParallelMngUtilsFactory > _internalUtilsFactory() const override
Factory for utility functions.
MessageSourceInfo legacyProbe(const PointToPointMessageInfo &message) override
Probes if messages are available.
void processMessages(ConstArrayView< ISerializeMessage * > messages) override
Executes the operations of messages messages.
bool isMasterIO() const override
true if the instance is a master I/O manager.
bool isThreadImplementation() const override
Indicates if the implementation uses threads.
Ref< IRequestList > createRequestListRef() override
Creates a request list for this manager.
Parallel::IStat * stat() override
Statistics manager.
void printStats() override
Prints statistics related to this parallelism manager.
ITraceMng * traceMng() const override
Trace manager.
void initialize() override
Initializes the parallelism manager.
IParallelMng * worldParallelMng() const override
Parallelism manager over all allocated resources.
bool isHybridImplementation() const override
Indicates if the implementation uses hybrid mode.
IParallelTopology * createTopology() override
Creates an instance containing information about the rank topology of this manager.
bool isParallel() const override
Returns true if the execution is parallel.
void setReplication(IParallelReplication *v) override
Sets the Replication Information.
void freeRequests(ArrayView< Parallel::Request > requests) override
Frees the requests.
void waitAllRequests(ArrayView< Request > requests) override
Blocks while waiting for the rvalues requests to complete.
UniqueArray< Integer > waitSomeRequests(ArrayView< Request > requests) override
Blocks while waiting for one of the rvalues requests to complete.
IParallelMngInternal * _internalApi() override
Internal Arcane API.
void broadcastMemoryBuffer(ByteArray &bytes, Int32 rank) override
Performs a broadcast of a memory region.
IVariableSynchronizer * createSynchronizer(const ItemGroup &group) override
Returns an interface for synchronizing variables on the group.
IIOMng * ioMng() const override
I/O manager.
Int32 masterIORank() const override
Rank of the instance managing I/O (for which isMasterIO() is true).
IVariableSynchronizer * createSynchronizer(IItemFamily *family) override
Returns an interface for synchronizing variables on the group of the family.
IParallelExchanger * createExchanger() override
Returns an interface for transferring messages between processors.
Request sendSerializer(ISerializer *values, Int32 rank, ByteArray &bytes) override
void * getMPICommunicator() override
Address of the MPI communicator associated with this manager.
Sequential parallelism supervisor.
void initialize() override
Initializes the instance.
Ref< IParallelMng > internalCreateWorldParallelMng(Int32 local_rank) override
Creates a parallelism manager for all allocated cores.
MP::Communicator communicator() const override
MPI communicator associated with this manager.
void tryAbort() override
Attempts to abort.
void build() override
Build-level construction of the service.
IApplication * m_application
Associated supervisor.
IThreadMng * threadMng() const override
Thread manager.
void _wait(Parallel::eWaitType wait_mode)
Performs the wait or test.
Message using a SerializeBuffer.
IApplication * application() const
Access to the associated IApplication.
Structure containing the information to create a service.
Service creation properties.
__host__ __device__ void copy(const U &copy_array)
Copies the array copy_array into the instance.
Definition Span.h:477
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Definition Span.h:327
View of an array of elements of type T.
Definition Span.h:635
constexpr __host__ __device__ Span< T, DynExtent > subSpan(Int64 abegin, Int64 asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:736
Timer manager.
Definition TimerMng.h:40
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
ITraceMng * traceMng() const
Trace manager.
1D data vector with value semantics (STL style).
#define ARCANE_REGISTER_SERVICE(aclass, a_service_property,...)
Macro for registering a service.
Declarations of types and methods used by message exchange mechanisms.
eReduceType
Supported reduction types.
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.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
Definition UtilsTypes.h:121
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
@ ST_Application
The service is used at the application level.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
std::int32_t Int32
Signed integer type of 32 bits.
Type
Type of JSON value.
Definition rapidjson.h:730
Information to construct a SequentialParallelMng.