Block-Structured AMR Software Framework
distribution_c.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017, UChicago Argonne, LLC
3  * All Rights Reserved
4  *
5  * Hardware/Hybrid Cosmology Code (HACC), Version 1.0
6  *
7  * Salman Habib, Adrian Pope, Hal Finkel, Nicholas Frontiere, Katrin Heitmann,
8  * Vitali Morozov, Jeffrey Emberson, Thomas Uram, Esteban Rangel
9  * (Argonne National Laboratory)
10  *
11  * David Daniel, Patricia Fasel, Chung-Hsing Hsu, Zarija Lukic, James Ahrens
12  * (Los Alamos National Laboratory)
13  *
14  * George Zagaris
15  * (Kitware)
16  *
17  * OPEN SOURCE LICENSE
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are met:
21  *
22  * 1. Redistributions of source code must retain the above copyright notice,
23  * this list of conditions and the following disclaimer. Software changes,
24  * modifications, or derivative works, should be noted with comments and
25  * the author and organization's name.
26  *
27  * 2. Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  *
31  * 3. Neither the names of UChicago Argonne, LLC or the Department of Energy
32  * nor the names of its contributors may be used to endorse or promote
33  * products derived from this software without specific prior written
34  * permission.
35  *
36  * 4. The software and the end-user documentation included with the
37  * redistribution, if any, must include the following acknowledgment:
38  *
39  * "This product includes software produced by UChicago Argonne, LLC under
40  * Contract No. DE-AC02-06CH11357 with the Department of Energy."
41  *
42  * *****************************************************************************
43  * DISCLAIMER
44  * THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY OF ANY KIND. NEITHER THE
45  * UNITED STATES GOVERNMENT, NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR
46  * UCHICAGO ARGONNE, LLC, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY,
47  * EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE
48  * ACCURARY, COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, DATA, APPARATUS,
49  * PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE
50  * PRIVATELY OWNED RIGHTS.
51  *
52  * *****************************************************************************
53  */
54 
55 #ifndef HACC_DISTRIBUTION_H
56 #define HACC_DISTRIBUTION_H
57 
58 #include <mpi.h>
59 
60 #include "complex-type.h"
61 
62 #define PENCIL 1
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
69 // descriptor for a process grid
70 // cart Cartesian MPI communicator
71 // nproc[] dimensions of process grid
72 // period[] periods of process grid
73 // self[] coordinate of this process in the process grid
74 // n[] local grid dimensions
76 typedef struct {
78  int nproc[3];
79  int period[3];
80  int self[3];
81  int n[3];
83 
84 
86 // descriptor for data distribution
87 // debug toggle debug output
88 // n[3] (global) grid dimensions
89 // process_topology_1 1-d process topology
90 // process_topology_2 2-d process topology
91 // process_topology_3 3-d process topology
93 typedef struct {
94  bool debug;
95  int n[3];
103  int *gridmap;
104  int *rankmap;
107 
108 
110 // create 1-, 2- and 3-d cartesian data distributions
111 // comm MPI Communicator
112 // d distribution descriptor
113 // n (global) grid dimensions (3 element array)
114 // Ndims 3d process grid (3 element array: x, y, z)
115 // rmap pointer to grid->rank map
116 // debug debugging output
118 void distribution_init(MPI_Comm comm,
119  const int n[],
120  const int Ndims[],
121  distribution_t *d,
122  const int* rmap,
123  bool debug);
124 
125 
127 // create 1-, 2- and 3-d cartesian data distributions with explicitly
128 // provided dimension lists
129 // comm MPI Communicator
130 // n (global) grid dimensions (3 element array)
131 // nproc_1d 1d process grid (3 element array: x, 1, 1)
132 // nproc_2d 1d process grid (3 element array: x, y, 1)
133 // nproc_3d 3d process grid (3 element array: x, y, z)
134 // d distribution descriptor
135 // debug debugging output
138  const int n[],
139  int nproc_1d[],
140  int nproc_2d_x[],
141  int nproc_2d_y[],
142  int nproc_2d_z[],
143  int nproc_3d[],
144  distribution_t *d,
145  bool debug);
146 
148 // creates a custom 3D decomposition or uses MPI_Dims_create to do so
150 void Custom3D_Dims_create(const int Ndims[], int nproc, int ndims, int dims[]);
151 
152 
154 // clean up the data distribution
155 // d distribution descriptor
158 
159 
161 // assert that the data and processor grids are commensurate
162 // d distribution descriptor
165 
166 
168 // redistribute a 1-d to a 3-d data distribution
169 // a input
170 // b ouput
171 // d distribution descriptor
173 void distribution_1_to_3(const complex_t *a,
174  complex_t *b,
175  distribution_t *d);
176 
178 // redistribute a 3-d to a 1-d data distribution
179 // a input
180 // b ouput
181 // d distribution descriptor
183 void distribution_3_to_1(const complex_t *a,
184  complex_t *b,
185  distribution_t *d);
186 
188 // redistribute a 2-d to a 3-d data distribution
189 // a input
190 // b ouput
191 // d distribution descriptor
193 void distribution_2_to_3(const complex_t *a,
194  complex_t *b,
195  distribution_t *d,
196  int dim_z);
197 
199 // redistribute a 3-d to a 2-d data distribution
200 // a input
201 // b ouput
202 // d distribution descriptor
204 void distribution_3_to_2(const complex_t *a,
205  complex_t *b,
206  distribution_t *d,
207  int dim_z);
208 
209 
211 // Some accessor functions
213 static inline int distribution_get_nproc_1d(distribution_t *d, int direction)
214 {
215  return d->process_topology_1.nproc[direction];
216 }
217 
218 static inline int distribution_get_nproc_2d_x(distribution_t *d, int direction)
219 {
220  return d->process_topology_2_x.nproc[direction];
221 }
222 static inline int distribution_get_nproc_2d_y(distribution_t *d, int direction)
223 {
224  return d->process_topology_2_y.nproc[direction];
225 }
226 static inline int distribution_get_nproc_2d_z(distribution_t *d, int direction)
227 {
228  return d->process_topology_2_z.nproc[direction];
229 }
230 
231 static inline int distribution_get_nproc_3d(distribution_t *d, int direction)
232 {
233  return d->process_topology_3.nproc[direction];
234 }
235 
236 static inline int distribution_get_self_1d(distribution_t *d, int direction)
237 {
238  return d->process_topology_1.self[direction];
239 }
240 
241 static inline int distribution_get_self_2d_x(distribution_t *d, int direction)
242 {
243  return d->process_topology_2_x.self[direction];
244 }
245 static inline int distribution_get_self_2d_y(distribution_t *d, int direction)
246 {
247  return d->process_topology_2_y.self[direction];
248 }
249 static inline int distribution_get_self_2d_z(distribution_t *d, int direction)
250 {
251  return d->process_topology_2_z.self[direction];
252 }
253 static inline int distribution_get_self_3d(distribution_t *d, int direction)
254 {
255  return d->process_topology_3.self[direction];
256 }
257 
258 void Coord_x_pencils(int myrank, int coord[], distribution_t *d);
259 void Rank_x_pencils(int * myrank, int coord[], distribution_t *d);
260 void Coord_y_pencils(int myrank, int coord[], distribution_t *d);
261 void Rank_y_pencils(int * myrank, int coord[], distribution_t *d);
262 void Coord_z_pencils(int myrank, int coord[], distribution_t *d);
263 void Rank_z_pencils(int * myrank, int coord[], distribution_t *d);
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 #endif // HACC_DISTRIBUTION_H
int MPI_Comm
Definition: AMReX_ccse-mpi.H:47
double complex complex_t
Definition: complex-type.h:79
void Rank_x_pencils(int *myrank, int coord[], distribution_t *d)
Definition: distribution.c:150
void distribution_3_to_1(const complex_t *a, complex_t *b, distribution_t *d)
Definition: distribution.c:1287
static int distribution_get_self_2d_x(distribution_t *d, int direction)
Definition: distribution_c.h:241
void distribution_assert_commensurate(distribution_t *d)
Definition: distribution.c:1242
static int distribution_get_nproc_2d_y(distribution_t *d, int direction)
Definition: distribution_c.h:222
static int distribution_get_nproc_1d(distribution_t *d, int direction)
Definition: distribution_c.h:213
void distribution_fini(distribution_t *d)
Definition: distribution.c:1222
static int distribution_get_nproc_2d_z(distribution_t *d, int direction)
Definition: distribution_c.h:226
static int distribution_get_nproc_2d_x(distribution_t *d, int direction)
Definition: distribution_c.h:218
void Coord_y_pencils(int myrank, int coord[], distribution_t *d)
Definition: distribution.c:171
static int distribution_get_self_2d_z(distribution_t *d, int direction)
Definition: distribution_c.h:249
static int distribution_get_self_3d(distribution_t *d, int direction)
Definition: distribution_c.h:253
void Rank_y_pencils(int *myrank, int coord[], distribution_t *d)
Definition: distribution.c:189
static int distribution_get_nproc_3d(distribution_t *d, int direction)
Definition: distribution_c.h:231
void distribution_1_to_3(const complex_t *a, complex_t *b, distribution_t *d)
Definition: distribution.c:1269
static int distribution_get_self_1d(distribution_t *d, int direction)
Definition: distribution_c.h:236
void Coord_z_pencils(int myrank, int coord[], distribution_t *d)
Definition: distribution.c:206
static int distribution_get_self_2d_y(distribution_t *d, int direction)
Definition: distribution_c.h:245
void distribution_3_to_2(const complex_t *a, complex_t *b, distribution_t *d, int dim_z)
Definition: distribution.c:1509
void Rank_z_pencils(int *myrank, int coord[], distribution_t *d)
Definition: distribution.c:224
void distribution_init(MPI_Comm comm, const int n[], const int Ndims[], distribution_t *d, const int *rmap, bool debug)
Definition: distribution.c:248
void Custom3D_Dims_create(const int Ndims[], int nproc, int ndims, int dims[])
Definition: distribution.c:990
void Coord_x_pencils(int myrank, int coord[], distribution_t *d)
Definition: distribution.c:117
void distribution_init_explicit(MPI_Comm comm, const int n[], int nproc_1d[], int nproc_2d_x[], int nproc_2d_y[], int nproc_2d_z[], int nproc_3d[], distribution_t *d, bool debug)
Definition: distribution.c:1007
void distribution_2_to_3(const complex_t *a, complex_t *b, distribution_t *d, int dim_z)
Definition: distribution.c:1495
Definition: distribution_c.h:93
process_topology_t process_topology_2_y
Definition: distribution_c.h:98
process_topology_t process_topology_1
Definition: distribution_c.h:96
process_topology_t process_topology_2_z
Definition: distribution_c.h:97
int * rankmap
Definition: distribution_c.h:104
MPI_Comm parent
Definition: distribution_c.h:105
bool debug
Definition: distribution_c.h:94
complex_t * d2_chunk
Definition: distribution_c.h:101
complex_t * d3_chunk
Definition: distribution_c.h:102
int * gridmap
Definition: distribution_c.h:103
process_topology_t process_topology_3
Definition: distribution_c.h:100
process_topology_t process_topology_2_x
Definition: distribution_c.h:99
Definition: distribution_c.h:76
int self[3]
Definition: distribution_c.h:80
int nproc[3]
Definition: distribution_c.h:78
MPI_Comm cart
Definition: distribution_c.h:77