Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
VBlock.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 "VBlock.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{
49
57 ValuePerBlock&& all_sizes, Integer max_block_size);
58
66 const ValuePerBlock& all_sizes, Integer max_block_size);
67};
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
73VBlock::Internal::newVariableSizeBlock(ValuePerBlock&& all_sizes, Integer max_block_size)
74{
75 return new VBlock::Internal{ std::move(all_sizes), max_block_size };
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
83const ValuePerBlock& all_sizes, Integer max_block_size)
84{
85 return new VBlock::Internal{ all_sizes, max_block_size };
86}
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
93{}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
98VBlock::VBlock(ValuePerBlock&& all_blocks_sizes)
99{
100 Integer max_block_size = 0;
101 for (auto it = all_blocks_sizes.begin(); it != all_blocks_sizes.end(); ++it) {
102 const Integer block_size = it.value();
103 max_block_size = (max_block_size > block_size) ? max_block_size : block_size;
104 }
105 m_internal.reset(
106 Internal::newVariableSizeBlock(std::move(all_blocks_sizes), max_block_size));
107
108 // TOCHECK: Debug info to remove or not ?
109 /*
110 if(parallel_mng->commRank()==0)
111 {
112 std::cout << "Blocks in VBlock:\n";
113 std::cout << "m_local_scalarized_size: " << m_internal->m_local_scalarized_size <<
114 "\n"; std::cout << "m_global_scalarized_size: " <<
115 m_internal->m_global_scalarized_size << "\n"; std::cout << "m_scalarized_offset: " <<
116 m_internal->m_scalarized_offset << "\n"; std::cout << "m_max_block_size: " <<
117 m_internal->m_max_block_size << "\n"; std::cout << "m_local_sizes.size(): " <<
118 m_internal->m_local_sizes.size() << "\n"; std::cout << "m_local_offsets.size(): " <<
119 m_internal->m_local_offsets.size() << "\n"; std::cout << "m_all_sizes.size(): " <<
120 m_internal->m_all_sizes.size() << "\n"; std::cout << "m_all_offsets.size(): " <<
121 m_internal->m_all_offsets.size() << "\n"; std::cout << "m_local_sizes: \n";
122 for(Integer i=0;i<m_internal->m_local_sizes.size();++i)
123 std::cout << m_internal->m_local_sizes[i] << "\n";
124 std::cout << "m_local_offsets: \n";
125 for(Integer i=0;i<m_internal->m_local_offsets.size();++i)
126 std::cout << m_internal->m_local_offsets[i] << "\n";
127 std::cout << "m_all_sizes: \n";
128 for(ValuePerBlock::const_iterator it = m_internal->m_all_sizes.begin(); it !=
129 m_internal->m_all_sizes.end(); ++it)
130 {
131 std::cout << "index: " << it.key() << " value: " << it.value() << "\n";
132 }
133 std::cout << "m_all_offsets: \n";
134 for(ValuePerBlock::const_iterator it = m_internal->m_all_offsets.begin(); it !=
135 m_internal->m_all_offsets.end(); ++it)
136 {
137 std::cout << "index: " << it.key() << " value: " << it.value() << "\n";
138 }
139 }
140 */
141}
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
146VBlock::VBlock(const ValuePerBlock& all_blocks_sizes)
147{
148 Integer max_block_size = 0;
149 for (ValuePerBlock::const_iterator it = all_blocks_sizes.begin();
150 it != all_blocks_sizes.end(); ++it) {
151 const Integer block_size = it.value();
152 max_block_size = (max_block_size > block_size) ? max_block_size : block_size;
153 }
154 m_internal.reset(
155 Internal::newVariableSizeBlock(std::move(all_blocks_sizes), max_block_size));
156}
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161Integer
162VBlock::size(Integer index) const
163{
164 auto it = m_internal->m_all_sizes.find(index);
165
166 if (it == m_internal->m_all_sizes.end())
167 throw FatalErrorException(A_FUNCINFO, "index is not registered");
168 return it.value();
169}
170
171/*---------------------------------------------------------------------------*/
172/*---------------------------------------------------------------------------*/
173
174Integer
176{
177 return m_internal->m_max_block_size;
178}
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
183std::shared_ptr<VBlock>
185{
186 return std::make_shared<VBlock>(*this);
187}
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
191
194{
195 return m_internal->m_all_sizes;
196}
197
198/*---------------------------------------------------------------------------*/
199/*---------------------------------------------------------------------------*/
200
201} // namespace Alien
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
VBlock.h.
const ValuePerBlock & blockSizes() const
Get the size of all blocks.
Definition VBlock.cc:193
std::shared_ptr< Internal > m_internal
Actual implementation of variable blocks size.
Definition VBlock.h:106
Arccore::Integer maxBlockSize() const
Get the max size of all block size.
Definition VBlock.cc:175
VBlock(ValuePerBlock &&all_blocks_sizes)
Rvalue constructor.
Definition VBlock.cc:98
VMap< Arccore::Integer, Arccore::Integer > ValuePerBlock
Type of the size of each block.
Definition VBlock.h:49
std::shared_ptr< VBlock > clone() const
Copy this object.
Definition VBlock.cc:184
Arccore::Integer size(Arccore::Integer index) const
Get the size of a block.
Definition VBlock.cc:162
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17
Actual implementation of variable blocks size.
Definition VBlock.cc:44
ValuePerBlock m_all_sizes
Size for all blocks.
Definition VBlock.cc:46
static VBlock::Internal * newVariableSizeBlock(ValuePerBlock &&all_sizes, Integer max_block_size)
Creates a new variable block size element.
Definition VBlock.cc:73
Integer m_max_block_size
Maximum size amongst all blocks.
Definition VBlock.cc:48