Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
MultiVectorImpl.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 <iostream>
27#include <map>
28
29#include <alien/core/backend/BackEnd.h>
34#include <alien/data/Space.h>
36#include <alien/utils/Precomp.h>
37#include <alien/utils/UserFeatureMng.h>
38#include <alien/utils/time_stamp/TimestampMng.h>
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43namespace Alien
44{
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49class ALIEN_EXPORT MultiVectorImpl : public TimestampMng
50, public UserFeatureMng
51, public ObjectWithTrace
52{
68 public:
71
78 std::shared_ptr<ISpace> space, std::shared_ptr<VectorDistribution> dist);
79
81 ~MultiVectorImpl() override;
82
83 protected:
89
90 public:
91 MultiVectorImpl(MultiVectorImpl&& impl) = delete;
92 void operator=(const MultiVectorImpl&) = delete;
93 void operator=(MultiVectorImpl&&) = delete;
94
95 public:
100 void setBlockInfos(const Block* blocks);
101
106 void setBlockInfos(const VBlock* blocks);
107
112 void setBlockInfos(Arccore::Integer block_size);
113
115 void free();
116
118 void clear();
119
124 const ISpace& space() const { return *m_space.get(); }
125
130 const VectorDistribution& distribution() const { return *m_distribution.get(); }
131
137 const Block* block() const;
138
144 const VBlock* vblock() const;
145
146 public:
151 MultiVectorImpl* clone() const;
152
161 template <typename tag>
162 const typename AlgebraTraits<tag>::vector_type& get() const;
163
173 template <typename tag>
174 typename AlgebraTraits<tag>::vector_type& get(bool update_stamp);
175
177 template <typename tag>
178 void release() const;
179
180 private:
186 template <typename vector_type>
187 IVectorImpl*& getImpl(BackEndId backend) const;
188
193 void updateImpl(IVectorImpl* target) const;
194
195 protected:
201 template <typename vector_type>
202 void insert(const BackEndId& backend, vector_type* v);
203
204 private:
206 std::shared_ptr<ISpace> m_space;
208 std::shared_ptr<VectorDistribution> m_distribution;
210 typedef std::map<BackEndId, IVectorImpl*> MultiVectorImplMap;
214 std::shared_ptr<Block> m_block;
216 std::shared_ptr<VBlock> m_variable_block;
217};
218
219/*---------------------------------------------------------------------------*/
220/*---------------------------------------------------------------------------*/
221
222template <typename tag>
225{
228 ALIEN_ASSERT(
229 (impl2->backend() == AlgebraTraits<tag>::name()), ("Inconsistent backend"));
230 updateImpl(impl2);
231 return *dynamic_cast<vector_type*>(impl2);
232}
233
234/*---------------------------------------------------------------------------*/
235/*---------------------------------------------------------------------------*/
236
237template <typename tag>
239MultiVectorImpl::get(const bool update_stamp)
240{
243 ALIEN_ASSERT(
244 (impl2->backend() == AlgebraTraits<tag>::name()), ("Inconsistent backend"));
245 updateImpl(impl2);
246 if (update_stamp) {
247 impl2->updateTimestamp();
248 }
249 return *dynamic_cast<vector_type*>(impl2);
250}
251
252/*---------------------------------------------------------------------------*/
253/*---------------------------------------------------------------------------*/
254
255template <typename tag>
257{
258 auto finder = m_impls2.find(AlgebraTraits<tag>::name());
259 if (finder == m_impls2.end())
260 return; // already freed
261 delete finder->second, finder->second = NULL;
262}
263
264/*---------------------------------------------------------------------------*/
265/*---------------------------------------------------------------------------*/
266
267template <typename vector_type>
269MultiVectorImpl::getImpl(BackEndId backend) const
270{
271 auto inserter = m_impls2.insert(MultiVectorImplMap::value_type(backend, NULL));
272 IVectorImpl*& impl2 = inserter.first->second;
273 if (impl2 == NULL) {
274 auto new_impl = new vector_type(this); // constructeur associ� � un multi-impl
275 new_impl->init(*m_distribution.get(), true);
276 impl2 = new_impl;
277 }
278 return impl2;
279}
280
281/*---------------------------------------------------------------------------*/
282/*---------------------------------------------------------------------------*/
283
284template <typename vector_type>
285void MultiVectorImpl::insert(const BackEndId& backend, vector_type* v)
286{
287 if (m_impls2.find(backend) != m_impls2.end()) {
288 alien_fatal([&] { cout() << "try to insert already inserted value"; });
289 }
290 m_impls2[backend] = v;
291}
292
293/*---------------------------------------------------------------------------*/
294/*---------------------------------------------------------------------------*/
295
296} // namespace Alien
297
298/*---------------------------------------------------------------------------*/
299/*---------------------------------------------------------------------------*/
Block.h.
IVectorImpl.h.
Space.h.
VBlock.h.
VectorConverterRegisterer.h.
VectorDistribution.h.
Block elements for block matrices.
Definition Block.h:45
Interface for algebraic space objects.
Definition ISpace.h:44
Interface to handle abstract vectors implementation.
Definition IVectorImpl.h:47
virtual BackEndId backend() const
Definition IVectorImpl.h:95
std::shared_ptr< ISpace > m_space
The vector space.
std::shared_ptr< VectorDistribution > m_distribution
The vector distribution.
std::shared_ptr< Block > m_block
The uniform block datas.
void free()
Free resources.
void updateImpl(IVectorImpl *target) const
Update a vector implementation.
MultiVectorImplMap m_impls2
The vectors container.
void insert(const BackEndId &backend, vector_type *v)
Insert a vector implementation in the multi vector container.
void clear()
Clear resources.
const AlgebraTraits< tag >::vector_type & get() const
Get a specific vector implementation.
const VectorDistribution & distribution() const
Get the vector distribution.
void setBlockInfos(Arccore::Integer block_size)
Set uniform block information.
std::map< BackEndId, IVectorImpl * > MultiVectorImplMap
The type of the vector container.
void release() const
Release a vector implementation.
void setBlockInfos(const Block *blocks)
Set uniform block information.
std::shared_ptr< VBlock > m_variable_block
The variable block datas.
const ISpace & space() const
Get the space associated with the vector.
IVectorImpl *& getImpl(BackEndId backend) const
Get a specific vector implementation.
void updateTimestamp()
Met à jour le timestamp.
Definition Timestamp.cc:50
Variable size block elements for block matrices.
Definition VBlock.h:46
Computes a vector distribution.
MultiVectorImpl()
Multi vectors representation container.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17