MeDiPack  1.2.2
A Message Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
displacementTools.hpp
Go to the documentation of this file.
1/*
2 * MeDiPack, a Message Differentiation Package
3 *
4 * Copyright (C) 2015-2023 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://www.scicomp.uni-kl.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of MeDiPack (http://www.scicomp.uni-kl.de/software/codi).
11 *
12 * MeDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation, either
15 * version 3 of the License, or (at your option) any later version.
16 *
17 * MeDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU Lesser General Public License for more details.
22 * You should have received a copy of the GNU
23 * Lesser General Public License along with MeDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * Authors: Max Sagebaum, Tim Albring (SciComp, University of Kaiserslautern-Landau)
27 */
28
29#pragma once
30
31
32#include "macros.h"
33
37namespace medi {
38
44
48 int* displs;
49
53 int* counts;
54
68 inline LinearDisplacements(int commSize, int length) {
69 counts = new int[commSize];
70 displs = new int[commSize];
71 for(int i = 0; i < commSize; ++i) {
72 counts[i] = length;
73 displs[i] = i * length;
74 }
75 }
76
81 delete [] displs;
82 delete [] counts;
83 }
84
90 static inline void deleteFunc(void* d) {
91 LinearDisplacements* data = reinterpret_cast<LinearDisplacements*>(d);
92
93 delete data;
94 }
95 };
96
105 inline int computeDisplacementsTotalSize(const int* counts, int ranks) {
106 int totalSize = 0;
107 for(int i = 0; i < ranks; ++i) {
108 totalSize += counts[i];
109 }
110
111 return totalSize;
112 }
113
122 inline int* createLinearDisplacements(const int* counts, int ranks) {
123 int* displs = new int[ranks];
124
125 displs[0] = 0;
126 for(int i = 1; i < ranks; ++i) {
127 displs[i] = counts[i - 1] + displs[i - 1];
128 }
129
130 return displs;
131 }
132
144 inline void createLinearDisplacementsAndCount(int* &countsOut, int* &displsOut, const int* counts, int ranks, int scale) {
145 displsOut = new int[ranks];
146 countsOut = new int[ranks];
147
148 countsOut[0] = counts[0] * scale;
149 displsOut[0] = 0;
150 for(int i = 1; i < ranks; ++i) {
151 countsOut[i] = counts[i] * scale;
152 displsOut[i] = countsOut[i - 1] + displsOut[i - 1];
153 }
154 }
155
169 template<typename Datatype>
170 inline void createLinearIndexCounts(int* &linearCounts, const int* counts, const int* displs, int ranks, Datatype* type) {
171 linearCounts = new int[ranks];
172
173 linearCounts[0] = type->computeActiveElements(displs[0] + counts[0]);
174 int lastSum = linearCounts[0];
175 for(int i = 1; i < ranks; ++i) {
176 int curSum = type->computeActiveElements(displs[i] + counts[i]);
177 linearCounts[i] = curSum - lastSum;
178 lastSum = curSum;
179 }
180 }
181}
Global namespace for MeDiPack - Message Differentiation Package.
Definition: adjointInterface.hpp:37
int computeDisplacementsTotalSize(const int *counts, int ranks)
Compute the total size of a message that has a different size on each rank.
Definition: displacementTools.hpp:105
int * createLinearDisplacements(const int *counts, int ranks)
Creates the linearized displacements of a message with a different size on each rank.
Definition: displacementTools.hpp:122
void createLinearDisplacementsAndCount(int *&countsOut, int *&displsOut, const int *counts, int ranks, int scale)
Creates the linearized displacements of a message with a different size on each rank.
Definition: displacementTools.hpp:144
void createLinearIndexCounts(int *&linearCounts, const int *counts, const int *displs, int ranks, Datatype *type)
Creates the counts for a message with a different size on each rank.
Definition: displacementTools.hpp:170
Helper structure for the easy creation of a linear displacement with a the same length.
Definition: displacementTools.hpp:43
int * displs
The array with the displacements.
Definition: displacementTools.hpp:48
int * counts
The array with the counts.
Definition: displacementTools.hpp:53
LinearDisplacements(int commSize, int length)
Create displacemnts where each displacement has the size length.
Definition: displacementTools.hpp:68
~LinearDisplacements()
Destroy the structure.
Definition: displacementTools.hpp:80
static void deleteFunc(void *d)
Helper function for deleting a LinearDisplacements structure.
Definition: displacementTools.hpp:90