19#include "RedistributorCommPlan.h"
21#include <arccore/message_passing/Messages.h>
23#include <alien/utils/Precomp.h>
28using namespace Arccore;
29using namespace Arccore::MessagePassing;
31RedistributorCommPlan::RedistributorCommPlan(
32int globalSize, IMessagePassingMng* super_pm, IMessagePassingMng* target_pm)
35, m_proc_num(super_pm->commSize() + 1, -1)
36, m_tgt_dist(super_pm->commSize() + 1, -1)
38 m_tgt_distribution.reset(
new VectorDistribution(globalSize, m_tgt_pm));
41 tgt_rank = m_tgt_pm->commRank();
42 m_proc_num.resize(m_tgt_pm->commSize());
46 UniqueArray<Int32> reverse_proc_num(m_super_pm->commSize());
47 Arccore::MessagePassing::mpAllGather(
48 m_super_pm, ConstArrayView<Int32>(1, &tgt_rank), reverse_proc_num);
50 for (Int32 i = 0; i < (Int32)reverse_proc_num.size(); ++i) {
51 Int32 rank = reverse_proc_num[i];
56 this->_buildTgtDist();
59RedistributorCommPlan::~RedistributorCommPlan() {}
61std::shared_ptr<IMessagePassingMng>
62RedistributorCommPlan::tgtParallelMng()
const
64 return m_tgt_distribution->sharedParallelMng();
68RedistributorCommPlan::superParallelMng()
const
73const VectorDistribution&
74RedistributorCommPlan::distribution()
const
76 return *m_tgt_distribution;
80RedistributorCommPlan::tgtDist()
const
82 return m_tgt_dist.view();
85Int32 RedistributorCommPlan::procNum(Int32 proc)
const
87 return m_proc_num[proc];
90void RedistributorCommPlan::_buildTgtDist()
92 Int32 super_comm_size = m_super_pm->commSize();
97 Int32 dst_comm_size = m_tgt_pm->commSize();
98 for (Int32 p = 0; p < dst_comm_size; p++) {
99 m_tgt_dist[m_proc_num[p]] = m_tgt_distribution->offset(p);
101 m_tgt_dist[super_comm_size] = m_tgt_distribution->globalSize();
104 if (m_tgt_dist[0] < 0)
106 for (Int32 p = super_comm_size; p > 0; --p) {
107 if (m_tgt_dist[p] < 0) {
108 m_tgt_dist[p] = m_tgt_dist[p + 1];
111 super_rank = m_super_pm->commRank();
115 Int32 root = Arccore::MessagePassing::mpAllReduce(
116 m_super_pm, Arccore::MessagePassing::ReduceMax, super_rank);
119 Arccore::MessagePassing::mpBroadcast(m_super_pm, m_tgt_dist, root);
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --