Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
BlockIndexList.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/* BlockIndexList.h (C) 2000-2025 */
9/* */
10/* Class managing an array of indices in the form of a block list. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_BLOCKINDEXLIST_H
13#define ARCANE_CORE_BLOCKINDEXLIST_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/TraceAccessor.h"
18#include "arcane/utils/UniqueArray.h"
19
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
36class ARCANE_CORE_EXPORT BlockIndex
37{
38 friend class BlockIndexList;
39
40 public:
41
42 static constexpr Int16 MAX_BLOCK_SIZE = 512;
43
44 private:
45
46 BlockIndex(const Int32* ptr, Int32 value_offset, Int16 size)
47 : m_block_start(ptr)
48 , m_value_offset(value_offset)
49 , m_size(size)
50 {}
51
52 public:
53
56 {
57 ARCANE_CHECK_AT(i, m_size);
58 return m_block_start[i] + m_value_offset;
59 }
60
62 Int16 size() const { return m_size; }
63
65 Int32 valueOffset() const { return m_value_offset; }
66
67 private:
68
69 const Int32* m_block_start = nullptr;
70 Int32 m_value_offset = 0;
71 Int16 m_size = 0;
72};
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
82class ARCANE_CORE_EXPORT BlockIndexList
83{
84 friend class BlockIndexListBuilder;
85
86 // TODO: be able to choose an allocator with accelerator support.
87
88 public:
89
90 Int32 nbBlock() const { return m_nb_block; }
91 Real memoryRatio() const;
92 void reset();
93 BlockIndex block(Int32 i) const
94 {
95 Int32 index = m_blocks_index_and_offset[i * 2];
96 Int32 offset = m_blocks_index_and_offset[(i * 2) + 1];
97 Int16 size = ((i + 1) != m_nb_block) ? m_block_size : m_last_block_size;
98 return BlockIndex(m_indexes.span().ptrAt(index), offset, size);
99 }
100 void fillArray(Array<Int32>& v);
101
102 private:
103
106 // Index in 'm_indexes' and offset for each block
107 UniqueArray<Int32> m_blocks_index_and_offset;
116
117 private:
118
119 void _setBlockIndexAndOffset(Int32 block, Int32 index, Int32 offset);
120 void _setNbBlock(Int32 nb_block);
121 Int32 _currentIndexPosition() const;
122 void _addBlockInfo(const Int32* data, Int16 size);
123 Int32 _computeNbContigusBlock() const;
124};
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
134class ARCANE_CORE_EXPORT BlockIndexListBuilder
135: public TraceAccessor
136{
137 public:
138
139 BlockIndexListBuilder(ITraceMng* tm);
140
141 public:
142
143 void setVerbose(bool v) { m_is_verbose = v; }
144
153
154 public:
155
156 void build(BlockIndexList& block_index_list, SmallSpan<const Int32> indexes, const String& name);
157
158 private:
159
160 bool m_is_verbose = false;
161 Int16 m_block_size = 32;
162
163 private:
164
165 void _throwInvalidBlockSize [[noreturn]] (Int32 block_size);
166};
167
168/*---------------------------------------------------------------------------*/
169/*---------------------------------------------------------------------------*/
170
171} // namespace Arcane
172
173/*---------------------------------------------------------------------------*/
174/*---------------------------------------------------------------------------*/
175
176#endif
Declarations of Arcane's general types.
Base class for 1D data vectors.
void setBlockSizeAsPowerOfTwo(Int32 v)
Sets the block size as a power of 2.
Class managing an array in the form of a block list.
Int16 m_block_size
Size of a block.
UniqueArray< Int32 > m_indexes
List of indexes.
Int32 m_original_size
Original size of the index array.
Int32 m_nb_block
Number of blocks (m_original_size/m_block_size rounded up).
Int16 m_last_block_size
Size of the last block.
Block containing a list of indices with an offset.
Int32 valueOffset() const
Offset of the block values.
Int16 size() const
Size of the block.
Int32 operator[](Int32 i) const
i-th value of the block
View of an array of elements of type T.
Definition Span.h:805
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int16_t Int16
Signed integer type of 16 bits.
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.