QuIDS: Quantum Irregular Dynamic Simulator
mpi_utils.hpp
1#pragma once
2
3#include <mpi.h>
4
7
9 void make_equal_pairs(size_t *size_begin, size_t *size_end, int *pair_id) {
10 size_t size = std::distance(size_begin, size_end);
11
12 std::vector<int> node_ids(size, 0);
13 std::iota(node_ids.begin(), node_ids.begin() + size, 0);
14
15 /* compute average value */
16 __gnu_parallel::sort(node_ids.begin(), node_ids.begin() + size,
17 [&](int const node_id1, int const node_id2) {
18 return size_begin[node_id1] > size_begin[node_id2];
19 });
20
21 #pragma omp parallel for
22 for (int i = 0; i < size; ++i)
23 pair_id[node_ids[i]] = node_ids[size - i - 1];
24 }
25
27
32 template<typename T>
33 MPI_Datatype get_mpi_datatype(T x) { return NULL; }
34 MPI_Datatype get_mpi_datatype(float x) { return MPI_FLOAT; }
35 MPI_Datatype get_mpi_datatype(double x) { return MPI_DOUBLE; }
36 MPI_Datatype get_mpi_datatype(long double x) { return MPI_LONG_DOUBLE; }
37 MPI_Datatype get_mpi_datatype(std::complex<float> x) { return MPI_COMPLEX; }
38 MPI_Datatype get_mpi_datatype(std::complex<double> x) { return MPI_DOUBLE_COMPLEX; }
39 MPI_Datatype get_mpi_datatype(std::complex<long double> x) { return MPI_C_LONG_DOUBLE_COMPLEX; }
40 MPI_Datatype get_mpi_datatype(bool x) { return MPI_CHAR; }
41 MPI_Datatype get_mpi_datatype(char x) { return MPI_CHAR; }
42 MPI_Datatype get_mpi_datatype(signed char x) { return MPI_SIGNED_CHAR; }
43 MPI_Datatype get_mpi_datatype(unsigned char x) { return MPI_UNSIGNED_CHAR; }
44 MPI_Datatype get_mpi_datatype(short x) { return MPI_SHORT; }
45 MPI_Datatype get_mpi_datatype(unsigned short x) { return MPI_UNSIGNED_SHORT; }
46 MPI_Datatype get_mpi_datatype(int x) { return MPI_INT; }
47 MPI_Datatype get_mpi_datatype(unsigned int x) { return MPI_UNSIGNED; }
48 MPI_Datatype get_mpi_datatype(long x) { return MPI_LONG; }
49 MPI_Datatype get_mpi_datatype(unsigned long x) { return MPI_UNSIGNED_LONG; }
50}
QuIDS mpi utility function and variable namespace.
Definition: mpi_utils.hpp:6
void make_equal_pairs(size_t *size_begin, size_t *size_end, int *pair_id)
function to partition into pair of almost equal sum
Definition: mpi_utils.hpp:9
MPI_Datatype get_mpi_datatype(T x)
function to get the corresponding MPI type of a variable
Definition: mpi_utils.hpp:33