Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
SimpleCSRVector.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7
8#pragma once
9
13#include <alien/data/ISpace.h>
14#include <alien/kernels/simple_csr/SimpleCSRBackEnd.h>
15#include <alien/kernels/simple_csr/SimpleCSRPrecomp.h>
16#include <iostream>
17
18/*---------------------------------------------------------------------------*/
19
20namespace Alien {
21
22template <typename ValueT>
24{
25 public:
26 typedef ValueT ValueType;
27
30 : IVectorImpl(nullptr, AlgebraTraits<BackEnd::tag::simplecsr>::name())
31 {}
32
35 : IVectorImpl(multi_impl, AlgebraTraits<BackEnd::tag::simplecsr>::name())
36 {}
37
38 Integer blockSize() const
39 {
40 if (block())
41 {
42 return block()->size();
43 }
44 else if (vblock()) {
45 return 1 ;
46 }
47 else {
48 return m_own_block_size ;
49 }
50 }
51
52 void setBlockSize(Integer block_size)
53 {
54 if(this->m_multi_impl)
55 const_cast<MultiVectorImpl*>(this->m_multi_impl)->setBlockInfos(block_size) ;
56 else
57 m_own_block_size = block_size ;
58 }
59
60 void allocate()
61 {
62 m_values.resize(scalarizedLocalSize());
63 if (this->vblock())
64 m_vblock.reset(new VBlockImpl(*this->vblock(), this->distribution()));
65 }
66
67 void resize(Integer alloc_size) const
68 {
69 if (alloc_size > scalarizedLocalSize())
70 m_values.resize(alloc_size);
71 if (this->vblock()) {
72 m_vblock.reset(new VBlockImpl(*this->vblock(), this->distribution()));
73 }
74 }
75
76 Integer getAllocSize() const { return m_values.size(); }
77
78 void clear() override
79 {
80 m_values.dispose();
81 m_vblock.reset();
82 }
83
84 // values on local part
85 Arccore::ArrayView<ValueType> values()
86 {
87 return m_values.subView(0, scalarizedLocalSize());
88 }
89
90 Arccore::ConstArrayView<ValueType> values() const
91 {
92 return m_values.subConstView(0, scalarizedLocalSize());
93 }
94
95 // Algebra adds ghost values
96 ArrayView<ValueType> fullValues() { return m_values; }
97 ConstArrayView<ValueType> fullValues() const { return m_values; }
98
99 void setArrayValues(UniqueArray<ValueType>&& rhs) { m_values.copy(rhs); }
100
101 UniqueArray<ValueType> const& getArrayValues() const { return m_values; }
102
103 ValueType* getDataPtr() { return m_values.data(); }
104 ValueType* data() { return m_values.data(); }
105
106 ValueType const* getDataPtr() const { return m_values.data(); }
107 ValueType const* data() const { return m_values.data(); }
108 ValueType const* getAddressData() const { return m_values.data(); }
109
110 ValueType& operator[](Integer index) { return m_values[index]; }
111
112 ValueType const& operator[](Integer index) const { return m_values[index]; }
113
114 // FIXME: not implemented !
115 template <typename E>
116 SimpleCSRVector& operator=(E const& expr);
117
118 void init(const VectorDistribution& dist,
119 const bool need_allocate) override
120 {
121 if (this->m_multi_impl) {
122 if (this->vblock()) {
123 m_vblock.reset(new VBlockImpl(*this->vblock(), this->distribution()));
124 }
125 m_local_size = this->distribution().localSize();
126 }
127 else {
128 // Not associated vector
129 m_own_distribution = dist;
130 m_local_size = m_own_distribution.localSize();
131 }
132 if (need_allocate) {
133 m_values.resize(scalarizedLocalSize());
134 m_values.fill(ValueT());
135 }
136 }
137
138 void init(const VectorDistribution& dist,
139 Integer block_size,
140 const bool need_allocate)
141 {
142 alien_debug([&] { cout() << "Initializing SimpleCSRVector " << this; });
143 setBlockSize(block_size) ;
144 if (this->m_multi_impl) {
145 if (this->vblock()) {
146 m_vblock.reset(new VBlockImpl(*this->vblock(), this->distribution()));
147 }
148 m_local_size = this->distribution().localSize();
149 }
150 else {
151 // Not associated vector
152 m_own_distribution = dist;
153 m_local_size = m_own_distribution.localSize();
154 }
155 if (need_allocate) {
156 m_values.resize(scalarizedLocalSize());
157 m_values.fill(ValueT());
158 }
159 }
160
161 const VectorDistribution& distribution() const override
162 {
163 if (this->m_multi_impl)
165 else
166 return m_own_distribution;
167 }
168
169 Arccore::Integer scalarizedLocalSize() const override
170 {
171 if (this->m_multi_impl)
173 else
174 return m_own_distribution.localSize()*m_own_block_size;
175 }
176
177 Arccore::Integer scalarizedGlobalSize() const override
178 {
179 if (this->m_multi_impl)
181 else
182 return m_own_distribution.globalSize()*m_own_block_size;
183 }
184
185 Arccore::Integer scalarizedOffset() const override
186 {
187 if (this->m_multi_impl)
189 else
190 return m_own_distribution.offset()*m_own_block_size;
191 }
192
193 const VBlockImpl& vblockImpl() const { return *m_vblock; }
194
196 void update([[maybe_unused]] const SimpleCSRVector<ValueT>& v)
197 {
198 ALIEN_ASSERT((this == &v), ("Unexpected error"));
199 }
201
202 SimpleCSRVector<ValueT>* cloneTo(const MultiVectorImpl* impl) const
203 {
205 vector->init(this->distribution(), true);
206 ConstArrayView<ValueType> thisValues = this->fullValues();
207 vector->resize(thisValues.size());
208 for (Integer i = 0; i < thisValues.size(); ++i)
209 (*vector)[i] = m_values[i];
210 return vector;
211 }
212
213 private:
214 mutable UniqueArray<ValueT> m_values;
215 Integer m_local_size = 0;
216 Integer m_own_block_size = 1 ;
217 VectorDistribution m_own_distribution;
218 mutable std::unique_ptr<VBlockImpl> m_vblock ;
219};
220
221/*---------------------------------------------------------------------------*/
222
223} // namespace Alien
224
225/*---------------------------------------------------------------------------*/
ISpace.h.
IVectorImpl.h.
MultiVectorImpl.h.
VBlockOffsets.h.
Arccore::Integer size() const
Get square block size.
Definition Block.cc:90
virtual Arccore::Integer scalarizedOffset() const
Get the "scalarized" offset.
const MultiVectorImpl * m_multi_impl
Pointer on vectors implementations.
virtual const Block * block() const
Get block datas of the vector.
virtual const VectorDistribution & distribution() const
Get the distribution of the vector.
IVectorImpl(const MultiVectorImpl *multi_impl, BackEndId backend="")
Constructor.
virtual Arccore::Integer scalarizedGlobalSize() const
Get the "scalarized" global size.
virtual const VBlock * vblock() const
Get block datas of the vector.
virtual Arccore::Integer scalarizedLocalSize() const
Get the "scalarized" local size.
SimpleCSRVector()
Constructeur sans association ? un MultiImpl.
Arccore::Integer scalarizedGlobalSize() const override
Get the "scalarized" global size.
SimpleCSRVector(const MultiVectorImpl *multi_impl)
Constructeur avec association ? un MultiImpl.
void init(const VectorDistribution &dist, const bool need_allocate) override
Initialize vector datas.
const VectorDistribution & distribution() const override
Get the distribution of the vector.
void clear() override
Wipe out internal data.
Arccore::Integer scalarizedOffset() const override
Get the "scalarized" offset.
Arccore::Integer scalarizedLocalSize() const override
Get the "scalarized" local size.
Compute block offsets for variable block elements.
Computes a vector distribution.
Arccore::Integer localSize() const
Get the local size.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17