Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
DoKDistributor.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#include "DoKDistributor.h"
20
21#include <vector>
22
23#include "DoKBackEnd.h"
24#include "DoKMatrixT.h"
25#include "DoKVector.h"
26
27#include <alien/kernels/redistributor/RedistributorCommPlan.h>
28
29namespace Alien
30{
31
32DoKDistributor::DoKDistributor(const RedistributorCommPlan* commPlan)
33: m_distributor(new DoKDistributorComm(commPlan))
34{}
35
36void DoKDistributor::distribute(const DoKMatrix& src, DoKMatrix& dst)
37{
38 distribute(src.data(), dst.data());
39}
40
41void DoKDistributor::distribute(const DoKVector& src, DoKVector& dst)
42{
43 std::vector<std::pair<Arccore::Int32, DoKVector::ValueType>> pair_values(src.m_data.begin(), src.m_data.end());
44 std::sort(pair_values.begin(), pair_values.end());
45
46 Arccore::UniqueArray<Int32> snd_keys(src.m_data.size());
47 Arccore::UniqueArray<DoKVector::ValueType> snd_values(src.m_data.size());
48
49 int i = 0;
50 for (auto k : pair_values) {
51 snd_keys[i] = k.first;
52 snd_values[i] = k.second;
53 i++;
54 }
55
56 m_distributor->computeCommPlan(snd_keys);
57
58 const auto size = m_distributor->rcvSize();
59 // We split in 2 arrays to be able to use Arccore ...
60 UniqueArray<DoKVector::ValueType> rcv_values(size);
61 UniqueArray<Int32> rcv_keys(size);
62 m_distributor->exchange(snd_keys.constView(), rcv_keys.view());
63 m_distributor->exchange(snd_values.constView(), rcv_values.view());
64
65 dst.m_data.clear();
66
67 for (int offset = 0; offset < size; ++offset) {
68 dst.set(rcv_keys[offset], rcv_values[offset]);
69 }
70}
71
72} // namespace Alien
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17