underling  0.3.2
underling.hpp
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 // underling 0.3.1: an FFTW MPI-based library for 3D pencil decompositions
3 // https://github.com/RhysU/underling
4 //
5 // Copyright (C) 2010--2013, 2026 Rhys Ulerich
6 // Copyright (C) 2012, 2013 The PECOS Development Team
7 //
8 // This file is part of underling.
9 //
10 // underling is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // underling is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with underling. If not, see <http://www.gnu.org/licenses/>.
22 //-----------------------------------------------------------------------el-
23 // $Id$
24 
25 #ifndef UNDERLING_HPP
26 #define UNDERLING_HPP
27 
28 #include <ostream>
29 #include <underling/underling.h>
30 
38 namespace underling {
39 
42 
45 
47 namespace transpose {
48 
49  enum { // Anonymous to avoid introducing an unnecessary type
50 
53 
56 
59 
62 
65 
68 
69  };
70 
71 }
72 
74 namespace transposed {
75 
76  enum { // Anonymous to avoid introducing an unnecessary type
77 
80 
83 
84  };
85 
86 }
87 
90 {
91 protected:
94 
95 private:
96  noncopyable (const noncopyable &);
97  noncopyable & operator = (const noncopyable &);
98 };
99 
104 class grid : private noncopyable {
105 public:
106 
108  grid(MPI_Comm comm, int n0, int n1, int n2, int pA = 0, int pB = 0)
109  : grid_(underling_grid_create(comm, n0, n1, n2, pA, pB))
110  {};
111 
113  template< class InputIterator1, class InputIterator2 >
114  grid(MPI_Comm comm, InputIterator1 n, InputIterator2 p)
115  : grid_(NULL)
116  {
117  const int n0 = *n++; const int n1 = *n++; const int n2 = *n;
118  const int pA = *p++; const int pB = *p;
119 
120  grid_ = underling_grid_create(comm, n0, n1, n2, pA, pB);
121  }
122 
124  template< class InputIterator >
125  grid(MPI_Comm comm, InputIterator n)
126  : grid_(NULL)
127  {
128  const int n0 = *n++; const int n1 = *n++; const int n2 = *n;
129 
130  grid_ = underling_grid_create(comm, n0, n1, n2, 0, 0);
131  }
132 
135 
137  int pA_size() const { return underling_grid_pA_size(grid_); }
138 
140  int pB_size() const { return underling_grid_pB_size(grid_); }
141 
143  underling_grid get() const { return grid_; }
144 
146  operator bool () const { return grid_ != NULL; };
147 
148 private:
149  underling_grid grid_;
150 };
151 
156 class problem : private noncopyable {
157 public:
158 
160  problem(const grid &g, int howmany, unsigned transposed_flags = 0)
161  : problem_(underling_problem_create(
162  g.get(), howmany, transposed_flags))
163  {};
164 
167 
169  underling_problem get() const { return problem_; }
170 
173  {
174  return underling_local_extents(problem_, i);
175  }
176 
178  size_t local(int i,
179  int *start = NULL,
180  int *size = NULL,
181  int *stride = NULL,
182  int *order = NULL) const
183  {
184  return underling_local(problem_, i, start, size, stride, order);
185  }
186 
188  size_t local_memory() const
189  {
190  return underling_local_memory(problem_);
191  }
192 
194  size_t local_memory_optimum() const
195  {
196  return underling_local_memory_optimum(problem_);
197  }
198 
200  operator bool () const { return problem_ != NULL; };
201 
202 private:
203  underling_problem problem_;
204 };
205 
207 inline
208 size_t local_memory_maximum(const grid &g, const problem &p)
209 {
210  return underling_local_memory_maximum(g.get(), p.get());
211 }
212 
214 inline
215 size_t local_memory_minimum(const grid &g, const problem &p)
216 {
217  return underling_local_memory_minimum(g.get(), p.get());
218 }
219 
221 inline
222 size_t global_memory(const grid &g, const problem &p)
223 {
224  return underling_global_memory(g.get(), p.get());
225 }
226 
228 inline
229 size_t global_memory_optimum(const grid &g, const problem &p)
230 {
231  return underling_global_memory_optimum(g.get(), p.get());
232 }
233 
238 class plan : private noncopyable {
239 public:
240 
242  plan(const problem &p,
243  underling_real * in,
244  underling_real * out,
245  unsigned transpose_flags = 0,
246  unsigned fftw_rigor_flags = 0)
247  : plan_(underling_plan_create(p.get(),
248  in,
249  out,
250  transpose_flags,
251  fftw_rigor_flags))
252  {}
253 
256 
258  underling_plan get() const { return plan_; }
259 
262  underling_real * out) const
263  {
264  return underling_execute_long_n2_to_long_n1(plan_, in, out);
265  }
266 
269  underling_real * out) const
270  {
271  return underling_execute_long_n1_to_long_n0(plan_, in, out);
272  }
273 
276  underling_real * out) const
277  {
278  return underling_execute_long_n0_to_long_n1(plan_, in, out);
279  }
280 
283  underling_real * out) const
284  {
285  return underling_execute_long_n1_to_long_n2(plan_, in, out);
286  }
287 
289  operator bool () const { return plan_ != NULL; };
290 
291 private:
292  underling_plan plan_;
293 };
294 
295 } // namespace underling
296 
306 template< typename charT, typename traits >
307 std::basic_ostream<charT,traits>& operator<<(
308  std::basic_ostream<charT,traits> &os,
309  const underling::extents &e)
310 {
311  return os << '['
312  << e.start[0] << ',' << (e.start[0] + e.size[0])
313  << ")x["
314  << e.start[1] << ',' << (e.start[1] + e.size[1])
315  << ")x["
316  << e.start[2] << ',' << (e.start[2] + e.size[2])
317  << ")x["
318  << e.start[3] << ',' << (e.start[3] + e.size[3])
319  << ')';
320 }
321 
323 inline
325  const underling::extents &e2) {
326  return !underling_extents_cmp(&e1, &e2);
327 }
328 
329 #endif // UNDERLING_HPP
underling::transposed::long_n0
@ long_n0
Definition: underling.hpp:82
underling_local_memory
size_t underling_local_memory(const underling_problem problem)
Find the amount of local storage necessary to plan and execute a problem.
underling::local_memory_maximum
size_t local_memory_maximum(const grid &g, const problem &p)
Definition: underling.hpp:208
underling_extents::size
int size[4]
The amount of global data stored locally in directions n{0,1,2}.
Definition: underling.h:93
underling_local
size_t underling_local(const underling_problem problem, int i, int *start, int *size, int *stride, int *order)
Obtain the processor-local sizes, storage details, and global starting offsets when the data is long ...
operator<<
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &os, const underling::extents &e)
Outputs an underling_extents or underling::extents instance as a human-readable string on any std::ba...
Definition: underling.hpp:307
underling::problem::local_memory
size_t local_memory() const
Definition: underling.hpp:188
underling::transpose::long_n0_to_long_n1
@ long_n0_to_long_n1
Definition: underling.hpp:58
underling::grid::grid
grid(MPI_Comm comm, InputIterator1 n, InputIterator2 p)
Definition: underling.hpp:114
underling_local_memory_optimum
size_t underling_local_memory_optimum(const underling_problem problem)
Find the amount of local storage necessary to merely hold a problem in memory.
underling::real
underling_real real
Definition: underling.hpp:41
underling::noncopyable
A mixin for making a subclass non-copyable via private inheritance.
Definition: underling.hpp:89
underling::problem::get
underling_problem get() const
Definition: underling.hpp:169
underling_grid_create
underling_grid underling_grid_create(MPI_Comm comm, int n0, int n1, int n2, int pA, int pB)
Collectively create a reusable domain-to-processor mapping across the given MPI communicator.
underling::problem
Provides a thin RAII wrapper for underling_problem.
Definition: underling.hpp:156
underling_plan
struct underling_plan_s * underling_plan
A type encapsulating the FFTW MPI invocations necessary to transition from being long in one directio...
Definition: underling.h:614
operator==
bool operator==(const underling::extents &e1, const underling::extents &e2)
Definition: underling.hpp:324
underling::plan::get
underling_plan get() const
Definition: underling.hpp:258
underling::local_memory_minimum
size_t local_memory_minimum(const grid &g, const problem &p)
Definition: underling.hpp:215
underling::grid::grid
grid(MPI_Comm comm, int n0, int n1, int n2, int pA=0, int pB=0)
Definition: underling.hpp:108
underling_grid_destroy
void underling_grid_destroy(underling_grid grid)
Destroy all resources associated with the given grid.
underling::problem::local
size_t local(int i, int *start=NULL, int *size=NULL, int *stride=NULL, int *order=NULL) const
Definition: underling.hpp:178
UNDERLING_TRANSPOSE_LONG_N1_TO_LONG_N0
#define UNDERLING_TRANSPOSE_LONG_N1_TO_LONG_N0
Flag indicating a transform from long in n1 to long in n0.
Definition: underling.h:562
UNDERLING_TRANSPOSE_LONG_N2_TO_LONG_N1
#define UNDERLING_TRANSPOSE_LONG_N2_TO_LONG_N1
Flag indicating a transform from long in n2 to long in n1.
Definition: underling.h:554
UNDERLING_TRANSPOSE_NONE
#define UNDERLING_TRANSPOSE_NONE
Flag indicating that no transposes will be performed.
Definition: underling.h:593
underling::transpose::long_n1_to_long_n0
@ long_n1_to_long_n0
Definition: underling.hpp:55
underling::grid
Provides a thin RAII wrapper for underling_grid.
Definition: underling.hpp:104
underling_grid_pA_size
int underling_grid_pA_size(const underling_grid grid)
Obtain the size of the processor grid in the pA direction.
UNDERLING_TRANSPOSE_LONG_N0_TO_LONG_N1
#define UNDERLING_TRANSPOSE_LONG_N0_TO_LONG_N1
Flag indicating a transform from long in n0 to long in n1.
Definition: underling.h:570
underling::transpose::all
@ all
Definition: underling.hpp:64
underling
Provides C++ wrappers for underling's C-based API.
Definition: underling.hpp:38
underling_grid
struct underling_grid_s * underling_grid
A type encapsulating a reusable domain-to-processor mapping.
Definition: underling.h:238
UNDERLING_TRANSPOSED_LONG_N0
#define UNDERLING_TRANSPOSED_LONG_N0
Flag indicating that "long in n0" storage is stored as n0 x (n1/pB x n2/pA) in row-major order.
Definition: underling.h:789
underling::transpose::long_n2_to_long_n1
@ long_n2_to_long_n1
Definition: underling.hpp:52
UNDERLING_TRANSPOSED_LONG_N2
#define UNDERLING_TRANSPOSED_LONG_N2
Flag indicating that "long in n2" storage is stored as n2 x (n0/pB x n1/pA) in row-major order.
Definition: underling.h:775
underling::noncopyable::noncopyable
noncopyable()
Definition: underling.hpp:92
underling::transpose::long_n1_to_long_n2
@ long_n1_to_long_n2
Definition: underling.hpp:61
underling_execute_long_n2_to_long_n1
int underling_execute_long_n2_to_long_n1(const underling_plan plan, underling_real *in, underling_real *out)
Collectively transform data from being long in n2 within buffer in to being long in n1 within buffer ...
UNDERLING_TRANSPOSE_LONG_N1_TO_LONG_N2
#define UNDERLING_TRANSPOSE_LONG_N1_TO_LONG_N2
Flag indicating a transform from long in n1 to long in n2.
Definition: underling.h:578
underling::grid::grid
grid(MPI_Comm comm, InputIterator n)
Definition: underling.hpp:125
underling::grid::pA_size
int pA_size() const
Definition: underling.hpp:137
underling::problem::~problem
~problem()
Definition: underling.hpp:166
underling::global_memory
size_t global_memory(const grid &g, const problem &p)
Definition: underling.hpp:222
underling::plan
Provides a thin RAII wrapper for underling_plan.
Definition: underling.hpp:238
underling_grid_pB_size
int underling_grid_pB_size(const underling_grid grid)
Obtain the size of the processor grid in the pB direction.
underling::global_memory_optimum
size_t global_memory_optimum(const grid &g, const problem &p)
Definition: underling.hpp:229
underling::plan::execute_long_n1_to_long_n2
int execute_long_n1_to_long_n2(underling_real *in, underling_real *out) const
Definition: underling.hpp:282
underling_local_memory_maximum
size_t underling_local_memory_maximum(const underling_grid grid, const underling_problem problem)
Collectively find the maximum amount of per-processor memory required to handle the problem across al...
underling::plan::execute_long_n0_to_long_n1
int execute_long_n0_to_long_n1(underling_real *in, underling_real *out) const
Definition: underling.hpp:275
underling_problem_destroy
void underling_problem_destroy(underling_problem problem)
Destroy all resources associated with the given problem.
underling::transpose::none
@ none
Definition: underling.hpp:67
underling::transposed::long_n2
@ long_n2
Definition: underling.hpp:79
underling_extents::start
int start[4]
The inclusive global data starting offset in directions n{0,1,2}.
Definition: underling.h:85
underling::noncopyable::~noncopyable
~noncopyable()
Definition: underling.hpp:93
underling_local_extents
underling_extents underling_local_extents(const underling_problem problem, int i)
Obtain the processor-local sizes, storage details, and global starting offsets when the data is long ...
UNDERLING_TRANSPOSE_ALL
#define UNDERLING_TRANSPOSE_ALL
Convenience flag indicating all transform directions.
Definition: underling.h:596
underling_local_memory_minimum
size_t underling_local_memory_minimum(const underling_grid grid, const underling_problem problem)
Collectively find the minimal amount of per-processor memory required to handle the problem across al...
underling_global_memory_optimum
size_t underling_global_memory_optimum(const underling_grid grid, const underling_problem problem)
Find the theoretical optimum (minimum) amount of memory required to store the given problem on all pr...
underling::grid::pB_size
int pB_size() const
Definition: underling.hpp:140
underling_real
double underling_real
The real-valued scalar type used throughout the library.
Definition: underling.h:63
underling_extents
A transparent type storing the local sizes, strides, and storage when the data is long in a particula...
Definition: underling.h:79
underling::plan::execute_long_n2_to_long_n1
int execute_long_n2_to_long_n1(underling_real *in, underling_real *out) const
Definition: underling.hpp:261
underling::plan::plan
plan(const problem &p, underling_real *in, underling_real *out, unsigned transpose_flags=0, unsigned fftw_rigor_flags=0)
Definition: underling.hpp:242
underling_execute_long_n0_to_long_n1
int underling_execute_long_n0_to_long_n1(const underling_plan plan, underling_real *in, underling_real *out)
Collectively transform data from being long in n0 within buffer in to being long in n1 within buffer ...
underling::grid::get
underling_grid get() const
Definition: underling.hpp:143
underling_execute_long_n1_to_long_n0
int underling_execute_long_n1_to_long_n0(const underling_plan plan, underling_real *in, underling_real *out)
Collectively transform data from being long in n1 within buffer in to being long in n0 within buffer ...
underling::problem::local_extents
underling_extents local_extents(int i) const
Definition: underling.hpp:172
underling::grid::~grid
~grid()
Definition: underling.hpp:134
underling_plan_destroy
void underling_plan_destroy(underling_plan plan)
Destroy all resources associated with the given plan.
underling::plan::~plan
~plan()
Definition: underling.hpp:255
underling.h
underling_extents_cmp
int underling_extents_cmp(const underling_extents *const e1, const underling_extents *const e2)
Compare two underling_extents instances using lexicographic ordering.
underling::plan::execute_long_n1_to_long_n0
int execute_long_n1_to_long_n0(underling_real *in, underling_real *out) const
Definition: underling.hpp:268
underling_problem
struct underling_problem_s * underling_problem
A type encapsulating all parallel decomposition information, including required local storage and str...
Definition: underling.h:352
underling_execute_long_n1_to_long_n2
int underling_execute_long_n1_to_long_n2(const underling_plan plan, underling_real *in, underling_real *out)
Collectively transform data from being long in n1 within buffer in to being long in n2 within buffer ...
underling::problem::local_memory_optimum
size_t local_memory_optimum() const
Definition: underling.hpp:194
underling_global_memory
size_t underling_global_memory(const underling_grid grid, const underling_problem problem)
Collectively find the global amount of memory required to handle the problem across all processors in...
underling::extents
underling_extents extents
Definition: underling.hpp:44
underling_problem_create
underling_problem underling_problem_create(underling_grid grid, int howmany, unsigned transposed_flags)
Collectively create an instance encapsulating the parallel decomposition details for a decomposition ...
underling::problem::problem
problem(const grid &g, int howmany, unsigned transposed_flags=0)
Definition: underling.hpp:160
underling_plan_create
underling_plan underling_plan_create(const underling_problem problem, underling_real *in, underling_real *out, unsigned transpose_flags, unsigned fftw_rigor_flags)
Collectively create an execution plan to solve the given decomposition problem using the given input ...

Generated on Wed Jul 1 2026 13:22:57 for underling by  doxygen 1.8.17