Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
DoKDistributor.h
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#pragma once
20
21#include <alien/utils/Precomp.h>
23
24#include <alien/kernels/dok/DoKDistributorComm.h>
25#include <alien/kernels/dok/DoKLocalMatrixT.h>
26
27namespace Alien
28{
29
30class DoKMatrix;
31class DoKVector;
33
34class ALIEN_EXPORT DoKDistributor
35{
36 public:
37 explicit DoKDistributor(const RedistributorCommPlan* commPlan);
38 virtual ~DoKDistributor() = default;
39
40 void distribute(const DoKMatrix& src, DoKMatrix& dst);
41
42 void distribute(const DoKVector& src, DoKVector& dst);
43
44 template <typename NNZValue>
46 {
47 /* Distribution algorithm:
48 * 1 - Compact local data
49 * 2 - Compute communication plan
50 * 3 - Perform communication
51 * 4 - Return new local DoKMatrix
52 *
53 * Note: this function can almost be used to redistribute data accross
54 * different IMessagePassingMng.
55 */
56
57 src.compact();
58
59 // Copy values to a send buffer, in case src and dst are the same matrix.
60 UniqueArray<NNZValue> snd_values = src.getValues(); // TODO: avoid this copy
61
62 m_distributor->computeCommPlan(src.getReverseIndexer());
63 UniqueArray<NNZValue> rcv_values(m_distributor->rcvSize());
64 m_distributor->exchange(snd_values.constView(), rcv_values.view());
65
66 dst.setMaxNnz(rcv_values.size());
67
68 for (int offset = 0; offset < (int)rcv_values.size(); ++offset) {
69 auto index = m_distributor->getCoordinates(offset);
70 dst.set(index.first, index.second, rcv_values[offset]);
71 }
72 }
73
74 private:
75 std::unique_ptr<DoKDistributorComm> m_distributor;
76};
77
78} // namespace Alien
MatrixDistribution.h.
void set(Int32 i, Int32 j, const NNZValue &val)
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17