Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
DoKMatrixT.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
23
24#include <alien/kernels/dok/DoKDistributor.h>
25#include <alien/kernels/dok/DoKLocalMatrixT.h>
26
27#include <alien/kernels/redistributor/Redistributor.h>
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Alien
33{
34
38class DoKMatrix : public IMatrixImpl
39{
40 public:
41 typedef Real ValueType;
42
43 public:
44 explicit DoKMatrix(const MultiMatrixImpl* multi_impl = nullptr)
45 : IMatrixImpl(multi_impl, "DoK")
46 , m_data()
47 {}
48
49 DoKMatrix(const DoKMatrix&) = delete;
50
51 ~DoKMatrix() override = default;
52
53 void clear() override {}
54
60 bool setNNZ(Int32 row, Int32 col, const ValueType& value)
61 {
62 m_data.set(row, col, value);
63 m_need_update = true;
64 return true;
65 }
66
72 ValueType addNNZ(Int32 row, Int32 col, const ValueType& value)
73 {
74 m_need_update = true;
75 return m_data.add(row, col, value);
76 }
77
79 void assemble() { _distribute(); }
80
81 void compact() { m_data.compact(); }
82
83 DoKLocalMatrixT<ValueType>& data() { return m_data; }
84
85 DoKLocalMatrixT<ValueType>& data() const { return m_data; }
86
87 void dump() { m_data.dump(); }
88
89 private:
90 void _distribute()
91 {
92 m_need_update = Arccore::MessagePassing::mpAllReduce(distribution().parallelMng(), Arccore::MessagePassing::ReduceSum, m_need_update);
93 if (!m_need_update) {
94 return;
95 }
96 Redistributor redist(
97 distribution().globalRowSize(), distribution().parallelMng(), distribution().parallelMng());
98 DoKDistributor dist(redist.commPlan());
99 DoKLocalMatrixT<ValueType> new_data;
100 // distribute does not work if src == tgt.
101 dist.distribute(m_data, new_data);
102 m_data = new_data;
103 m_data.compact();
104 m_need_update = false;
105 }
106
107 private:
108 // TODO remove mutable !
109 mutable DoKLocalMatrixT<ValueType> m_data;
110 bool m_need_update = true;
111};
112
113} // namespace Alien
IMatrixImpl.h.
MultiMatrixImpl.h.
void compact()
Group non-zeros according to indexer.
void clear() override
Wipe out internal data.
Definition DoKMatrixT.h:53
bool setNNZ(Int32 row, Int32 col, const ValueType &value)
Definition DoKMatrixT.h:60
ValueType addNNZ(Int32 row, Int32 col, const ValueType &value)
Definition DoKMatrixT.h:72
void assemble()
Dispatch matrix elements.
Definition DoKMatrixT.h:79
virtual const MatrixDistribution & distribution() const
Get the distribution of the matrix.
IMatrixImpl(const MultiMatrixImpl *multi_impl, BackEndId backend="")
Constructor.
Multi matrices representation container.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17