Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
VBlockOffsets.cc
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#include "VBlockOffsets.h"
25
26#include <arccore/base/FatalErrorException.h>
27#include <arccore/base/TraceInfo.h>
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Alien
33{
34
35using namespace Arccore;
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
44{
45 // SD : clang error here, explicit ctor (VMap) in implicit ctor
46 Internal(const VBlock& blocks)
47 : m_blocks(blocks)
48 {}
49
55 UniqueArray<Integer> m_local_sizes;
57 UniqueArray<Integer> m_local_offsets;
58
65};
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
72{
73 return new VBlockImpl::Internal{ blocks };
74}
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
85
87: m_internal(Internal::newVariableSizeBlock(blocks))
88{
89 const Integer localSize = dist.localSize();
90 const Integer localOffset = dist.offset();
91 this->compute(localSize, localOffset);
92}
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
98: m_internal(Internal::newVariableSizeBlock(blocks))
99{
100 const Integer localSize = dist.localRowSize();
101 const Integer localOffset = dist.rowOffset();
102 this->compute(localSize, localOffset);
103}
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108void VBlockImpl::compute(Integer localSize, Integer localOffset)
109{
110 m_internal->m_local_sizes.resize(localSize);
111 m_internal->m_local_offsets.resize(localSize + 1);
112
113 Integer sum = 0;
114 const VBlock::ValuePerBlock& all_blocks_sizes = m_internal->m_blocks.blockSizes();
115 for (Integer i = 0; i < localSize; ++i) {
116 const Integer block_size = all_blocks_sizes.find(i + localOffset).value();
117 m_internal->m_local_sizes[i] = block_size;
118 m_internal->m_local_offsets[i] = sum;
119 m_internal->m_all_offsets[i + localOffset] = sum;
120 sum += block_size;
121 }
122 m_internal->m_local_offsets[localSize] = sum;
123
124 sum = 0;
125 for (VBlock::ValuePerBlock::const_iterator it = all_blocks_sizes.begin();
126 it != all_blocks_sizes.end(); ++it) {
127 const Integer globalIndex = it.key();
128 const Integer block_size = it.value();
129 if (m_internal->m_all_offsets.find(globalIndex) == m_internal->m_all_offsets.end())
130 m_internal->m_all_offsets[globalIndex] = sum;
131 sum += block_size;
132 }
133}
134
135/*---------------------------------------------------------------------------*/
136/*---------------------------------------------------------------------------*/
137
138Integer
140{
141 return m_internal->m_local_sizes[index];
142}
143
144/*---------------------------------------------------------------------------*/
145/*---------------------------------------------------------------------------*/
146
147Integer
148VBlockImpl::offset(Integer index) const
149{
150 auto it = m_internal->m_all_offsets.find(index);
151
152 if (it == m_internal->m_all_offsets.end())
153 throw FatalErrorException(A_FUNCINFO, "index is not registered");
154
155 return it.value();
156}
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161Integer
163{
164 return m_internal->m_local_offsets[index];
165}
166
167/*---------------------------------------------------------------------------*/
168/*---------------------------------------------------------------------------*/
169
170// TOCHECK : to remove or not
171/*
172Integer
173VBlockImpl::
174localSize() const
175{
176 return m_internal->m_local_scalarized_size;
177}
178*/
179
180/*---------------------------------------------------------------------------*/
181
182// TOCHECK : to remove or not
183/*
184Integer
185VBlockImpl::
186globalSize() const
187{
188 return m_internal->m_global_scalarized_size;
189}
190*/
191
192/*---------------------------------------------------------------------------*/
193
194// TOCHECK : to remove or not
195/*
196Integer
197VBlockImpl::
198offset() const
199{
200return m_internal->m_scalarized_offset;
201}
202*/
203
204/*---------------------------------------------------------------------------*/
205/*---------------------------------------------------------------------------*/
206
207ConstArrayView<Integer>
209{
210 return m_internal->m_local_sizes;
211}
212
213/*---------------------------------------------------------------------------*/
214/*---------------------------------------------------------------------------*/
215
216ConstArrayView<Integer>
218{
219 return m_internal->m_local_offsets;
220}
221
222/*---------------------------------------------------------------------------*/
223/*---------------------------------------------------------------------------*/
224
225std::shared_ptr<VBlockImpl>
227{
228 return std::make_shared<VBlockImpl>(*this);
229}
230
231/*---------------------------------------------------------------------------*/
232/*---------------------------------------------------------------------------*/
233
234} // namespace Alien
235
236/*---------------------------------------------------------------------------*/
237/*---------------------------------------------------------------------------*/
VBlockOffsets.h.
Computes a matrix distribution.
Arccore::Integer localRowSize() const
Get the local row size.
Arccore::Integer rowOffset() const
Get the row offset.
Arccore::ConstArrayView< Arccore::Integer > sizeOfLocalIndex() const
Get the block sizes for all local blocks.
Arccore::ConstArrayView< Arccore::Integer > offsetOfLocalIndex() const
Get the offsets for all local blocks.
Arccore::Integer offset(Arccore::Integer index) const
Get the offset from a global or local index.
Arccore::Integer offsetFromLocalIndex(Arccore::Integer index) const
Get the offset from a local index.
std::shared_ptr< VBlockImpl > clone() const
Copy this object.
void compute(Arccore::Integer local_size, Arccore::Integer local_offset)
Compute offsets for variable block size elements.
std::shared_ptr< Internal > m_internal
Actual implementation of the variable block offsets computation tool.
Arccore::Integer sizeFromLocalIndex(Arccore::Integer index) const
Get the block size from a local index.
VBlockImpl(const VBlock &block, const VectorDistribution &dist)
Constructor for vectors variable blocks.
Variable size block elements for block matrices.
Definition VBlock.h:46
VMap< Arccore::Integer, Arccore::Integer > ValuePerBlock
Type of the size of each block.
Definition VBlock.h:49
Computes a vector distribution.
Arccore::Integer offset() const
Get the offset.
Arccore::Integer localSize() const
Get the local size.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17
Internal structure for variable block offset computation tool.
VBlock::ValuePerBlock m_all_offsets
All offsets array.
const VBlock & m_blocks
Variable blocks information.
UniqueArray< Integer > m_local_sizes
Local sizes array.
static VBlockImpl::Internal * newVariableSizeBlock(const VBlock &blocks)
Compute offsets for variable block size algebraic element.
UniqueArray< Integer > m_local_offsets
Local sizes offset.