Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
VBlockSizes.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 "VBlockSizes.h"
25
26#include <arccore/message_passing/Messages.h>
27#include <cstdlib>
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Alien
33{
34
35using namespace Arccore;
36using namespace Arccore::MessagePassing;
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
42{
43 const Integer localSize = dist.localSize();
44 const Integer localOffset = dist.offset();
45 this->compute(blocks.blockSizes(), localSize, localOffset, dist.parallelMng());
46}
47
48/*---------------------------------------------------------------------------*/
49/*---------------------------------------------------------------------------*/
50
52{
53 const Integer localSize = dist.localRowSize();
54 const Integer localOffset = dist.rowOffset();
55 this->compute(blocks.blockSizes(), localSize, localOffset, dist.parallelMng());
56}
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
61void VBlockSizes::compute(const VBlock::ValuePerBlock& all_blocks_sizes, Integer localSize,
62 Integer localOffset, IMessagePassingMng* parallel_mng)
63{
65 for (Integer i = 0; i < localSize; ++i) {
66 const Integer block_size = all_blocks_sizes.find(i + localOffset).value();
67 m_local_scalarized_size += block_size;
68 }
69
72 const bool is_parallel = (parallel_mng != NULL) && (parallel_mng->commSize() > 1);
73 if (is_parallel) {
74 m_global_scalarized_size = Arccore::MessagePassing::mpAllReduce(
75 parallel_mng, Arccore::MessagePassing::ReduceSum, m_local_scalarized_size);
76 Arccore::UniqueArray<Arccore::Integer> local_sizes(parallel_mng->commSize());
77 Arccore::MessagePassing::mpAllGather(parallel_mng,
78 Alien::ArrayView<Integer>(1, &m_local_scalarized_size), local_sizes);
79 for (Integer i = 0; i < parallel_mng->commRank(); ++i)
80 m_scalarized_offset += local_sizes[i];
81 }
82 else {
84 }
85}
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90Integer
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99Integer
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108Integer
110{
111 return m_scalarized_offset;
112}
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
117} // namespace Alien
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
VBlockSizes.h.
Computes a matrix distribution.
Arccore::Integer localRowSize() const
Get the local row size.
Arccore::Integer rowOffset() const
Get the row offset.
Arccore::MessagePassing::IMessagePassingMng * parallelMng() const
Get the parallel manager.
Arccore::Integer m_local_scalarized_size
Scalarized local size.
Arccore::Integer offset() const
Get the "scalarized" offset.
void compute(const VBlock::ValuePerBlock &all_blocks_sizes, Arccore::Integer local_size, Arccore::Integer local_offset, Arccore::MessagePassing::IMessagePassingMng *parallel_mng)
Compute the actual sizes and offset of variable block size algebraic elements.
Arccore::Integer m_global_scalarized_size
Scalarized global size.
Arccore::Integer m_scalarized_offset
Scalarized offset.
VBlockSizes(const VBlock &block, const VectorDistribution &dist)
Constructor for vectors variable blocks.
Arccore::Integer globalSize() const
Get the "scalarized" global size.
Arccore::Integer localSize() const
Get the "scalarized" local size.
Variable size block elements for block matrices.
Definition VBlock.h:46
const ValuePerBlock & blockSizes() const
Get the size of all blocks.
Definition VBlock.cc:193
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.
Arccore::MessagePassing::IMessagePassingMng * parallelMng() const
Get the parallel manager.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17