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 alien_debug([&] { cout() << "Initializing SimpleCSRVector " << this; });
122 if (this->m_multi_impl) {
123 if (this->vblock()) {
124 m_vblock.reset(new VBlockImpl(*this->vblock(), this->distribution()));
125 }
126 m_local_size = this->distribution().localSize();
127 }
128 else {
129 // Not associated vector
130 m_own_distribution = dist;
131 m_local_size = m_own_distribution.localSize();
132 }
133 if (need_allocate) {
134 m_values.resize(scalarizedLocalSize());
135 m_values.fill(ValueT());
136 }
137 }
138
139 void init(const VectorDistribution& dist,
140 Integer block_size,
141 const bool need_allocate)
142 {
143 alien_debug([&] { cout() << "Initializing SimpleCSRVector " << this; });
144 setBlockSize(block_size) ;
145 if (this->m_multi_impl) {
146 if (this->vblock()) {
147 m_vblock.reset(new VBlockImpl(*this->vblock(), this->distribution()));
148 }
149 m_local_size = this->distribution().localSize();
150 }
151 else {
152 // Not associated vector
153 m_own_distribution = dist;
154 m_local_size = m_own_distribution.localSize();
155 }
156 if (need_allocate) {
157 m_values.resize(scalarizedLocalSize());
158 m_values.fill(ValueT());
159 }
160 }
161
162 const VectorDistribution& distribution() const override
163 {
164 if (this->m_multi_impl)
166 else
167 return m_own_distribution;
168 }
169
170 Arccore::Integer scalarizedLocalSize() const override
171 {
172 if (this->m_multi_impl)
174 else
175 return m_own_distribution.localSize()*m_own_block_size;
176 }
177
178 Arccore::Integer scalarizedGlobalSize() const override
179 {
180 if (this->m_multi_impl)
182 else
183 return m_own_distribution.globalSize()*m_own_block_size;
184 }
185
186 Arccore::Integer scalarizedOffset() const override
187 {
188 if (this->m_multi_impl)
190 else
191 return m_own_distribution.offset()*m_own_block_size;
192 }
193
194 const VBlockImpl& vblockImpl() const { return *m_vblock; }
195
197 void update([[maybe_unused]] const SimpleCSRVector<ValueT>& v)
198 {
199 ALIEN_ASSERT((this == &v), ("Unexpected error"));
200 }
202
203 SimpleCSRVector<ValueT>* cloneTo(const MultiVectorImpl* impl) const
204 {
206 vector->init(this->distribution(), true);
207 ConstArrayView<ValueType> thisValues = this->fullValues();
208 vector->resize(thisValues.size());
209 for (Integer i = 0; i < thisValues.size(); ++i)
210 (*vector)[i] = m_values[i];
211 return vector;
212 }
213
214 private:
215 mutable UniqueArray<ValueT> m_values;
216 Integer m_local_size = 0;
217 Integer m_own_block_size = 1 ;
218 VectorDistribution m_own_distribution;
219 mutable std::unique_ptr<VBlockImpl> m_vblock ;
220};
221
222/*---------------------------------------------------------------------------*/
223
224} // namespace Alien
225
226/*---------------------------------------------------------------------------*/
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