Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
RedistributorVector.cc
1/*
2 * Copyright 2020 IFPEN-CEA
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 */
18
19/*
20 * RedistributorVector.cc
21 *
22 * Created on: 27 juil. 2016
23 * Author: chevalic
24 */
25#include "RedistributorVector.h"
26
28#include <alien/kernels/simple_csr/SimpleCSRBackEnd.h>
29#include <alien/kernels/simple_csr/SimpleCSRVector.h>
30#include <alien/utils/time_stamp/TimestampObserver.h>
31
32#include "RedistributorBackEnd.h"
33#include "RedistributorCommPlan.h"
34
35namespace Alien
36{
37using namespace Arccore;
38
39RedistributorVector::RedistributorVector(const MultiVectorImpl* src_impl)
40: IVectorImpl(src_impl, AlgebraTraits<BackEnd::tag::redistributor>::name())
41, m_super_pm(nullptr)
42, m_tgt_impl(nullptr)
43{
44 m_super_pm = distribution().parallelMng();
45}
46
47void RedistributorVector::init(const VectorDistribution& dist ALIEN_UNUSED_PARAM,
48 const bool need_allocate ALIEN_UNUSED_PARAM)
49{
50 return;
51}
52
54{
55 // m_tgt_impl.reset(nullptr);
56 // m_tgt_dist.reset(nullptr);
57}
58
59void RedistributorVector::updateSuperPM(MultiVectorImpl* tgt_impl ALIEN_UNUSED_PARAM,
60 const RedistributorCommPlan* commPlan ALIEN_UNUSED_PARAM)
61{
62 // TODO Throw exception
63 /*
64 if (!m_tgt_impl || m_tgt_impl->distribution().parallelMng() !=
65 commPlan->tgtParallelMng()) return; redistributeBack(tgt_impl);
66 */
67}
68
69std::shared_ptr<MultiVectorImpl>
70RedistributorVector::updateTargetPM(const RedistributorCommPlan* commPlan)
71{
72 if (m_tgt_impl && m_tgt_impl->distribution().parallelMng() == commPlan->tgtParallelMng().get())
73 return m_tgt_impl;
74
75 m_tgt_dist.reset(new VectorDistribution(commPlan->distribution()));
76 m_tgt_impl.reset(new MultiVectorImpl(space().clone(), m_tgt_dist));
77
78 m_tgt_impl->addObserver(std::make_shared<TimestampObserver>(*this));
79
80 const VectorDistribution& src_dist = distribution();
81 m_distributor.reset(new SimpleCSRVectorRedistributor(commPlan, src_dist));
82 return redistribute();
83}
84
85std::shared_ptr<MultiVectorImpl>
86RedistributorVector::redistribute()
87{
88 auto& vec_src = m_multi_impl->get<BackEnd::tag::simplecsr>();
89 auto& vec_tgt = m_tgt_impl->get<BackEnd::tag::simplecsr>(true);
90 m_distributor->distribute(vec_src, vec_tgt);
91 return m_tgt_impl;
92}
93
94void RedistributorVector::redistributeBack(SimpleCSRVector<Real>& vec_tgt) const
95{
96 auto& vec_src = m_tgt_impl->get<BackEnd::tag::simplecsr>();
97 m_distributor->distributeBack(vec_src, vec_tgt);
98}
99
100} // namespace Alien
MultiVectorImpl.h.
Interface to handle abstract vectors implementation.
Definition IVectorImpl.h:47
void clear() override
Clear data.
void init(const VectorDistribution &dist, const bool need_allocate) override
Initialize vector datas.
Computes a vector distribution.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17