Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
VBlockMatrix.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/VBlockMatrix.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
33VBlockMatrix::VBlockMatrix()
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
40VBlockMatrix::VBlockMatrix(const VBlock& 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
49VBlockMatrix::VBlockMatrix(
50const VBlock& row_block, const VBlock& col_block, const MatrixDistribution& dist)
51: m_impl(
52 new MultiMatrixImpl(dist.rowSpace().clone(), dist.colSpace().clone(), dist.clone()))
53{
54 m_impl->setRowBlockInfos(&row_block);
55 m_impl->setColBlockInfos(&col_block);
56}
57
58/*---------------------------------------------------------------------------*/
59
60VBlockMatrix::VBlockMatrix(Integer nrows, Integer ncols, Integer nrows_local,
61 const VBlock& row_block, const VBlock& col_block, IMessagePassingMng* parallel_mng)
62: m_impl(
63 new MultiMatrixImpl(std::make_shared<Space>(nrows), std::make_shared<Space>(ncols),
64 std::make_shared<MatrixDistribution>(
65 MatrixDistribution(nrows, ncols, nrows_local, parallel_mng))))
66{
67 m_impl->setRowBlockInfos(&row_block);
68 m_impl->setColBlockInfos(&col_block);
69}
70
71/*---------------------------------------------------------------------------*/
72
73VBlockMatrix::VBlockMatrix(Integer nrows, Integer ncols, const VBlock& row_block,
74 const VBlock& col_block, IMessagePassingMng* parallel_mng)
75: m_impl(new MultiMatrixImpl(std::make_shared<Space>(nrows),
76 std::make_shared<Space>(ncols),
77 std::make_shared<MatrixDistribution>(MatrixDistribution(nrows, ncols, parallel_mng))))
78{
79 m_impl->setRowBlockInfos(&row_block);
80 m_impl->setColBlockInfos(&col_block);
81}
82
83/*---------------------------------------------------------------------------*/
84
85VBlockMatrix::VBlockMatrix(VBlockMatrix&& matrix)
86: m_impl(std::move(matrix.m_impl))
87{}
88
89/*---------------------------------------------------------------------------*/
90
91VBlockMatrix&
92VBlockMatrix::operator=(VBlockMatrix&& matrix)
93{
94 m_impl = std::move(matrix.m_impl);
95 return *this;
96}
97
98/*---------------------------------------------------------------------------*/
99
100void VBlockMatrix::init(const VBlock& block, const MatrixDistribution& dist)
101{
102 m_impl.reset(new MultiMatrixImpl(
103 dist.rowSpace().clone(), dist.colSpace().clone(), dist.clone()));
104 m_impl->setBlockInfos(&block);
105}
106
107/*---------------------------------------------------------------------------*/
108
109void VBlockMatrix::free()
110{
111 m_impl->free();
112}
113
114/*---------------------------------------------------------------------------*/
115
116void VBlockMatrix::clear()
117{
118 m_impl->clear();
119}
120
121/*---------------------------------------------------------------------------*/
122
124{
125 m.accept(m_impl);
126}
127
128/*---------------------------------------------------------------------------*/
129
131VBlockMatrix::distribution() const
132{
133 return m_impl->distribution();
134}
135
136/*---------------------------------------------------------------------------*/
137
138const ISpace&
140{
141 return m_impl->rowSpace();
142}
143
144/*---------------------------------------------------------------------------*/
145
146const ISpace&
148{
149 return m_impl->colSpace();
150}
151
152/*---------------------------------------------------------------------------*/
153
154void VBlockMatrix::setUserFeature(String feature)
155{
156 m_impl->setFeature(feature);
157}
158
159/*---------------------------------------------------------------------------*/
160
161bool VBlockMatrix::hasUserFeature(String feature) const
162{
163 return m_impl->hasFeature(feature);
164}
165
166/*---------------------------------------------------------------------------*/
167
168const VBlock&
169VBlockMatrix::vblock() const
170{
171 const VBlock* block = m_impl->vblock();
172 if (block)
173 return *block;
174 else
175 throw FatalErrorException(
176 A_FUNCINFO, "Requesting for block information but none was provided");
177}
178
179/*---------------------------------------------------------------------------*/
180
181const VBlock&
182VBlockMatrix::rowBlock() const
183{
184 const VBlock* block = m_impl->rowBlock();
185 if (block)
186 return *block;
187 else
188 throw FatalErrorException(
189 A_FUNCINFO, "Requesting for block information but none was provided");
190}
191
192/*---------------------------------------------------------------------------*/
193
194const VBlock&
195VBlockMatrix::colBlock() const
196{
197 const VBlock* block = m_impl->colBlock();
198 if (block)
199 return *block;
200 else
201 throw FatalErrorException(
202 A_FUNCINFO, "Requesting for block information but none was provided");
203}
204
205/*---------------------------------------------------------------------------*/
206
207MultiMatrixImpl*
209{
210 if (!m_impl) {
211 m_impl.reset(new MultiMatrixImpl());
212 }
213 /* JMG ????
214 else if (!m_impl.unique()) { // Need to clone due to other references.
215 m_impl.reset(m_impl->clone());
216 } */
217 return m_impl.get();
218}
219
220/*---------------------------------------------------------------------------*/
221
222const MultiMatrixImpl*
224{
225 return m_impl.get();
226}
227
228/*---------------------------------------------------------------------------*/
229/*---------------------------------------------------------------------------*/
230
231} // namespace Alien
232
233/*---------------------------------------------------------------------------*/
234/*---------------------------------------------------------------------------*/
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
void visit(ICopyOnWriteMatrix &) const
Visit method.
MultiMatrixImpl * impl()
Get the multimatrix implementation.
const ISpace & colSpace() const
Get col space associated to the matrix.
const ISpace & rowSpace() const
Get row space associated to the matrix.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17