Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
MultiMatrixImpl.h
Go to the documentation of this file.
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
23
24#pragma once
25
26#include <map>
27
28#include <alien/core/backend/BackEnd.h>
33#include <alien/data/Space.h>
35#include <alien/utils/ObjectWithLock.h>
36#include <alien/utils/Precomp.h>
37#include <alien/utils/UserFeatureMng.h>
38#include <alien/utils/time_stamp/TimestampMng.h>
39#include <cstdlib>
40#include <iostream>
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
45namespace Alien
46{
47
48/*---------------------------------------------------------------------------*/
49/*---------------------------------------------------------------------------*/
50
65class ALIEN_EXPORT MultiMatrixImpl : public TimestampMng
66, public UserFeatureMng
67, public ObjectWithTrace
68, public ObjectWithLock
69{
70 public:
73
80 MultiMatrixImpl(std::shared_ptr<ISpace> row_space, std::shared_ptr<ISpace> col_space,
81 std::shared_ptr<MatrixDistribution> dist);
82
84 virtual ~MultiMatrixImpl();
85
86 protected:
92
93 public:
98 void setBlockInfos(Arccore::Integer block_size);
99
104 void setBlockInfos(const Block* blocks);
105
110 void setBlockInfos(const VBlock* blocks);
111
116 void setRowBlockInfos(const VBlock* blocks);
117
122 void setColBlockInfos(const VBlock* blocks);
123
125 void free();
127 void clear();
128
133 const ISpace& rowSpace() const { return *m_row_space.get(); }
134
139 const ISpace& colSpace() const { return *m_col_space.get(); }
140
145 const MatrixDistribution& distribution() const { return *m_distribution.get(); }
146
152 const Block* block() const;
153
159 const VBlock* vblock() const;
160
166 const VBlock* rowBlock() const;
167
173 const VBlock* colBlock() const;
174
175 public:
184 template <typename tag>
185 const typename AlgebraTraits<tag>::matrix_type& get() const;
186
196 template <typename tag>
197 typename AlgebraTraits<tag>::matrix_type& get(const bool update_stamp);
198
200 template <typename tag>
201 void release() const;
202
207 MultiMatrixImpl* clone() const;
208
209 // TOCHECK : should be removed or not ?
210 // void setTimestamp(Int64 stamp)
211 // {
212 // TimestampMng::setTimestamp(stamp);
213 // }
214
215 private:
221 template <typename matrix_type>
222 IMatrixImpl*& getImpl(BackEndId backend) const;
223
228 void updateImpl(IMatrixImpl* target) const;
229
230 protected:
236 template <typename matrix_type>
237 void insert(BackEndId backend, matrix_type* m);
238
239 private:
241 std::shared_ptr<ISpace> m_row_space;
243 std::shared_ptr<ISpace> m_col_space;
245 std::shared_ptr<MatrixDistribution> m_distribution;
247 typedef std::map<BackEndId, IMatrixImpl*> MultiMatrixImplMap;
251 std::shared_ptr<Block> m_block;
253 std::shared_ptr<VBlock> m_rows_block;
255 std::shared_ptr<VBlock> m_cols_block;
256};
257
258/*---------------------------------------------------------------------------*/
259/*---------------------------------------------------------------------------*/
260
261template <typename tag>
264{
265 // TOCHECK : to be removed or not ?
266 // ALIEN_ASSERT(!m_row_space.isNull(), ("Null row space matrix access"));
267 // ALIEN_ASSERT(!m_col_space.isNull(), ("Null col space matrix access"));
270 ALIEN_ASSERT(
271 (impl2->backend() == AlgebraTraits<tag>::name()), ("Inconsistent backend"));
272 updateImpl(impl2);
273 return *dynamic_cast<matrix_type*>(impl2);
274}
275
276/*---------------------------------------------------------------------------*/
277/*---------------------------------------------------------------------------*/
278
279template <typename tag>
281MultiMatrixImpl::get(const bool update_stamp)
282{
283 // TOCHECK : to be removed or not ?
284 // ALIEN_ASSERT(!m_row_space.isNull(), ("Null row space matrix access"));
285 // ALIEN_ASSERT(!m_col_space.isNull(), ("Null col space matrix access"));
288 ALIEN_ASSERT(
289 (impl2->backend() == AlgebraTraits<tag>::name()), ("Inconsistent backend"));
290 updateImpl(impl2);
291 if (update_stamp)
292 impl2->updateTimestamp();
293 return *dynamic_cast<matrix_type*>(impl2);
294}
295
296/*---------------------------------------------------------------------------*/
297/*---------------------------------------------------------------------------*/
298
299template <typename tag>
301{
302 auto finder = m_impls2.find(AlgebraTraits<tag>::name());
303 if (finder == m_impls2.end())
304 return; // already freed
305 delete finder->second, finder->second = NULL;
306}
307
308/*---------------------------------------------------------------------------*/
309/*---------------------------------------------------------------------------*/
310
311template <typename matrix_type>
313MultiMatrixImpl::getImpl(BackEndId backend) const
314{
315 auto inserter = m_impls2.insert(MultiMatrixImplMap::value_type(backend, NULL));
316 IMatrixImpl*& impl2 = inserter.first->second;
317 if (impl2 == NULL) {
318 matrix_type* new_impl = new matrix_type(this); // constructeur associé à un multi-impl
319 // new_impl->init(*m_row_space.get(),
320 // *m_col_space.get(),
321 // m_distribution);
322 impl2 = new_impl;
323 }
324 return impl2;
325}
326
327/*---------------------------------------------------------------------------*/
328/*---------------------------------------------------------------------------*/
329
330template <typename matrix_type>
331void MultiMatrixImpl::insert(BackEndId backend, matrix_type* m)
332{
333 if (m_impls2.find(backend) != m_impls2.end()) {
334 alien_fatal([&] { cout() << "try to insert already inserted value"; });
335 }
336 m_impls2[backend] = m;
337}
338
339/*---------------------------------------------------------------------------*/
340/*---------------------------------------------------------------------------*/
341
342} // namespace Alien
343
344/*---------------------------------------------------------------------------*/
345/*---------------------------------------------------------------------------*/
Block.h.
IMatrixImpl.h.
MatrixConverterRegisterer.h.
MatrixDistribution.h.
Space.h.
VBlock.h.
Block elements for block matrices.
Definition Block.h:45
Interface to handle abstract matrices implementation.
Definition IMatrixImpl.h:47
virtual BackEndId backend() const
Definition IMatrixImpl.h:94
Interface for algebraic space objects.
Definition ISpace.h:44
Computes a matrix distribution.
Multi matrices representation container.
void setColBlockInfos(const VBlock *blocks)
Set variable col block information.
void insert(BackEndId backend, matrix_type *m)
Insert a matrix implementation in the multi matrix container.
std::shared_ptr< ISpace > m_row_space
The matrix row space.
std::shared_ptr< MatrixDistribution > m_distribution
The matrix distribution.
void setRowBlockInfos(const VBlock *blocks)
Set variable row block information.
void updateImpl(IMatrixImpl *target) const
Update a matrix implementation.
void release() const
Release a matrix implementation.
MultiMatrixImpl()
Default constructor.
std::shared_ptr< VBlock > m_cols_block
The variable col block datas.
std::shared_ptr< Block > m_block
The uniform block datas.
std::map< BackEndId, IMatrixImpl * > MultiMatrixImplMap
The type of the matrix container.
void clear()
Clear resources.
const MatrixDistribution & distribution() const
Get the matrix distribution.
void free()
Free resources.
IMatrixImpl *& getImpl(BackEndId backend) const
Get a specific matrix implementation.
std::shared_ptr< ISpace > m_col_space
The matrix column space.
const ISpace & rowSpace() const
Get the row space associated to the matrix.
std::shared_ptr< VBlock > m_rows_block
The variable row block datas.
MultiMatrixImplMap m_impls2
The matrices container.
const AlgebraTraits< tag >::matrix_type & get() const
Get a specific matrix implementation.
const ISpace & colSpace() const
Get the col space associated to the matrix.
void setBlockInfos(Arccore::Integer block_size)
Set uniform block information.
void updateTimestamp()
Met à jour le timestamp.
Definition Timestamp.cc:50
Variable size block elements for block matrices.
Definition VBlock.h:46
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17