28#include "heffte_config.h"
36template<
class T,
class U = T>
39 T old_value = std::move(obj);
40 obj = std::forward<U>(new_value);
81 MPI_Comm_rank(comm, &me);
117template<
typename vector_like>
118void dump(
int me, vector_like
const &x, std::string
const &message){
120 std::cout << message <<
"\n";
121 for(
auto i : x) std::cout << i <<
" ";
122 std::cout << std::endl;
138 MPI_Comm_size(comm, &nprocs);
153 MPI_Group orig_group, new_group;
154 MPI_Comm_group(comm, &orig_group);
155 MPI_Group_incl(orig_group, (
int) ranks.size(), ranks.data(), &new_group);
157 MPI_Comm_create(comm, new_group, &result);
158 MPI_Group_free(&orig_group);
159 MPI_Group_free(&new_group);
176 if (MPI_Comm_free(
const_cast<MPI_Comm*
>(&comm)) != MPI_SUCCESS)
177 throw std::runtime_error(
"Could not free a communicator.");
190template<
typename scalar>
inline MPI_Datatype
type_from(){
193 static_assert(!std::is_same<scalar, scalar>::value,
"The C++ type has unknown MPI equivalent.");
252template<
typename scalar_type>
struct is_ccomplex : std::false_type{};
270template<
typename scalar_type>
struct is_zcomplex : std::false_type{};
276template<>
struct is_ccomplex<std::complex<float>> : std::true_type{};
281template<>
struct is_zcomplex<std::complex<double>> : std::true_type{};
340 using type = std::complex<float>;
348 using type = std::complex<double>;
354template<
typename scalar_type>
362template<
typename scalar_type>
380template<
typename some_
class>
383 for(
int i=0; i<4; i++)
if (shaper[i]) last = i;
391template<
typename some_
class>
392int count_active(std::array<std::unique_ptr<some_class>, 4>
const &shaper){
394 for(
int i=0; i<4; i++)
if (shaper[i]) num++;
402template<
typename some_
class>
404 size_t max_size = (executors[0]) ? executors[0]->box_size() : 0;
405 max_size = std::max(max_size, (executors[1]) ? executors[1]->box_size() :
static_cast<size_t>(0));
406 return std::max(max_size, (executors[2]) ? executors[2]->box_size() :
static_cast<size_t>(0));
413template<
typename some_
class>
415 size_t max_size = (executors[0]) ? executors[0]->complex_size() : 0;
416 max_size = std::max(max_size, (executors[1]) ? executors[1]->box_size() :
static_cast<size_t>(0));
417 return std::max(max_size, (executors[2]) ? executors[2]->box_size() :
static_cast<size_t>(0));
423template<
typename some_
class>
425 size_t max_size = (executors[0]) ? executors[0]->workspace_size() : 0;
426 max_size = std::max(max_size, (executors[1]) ? executors[1]->workspace_size() :
static_cast<size_t>(0));
427 return std::max(max_size, (executors[2]) ? executors[2]->workspace_size() :
static_cast<size_t>(0));
434template<
typename some_
class_r2c,
typename some_
class>
435size_t get_max_work_size(some_class_r2c
const &executors_r2c, std::array<some_class, 2>
const &executors){
436 return std::max(executors_r2c->workspace_size(), std::max(executors[0]->workspace_size(), executors[1]->workspace_size()));
T c11_exchange(T &obj, U &&new_value)
Replace with the C++ 2014 std::exchange later.
Definition heffte_utils.h:37
int get_last_active(std::array< std::unique_ptr< some_class >, 4 > const &shaper)
Return the index of the last active (non-null) unique_ptr.
Definition heffte_utils.h:381
size_t get_max_box_size_r2c(std::array< some_class, 3 > const &executors)
Returns the max of the box_size() for each of the executors.
Definition heffte_utils.h:414
size_t get_max_box_size(std::array< some_class, 3 > const &executors)
Returns the max of the box_size() for each of the executors.
Definition heffte_utils.h:403
int count_active(std::array< std::unique_ptr< some_class >, 4 > const &shaper)
Return the number of active (non-null) unique_ptr.
Definition heffte_utils.h:392
size_t get_max_work_size(std::array< some_class, 3 > const &executors)
Returns the max of the workspace_size() for each of the executors.
Definition heffte_utils.h:424
MPI_Datatype type_from< float >()
Specialization to hand the float type.
Definition heffte_utils.h:205
MPI_Datatype type_from< int >()
Specialization to hand the int type.
Definition heffte_utils.h:200
int comm_rank(MPI_Comm const comm)
Returns the rank of this process within the specified comm.
Definition heffte_utils.h:79
void comm_free(MPI_Comm const comm)
Calls free on the MPI comm.
Definition heffte_utils.h:175
int comm_size(MPI_Comm const comm)
Returns the size of the specified communicator.
Definition heffte_utils.h:136
MPI_Datatype type_from< double >()
Specialization to hand the double type.
Definition heffte_utils.h:210
void dump(int me, vector_like const &x, std::string const &message)
Write the message and the data from the vector-like x, performed only on rank me (if positive),...
Definition heffte_utils.h:118
MPI_Datatype type_from()
Returns the MPI equivalent of the scalar C++ type.
Definition heffte_utils.h:190
MPI_Comm new_comm_from_group(std::vector< int > const &ranks, MPI_Comm const comm)
Creates a new sub-communicator from the provided processes in comm.
Definition heffte_utils.h:152
int world_rank()
Returns the rank of this process within the MPI_COMM_WORLD (useful for debugging).
Definition heffte_utils.h:105
Namespace containing all HeFFTe methods and classes.
Definition heffte_backend_cuda.h:38
define_standard_type< scalar_type >::type * convert_to_standard(scalar_type input[])
Converts an array of some type to an array of the C++ equivalent type.
Definition heffte_utils.h:355
double type
Double is equivalent to double.
Definition heffte_utils.h:331
float type
Float is equivalent to float.
Definition heffte_utils.h:323
std::complex< double > type
If heffte::is_ccomplex is true_type, then the type is equivalent to std::complex<double>.
Definition heffte_utils.h:348
std::complex< float > type
If heffte::is_ccomplex is true_type, then the type is equivalent to std::complex<float>.
Definition heffte_utils.h:340
Struct to specialize that returns the C++ equivalent of each type.
Definition heffte_utils.h:315
Struct to specialize to allow HeFFTe to recognize custom single precision complex types.
Definition heffte_utils.h:252
Struct to specialize to allow HeFFTe to recognize custom double precision complex types.
Definition heffte_utils.h:270