29#include <arccore/message_passing/Messages.h>
32#include <alien/utils/Trace.h>
40using namespace Arccore;
41using namespace Arccore::MessagePassing;
71 Internal(Integer global_size, IMessagePassingMng* parallel_mng);
78 Internal(Integer global_size, std::shared_ptr<IMessagePassingMng> parallel_mng);
95 std::shared_ptr<IMessagePassingMng> parallel_mng);
103 Internal(Integer global_size, Integer local_size, IMessagePassingMng* parallel_mng);
111 Internal(Integer global_size, Integer local_size,
112 std::shared_ptr<IMessagePassingMng> parallel_mng);
135 Integer
owner(Integer i)
const;
172const ISpace&
space, IMessagePassingMng* parallel_mng)
175 parallel_mng, [](IMessagePassingMng*) {}))
177, m_global_size(m_space->size())
183 m_rank = m_parallel_mng->commRank();
184 Integer np = parallel_mng->commSize();
185 UniqueArray<Integer> lsize(np, m_global_size / np);
186 for (Integer i = 0; i < m_global_size % np; ++i)
188 m_offsets.resize(np, 0);
189 for (Integer i = 1; i < np; ++i) {
190 m_offsets[i] = lsize[i - 1] + m_offsets[i - 1];
192 m_offsets.add(m_global_size);
193 m_offset = m_offsets[m_rank];
194 m_local_size = lsize[m_rank];
201const ISpace&
space, std::shared_ptr<IMessagePassingMng> parallel_mng)
212 Integer np = parallel_mng->commSize();
217 for (Integer i = 1; i < np; ++i) {
229Integer global_size, IMessagePassingMng* parallel_mng)
237Integer global_size, std::shared_ptr<IMessagePassingMng> parallel_mng)
245const ISpace&
space, Integer local_size, IMessagePassingMng* parallel_mng)
248 parallel_mng, [](IMessagePassingMng*) {}))
250, m_global_size(m_space->size())
251, m_local_size(local_size)
256 m_rank = m_parallel_mng->commRank();
257 Integer np = parallel_mng->commSize();
258 UniqueArray<Integer> lsize(np, 0);
259 lsize[m_rank] = m_local_size;
260 Arccore::MessagePassing::mpAllReduce(
261 m_parallel_mng.get(), Arccore::MessagePassing::ReduceMax, lsize.view());
262 Integer gsize = std::accumulate(lsize.begin(), lsize.end(), 0);
263 if (gsize != m_global_size) {
265 cout() <<
"error, expected global size (" << m_global_size
266 <<
") is not equal to computed global size (" << gsize <<
")";
269 m_offsets.resize(np, 0);
271 for (Integer i = 1; i < np; ++i) {
275 m_offsets.add(m_global_size);
276 m_offset = m_offsets[m_rank];
283 std::shared_ptr<IMessagePassingMng> parallel_mng)
294 Integer np = parallel_mng->commSize();
295 UniqueArray<Integer> lsize(np, 0);
297 Arccore::MessagePassing::mpAllReduce(
298 m_parallel_mng.get(), Arccore::MessagePassing::ReduceMax, lsize.view());
299 Integer gsize = std::accumulate(lsize.begin(), lsize.end(), 0);
303 <<
") is not equal to computed global size (" << gsize <<
")";
308 for (Integer i = 1; i < np; ++i) {
320Integer global_size, Integer local_size, IMessagePassingMng* parallel_mng)
328 std::shared_ptr<IMessagePassingMng> parallel_mng)
361 for (
int rk =
m_rank - 1; rk > 0; --rk) {
370 for (
int rk =
m_rank + 1; rk < np - 1; ++rk) {
385 alien_debug([&] { cout() <<
"Create Empty VectorDistribution"; });
392const ISpace& space, IMessagePassingMng* parallel_mng)
393: m_internal(std::make_shared<Internal>(space, parallel_mng))
396 [&] { cout() <<
"Create VectorDistribution(global=" <<
space.
size() <<
")"; });
403const ISpace& space, std::shared_ptr<IMessagePassingMng> parallel_mng)
404: m_internal(std::make_shared<Internal>(space, parallel_mng))
407 [&] { cout() <<
"Create VectorDistribution(global=" <<
space.size() <<
")"; });
414Integer global_size, IMessagePassingMng* parallel_mng)
415: m_internal(std::make_shared<Internal>(global_size, parallel_mng))
418 [&] { cout() <<
"Create VectorDistribution(global=" << global_size <<
")"; });
425const ISpace& space, Integer local_size, IMessagePassingMng* parallel_mng)
426: m_internal(std::make_shared<Internal>(space, local_size, parallel_mng))
429 cout() <<
"Create VectorDistribution(global=" <<
space.size()
430 <<
"local=" << local_size <<
")";
438 std::shared_ptr<IMessagePassingMng> parallel_mng)
439: m_internal(std::make_shared<Internal>(space, local_size, parallel_mng))
442 cout() <<
"Create VectorDistribution(global=" <<
space.size()
443 <<
"local=" << local_size <<
")";
451Integer global_size, Integer local_size, IMessagePassingMng* parallel_mng)
452: m_internal(std::make_shared<Internal>(global_size, local_size, parallel_mng))
455 cout() <<
"Create VectorDistribution(global=" << global_size <<
"local=" << local_size
464 std::shared_ptr<IMessagePassingMng> parallel_mng)
465: m_internal(std::make_shared<Internal>(global_size, local_size, parallel_mng))
468 cout() <<
"Create VectorDistribution(global=" << global_size <<
"local=" << local_size
549std::shared_ptr<IMessagePassingMng>
603ConstArrayView<Integer>
612std::shared_ptr<VectorDistribution>
615 return std::make_shared<VectorDistribution>(*
this);
660 nout <<
"1d distributed";
662 nout <<
", parallel";
664 nout <<
", global size=" << dist.
globalSize();
665 nout <<
", local size=" << dist.
localSize();
666 nout <<
", offset=" << dist.
offset();
Interface for algebraic space objects.
virtual Arccore::Integer size() const =0
Get space size.
Implementation of an algebraic space.
Computes a vector distribution.
VectorDistribution & operator=(const VectorDistribution &dist)
Equal operator.
std::shared_ptr< VectorDistribution > clone() const
Clone the distribution.
bool operator==(const VectorDistribution &dist) const
Comparison operator.
std::shared_ptr< Arccore::MessagePassing::IMessagePassingMng > sharedParallelMng() const
Get the parallel manager.
VectorDistribution()
Constructor.
Arccore::Integer offset() const
Get the offset.
Arccore::ConstArrayView< Integer > offsets() const
Get all the offsets.
const ISpace & space() const
Get the space.
Arccore::Integer owner(Arccore::Integer i) const
Get the owner of an entry.
Arccore::Integer localToGlobal(Arccore::Integer i) const
Get the global id of an elements with its local id.
Arccore::Integer globalToLocal(Arccore::Integer i) const
Get the local id of an elements with its global id.
Arccore::Integer localSize() const
Get the local size.
bool isParallel() const
Whether or not the run is parallel.
Arccore::Integer globalSize() const
Get the global size.
Arccore::MessagePassing::IMessagePassingMng * parallelMng() const
Get the parallel manager.
~VectorDistribution()
Free resources.
std::shared_ptr< Internal > m_internal
Internal implementation of the vector distribution.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::ostream & operator<<(std::ostream &nout, const MatrixDistribution &dist)
Print the distribution.
Internal implementation of the vector distribution.
~Internal()=default
Free resources.
Integer owner(Integer i) const
Get the owner of an entry.
std::shared_ptr< IMessagePassingMng > m_parallel_mng
The parallel manager.
UniqueArray< Integer > m_offsets
The array of offsets for all proc.
bool operator==(const Internal &dist) const
Comparison operator.
Integer m_global_size
The global size.
std::shared_ptr< ISpace > m_space
The space.
Integer m_offset
The local offset.
Integer m_local_size
The local size.
Integer m_rank
The local rank.
bool isParallel() const
Whether or not the run is parallel.