Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
RedistributorMatrix.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 * RedistributorMatrix.cc
21 *
22 * Created on: 27 juil. 2016
23 * Author: chevalic
24 */
25
26#include "RedistributorMatrix.h"
27
29#include <alien/kernels/dok/DoKBackEnd.h>
30#include <alien/kernels/dok/DoKMatrixT.h>
31
32#include "RedistributorBackEnd.h"
33#include "RedistributorCommPlan.h"
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38namespace Alien
39{
40
41using namespace Arccore;
42using namespace Arccore::MessagePassing;
43
44RedistributorMatrix::RedistributorMatrix(const MultiMatrixImpl* src_impl, bool use_dok)
45: IMatrixImpl(src_impl, AlgebraTraits<BackEnd::tag::redistributor>::name())
46, m_super_pm(nullptr)
47, m_tgt_impl(nullptr)
48, m_use_dok(use_dok)
49{
50 // Cannot call our "distribution()" from a constructor.
51 m_super_pm = IMatrixImpl::distribution().parallelMng();
52}
53
55{
56 // m_tgt_impl.reset(nullptr);
57 // m_tgt_dist.reset(nullptr);
58}
59
60void RedistributorMatrix::setSuperPM(IMessagePassingMng* pm)
61{
62 m_super_pm = pm;
63}
64
65void RedistributorMatrix::useCSRRedistributor()
66{
67 m_use_dok = false;
68}
69
70std::shared_ptr<MultiMatrixImpl>
71RedistributorMatrix::updateTargetPM(const RedistributorCommPlan* commPlan)
72{
73 if (m_tgt_impl && m_tgt_impl->distribution().parallelMng() == commPlan->tgtParallelMng().get())
74 return m_tgt_impl;
75
76 const MatrixDistribution& src_dist = distribution();
77 m_tgt_dist.reset(new MatrixDistribution(
78 src_dist.globalRowSize(), src_dist.globalColSize(), commPlan->tgtParallelMng()));
79 m_tgt_impl.reset(
80 new MultiMatrixImpl(rowSpace().clone(), colSpace().clone(), m_tgt_dist));
81
82 // Now, we have to exchange data, using DoK representation.
83 if (m_use_dok)
84 m_distributor.reset(new DoKDistributor(commPlan));
85 else {
86 const VectorDistribution& row_src_dist = distribution().rowDistribution();
87 const auto& mat_src = m_multi_impl->get<BackEnd::tag::simplecsr>();
88 m_simple_csr_distibutor = std::make_unique<SimpleCSRDistributor>(commPlan, row_src_dist, &mat_src.getProfile());
89 }
90 return redistribute();
91}
92
93std::shared_ptr<MultiMatrixImpl>
94RedistributorMatrix::redistribute()
95{
96 if (m_use_dok) {
97 auto& mat_src = m_multi_impl->get<BackEnd::tag::DoK>();
98 auto& mat_tgt = m_tgt_impl->get<BackEnd::tag::DoK>(true);
99 m_distributor->distribute(mat_src, mat_tgt);
100 }
101 else {
102 auto& mat_src = m_multi_impl->get<BackEnd::tag::simplecsr>();
103 auto& mat_tgt = m_tgt_impl->get<BackEnd::tag::simplecsr>(true);
104 m_simple_csr_distibutor->distribute(mat_src, mat_tgt);
105 }
106 return m_tgt_impl;
107}
108
109} // namespace Alien
MultiMatrixImpl.h.
Interface to handle abstract matrices implementation.
Definition IMatrixImpl.h:47
Multi matrices representation container.
void clear() override
Demande la lib�ration des donn�es.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17