Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
BlockMatrix.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 <alien/ref/data/block/BlockMatrix.h>
20
21#include <alien/ref/AlienRefSemantic.h>
22#include <alien/utils/ICopyOnWriteObject.h>
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Alien
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33BlockMatrix::BlockMatrix()
34: m_impl(new MultiMatrixImpl(std::make_shared<Space>(0), std::make_shared<Space>(0),
35 std::make_shared<MatrixDistribution>(MatrixDistribution())))
36{}
37
38/*---------------------------------------------------------------------------*/
39
40BlockMatrix::BlockMatrix(const Block& block, const MatrixDistribution& dist)
41: m_impl(
42 new MultiMatrixImpl(dist.rowSpace().clone(), dist.colSpace().clone(), dist.clone()))
43{
44 m_impl->setBlockInfos(&block);
45}
46
47/*---------------------------------------------------------------------------*/
48
49BlockMatrix::BlockMatrix(Integer nrows, Integer ncols, Integer nrows_local,
50 const Block& block, IMessagePassingMng* parallel_mng)
51: m_impl(
52 new MultiMatrixImpl(std::make_shared<Space>(nrows), std::make_shared<Space>(ncols),
53 std::make_shared<MatrixDistribution>(
54 MatrixDistribution(nrows, ncols, nrows_local, parallel_mng))))
55{
56 m_impl->setBlockInfos(&block);
57}
58
59/*---------------------------------------------------------------------------*/
60
61BlockMatrix::BlockMatrix(
62Integer nrows, Integer ncols, const Block& block, IMessagePassingMng* parallel_mng)
63: m_impl(new MultiMatrixImpl(std::make_shared<Space>(nrows),
64 std::make_shared<Space>(ncols),
65 std::make_shared<MatrixDistribution>(MatrixDistribution(nrows, ncols, parallel_mng))))
66{
67 m_impl->setBlockInfos(&block);
68}
69
70/*---------------------------------------------------------------------------*/
71
72BlockMatrix::BlockMatrix(BlockMatrix&& matrix)
73: m_impl(std::move(matrix.m_impl))
74{}
75
76/*---------------------------------------------------------------------------*/
77
78BlockMatrix&
79BlockMatrix::operator=(BlockMatrix&& matrix)
80{
81 m_impl = std::move(matrix.m_impl);
82 return *this;
83}
84
85/*---------------------------------------------------------------------------*/
86
87void BlockMatrix::init(const Block& block, const MatrixDistribution& dist)
88{
89 m_impl.reset(new MultiMatrixImpl(
90 dist.rowSpace().clone(), dist.colSpace().clone(), dist.clone()));
91 m_impl->setBlockInfos(&block);
92}
93
94/*---------------------------------------------------------------------------*/
95
96void BlockMatrix::free()
97{
98 m_impl->free();
99}
100
101/*---------------------------------------------------------------------------*/
102
103void BlockMatrix::clear()
104{
105 m_impl->clear();
106}
107
108/*---------------------------------------------------------------------------*/
109
111{
112 m.accept(m_impl);
113}
114
115/*---------------------------------------------------------------------------*/
116
118BlockMatrix::distribution() const
119{
120 return m_impl->distribution();
121}
122
123/*---------------------------------------------------------------------------*/
124
125const ISpace&
127{
128 return m_impl->rowSpace();
129}
130
131/*---------------------------------------------------------------------------*/
132
133const ISpace&
135{
136 return m_impl->colSpace();
137}
138
139/*---------------------------------------------------------------------------*/
140
141void BlockMatrix::setUserFeature(String feature)
142{
143 m_impl->setFeature(feature);
144}
145
146/*---------------------------------------------------------------------------*/
147
148bool BlockMatrix::hasUserFeature(String feature) const
149{
150 return m_impl->hasFeature(feature);
151}
152
153/*---------------------------------------------------------------------------*/
154
155const Block&
156BlockMatrix::block() const
157{
158 const Block* block = m_impl->block();
159 if (block)
160 return *block;
161 else
162 throw FatalErrorException(
163 A_FUNCINFO, "Requesting for block information but none was provided");
164}
165
166/*---------------------------------------------------------------------------*/
167
168MultiMatrixImpl*
170{
171 if (!m_impl) {
172 m_impl.reset(new MultiMatrixImpl());
173 }
174 /* JMG ????
175 else if (!m_impl.unique()) { // Need to clone due to other references.
176 m_impl.reset(m_impl->clone());
177 } */
178 return m_impl.get();
179}
180
181/*---------------------------------------------------------------------------*/
182
183const MultiMatrixImpl*
185{
186 return m_impl.get();
187}
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
191
192} // namespace Alien
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
MultiMatrixImpl * impl()
Get the multimatrix implementation.
const ISpace & rowSpace() const
Get row space associated to the matrix.
void visit(ICopyOnWriteMatrix &) const
Visit method.
const ISpace & colSpace() const
Get col space associated to the matrix.
Interface for algebraic space objects.
Definition ISpace.h:44
Computes a matrix distribution.
Multi matrices representation container.
Implementation of an algebraic space.
Definition Space.h:47
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17