Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
ComputeBlockOffsets.h
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#ifndef ALIEN_CORE_BLOCK_COMPUTEBLOCKOFFSETS_H
25#define ALIEN_CORE_BLOCK_COMPUTEBLOCKOFFSETS_H
26
27#include <vector>
28
30#include <alien/utils/Precomp.h>
31
34#include <arccore/message_passing/IMessagePassingMng.h>
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39namespace Alien
40{
41
42namespace IFPEN
43{
44 class BlockVector;
45}
46
47/*---------------------------------------------------------------------------*/
48/*---------------------------------------------------------------------------*/
49
57template <typename T = std::vector<std::size_t>>
58void computeBlockOffsets(const VectorDistribution& dist, const Block& block, T& offsets)
59{
60 IMessagePassingMng* parallel_mng = dist.parallelMng();
61 const Integer block_size = block.size();
62 if (parallel_mng && parallel_mng->commSize() > 1) {
63 const Integer nproc = parallel_mng->commSize();
64 offsets.resize(nproc + 1);
65 for (Integer i = 0; i < nproc; ++i)
66 offsets[i] = dist.offset(i) * block_size;
67 offsets[nproc] = dist.globalSize() * block_size;
68 }
69 else {
70 offsets.resize(2);
71 offsets[0] = 0;
72 offsets[1] = dist.globalSize() * block_size;
73 }
74}
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
86template <typename T = std::vector<std::size_t>>
87void computeBlockOffsets(const MatrixDistribution& dist, const Block& block, T& offsets)
88{
89 IMessagePassingMng* parallel_mng = dist.parallelMng();
90 const Integer block_size = block.size();
91 if (parallel_mng && parallel_mng->commSize() > 1) {
92 const Integer nproc = parallel_mng->commSize();
93 offsets.resize(nproc + 1);
94 for (Integer i = 0; i < nproc; ++i)
95 offsets[i] = dist.rowOffset(i) * block_size;
96 offsets[nproc] = dist.globalRowSize() * block_size;
97 }
98 else {
99 offsets.resize(2);
100 offsets[0] = 0;
101 offsets[1] = dist.globalRowSize() * block_size;
102 }
103}
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108} // namespace Alien
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113#endif /* ALIEN_CORE_BLOCK_COMPUTEBLOCKOFFSETS_H */
Block.h.
MatrixDistribution.h.
VectorDistribution.h.
Block elements for block matrices.
Definition Block.h:45
Arccore::Integer size() const
Get square block size.
Definition Block.cc:90
Computes a matrix distribution.
Arccore::Integer globalRowSize() const
Get the global row size.
Arccore::Integer rowOffset() const
Get the row offset.
Arccore::MessagePassing::IMessagePassingMng * parallelMng() const
Get the parallel manager.
Computes a vector distribution.
Arccore::Integer offset() const
Get the offset.
Arccore::Integer globalSize() const
Get the global 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
void computeBlockOffsets(const VectorDistribution &dist, const Block &block, T &offsets)
Compute block offsets for an uniform block vector.