19#include "SimpleCSRVectorRedistributor.h"
21#include <alien/kernels/redistributor/RedistributorCommPlan.h>
22#include <alien/utils/Precomp.h>
27using namespace Arccore;
30: m_comm_plan(commPlan)
31, m_pm_super(m_comm_plan->superParallelMng())
32, m_pm_dst(m_comm_plan->tgtParallelMng().get())
34 this->_computeCommPlan(src_dist);
37SimpleCSRVectorRedistributor::~SimpleCSRVectorRedistributor() {}
39void SimpleCSRVectorRedistributor::_computeCommPlan(
const VectorDistribution& src_dist)
41 Int32 super_comm_size = m_pm_super->commSize();
45 ConstArrayView<Int32> tgt_dist = m_comm_plan->tgtDist();
47 const Integer localSize = src_dist.localSize();
48 const Integer offset = src_dist.offset();
51 UniqueArray<Int32> snd_rows(localSize, 0);
53 for (Integer i = 0; i < localSize; ++i)
54 snd_rows[i] = i + offset;
58 auto is_mine = [&](Int32 p, Int32 rowid) {
59 return (tgt_dist[p] <= rowid) && (rowid < tgt_dist[p + 1]);
62 m_snd_offset.resize(super_comm_size + 1);
63 m_snd_offset.fill(-1);
65 for (Integer i = 0; i < localSize; i++) {
66 Int32 row_id = snd_rows[i];
67 while ((!is_mine(p, row_id)) && p < super_comm_size) {
72 for (
int p2 = p; p2 < super_comm_size; p2++)
73 m_snd_offset[p2 + 1] = localSize;
75 UniqueArray<Int32> snd_count(super_comm_size);
76 Alien::RedistributionTools::computeCounts(m_snd_offset.constView(), snd_count.view());
77 m_rcv_offset.resize(super_comm_size + 1);
78 UniqueArray<Int32> rcv_count(super_comm_size);
80 Arccore::MessagePassing::mpAllToAll(m_pm_super, snd_count, rcv_count, 1);
83 for (p = 0; p < super_comm_size; ++p) {
84 m_rcv_offset[p + 1] = m_rcv_offset[p] + rcv_count[p];
88void SimpleCSRVectorRedistributor::distribute(
89const SimpleCSRVector<Real>& src, SimpleCSRVector<Real>& tgt)
92 UniqueArray<Real> snd_values = src.fullValues();
93 UniqueArray<Real> rcv_values(this->rcvSize());
95 Alien::RedistributionTools::exchange(m_pm_super, snd_values.constView(),
96 m_snd_offset.constView(), rcv_values.view(), m_rcv_offset.constView());
98 ArrayView<Real> values = tgt.fullValues();
99 for (Integer i = 0; i < values.size(); ++i)
100 values[i] = rcv_values[i];
103void SimpleCSRVectorRedistributor::distributeBack(
104const SimpleCSRVector<Real>& src, SimpleCSRVector<Real>& tgt)
107 UniqueArray<Real> snd_values = src.fullValues();
108 UniqueArray<Real> rcv_values(this->rcvBackSize());
110 Alien::RedistributionTools::exchange(m_pm_super, snd_values.constView(),
111 m_rcv_offset.constView(), rcv_values.view(), m_snd_offset.constView());
113 ArrayView<Real> values = tgt.fullValues();
114 for (Integer i = 0; i < values.size(); ++i)
115 values[i] = rcv_values[i];
Computes a vector distribution.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --