COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
dtypes.h
Go to the documentation of this file.
1#ifndef __DTYPES_H_
2#define __DTYPES_H_
3
4#include <mpi.h>
5#include <complex>
6
18namespace par {
19
28 template <typename T>
29 class Mpi_datatype;
30
31 template <typename T1, typename T2>
32 class Mpi_pairtype;
33
34#define HS_MPIDATATYPE(CTYPE, MPITYPE) \
35 template <> \
36 class Mpi_datatype<CTYPE> \
37 { \
38 public: \
39 static MPI_Datatype value() {\
40 return MPITYPE;\
41 } \
42 };
43
44 HS_MPIDATATYPE(short, MPI_SHORT)
45 HS_MPIDATATYPE(int, MPI_INT)
46 HS_MPIDATATYPE(long, MPI_LONG)
47 HS_MPIDATATYPE(unsigned short, MPI_UNSIGNED_SHORT)
48 HS_MPIDATATYPE(unsigned int, MPI_UNSIGNED)
49 HS_MPIDATATYPE(unsigned long, MPI_UNSIGNED_LONG)
50 HS_MPIDATATYPE(float, MPI_FLOAT)
51 HS_MPIDATATYPE(double, MPI_DOUBLE)
52 HS_MPIDATATYPE(long double, MPI_LONG_DOUBLE)
53 HS_MPIDATATYPE(long long, MPI_LONG_LONG_INT)
54 HS_MPIDATATYPE(char, MPI_CHAR)
55 HS_MPIDATATYPE(unsigned char, MPI_UNSIGNED_CHAR)
56
57 //PetscScalar is simply a typedef for double. Hence no need to explicitly
58 //define an mpi_datatype for it.
59
60#undef HS_MPIDATATYPE
61
62#define HS_MPIPAIRDATATYPE(CTYPE1, CTYPE2, MPITYPE) \
63 template <> \
64 class Mpi_pairtype<CTYPE1, CTYPE2> \
65 { \
66 public: \
67 static MPI_Datatype value() {\
68 return MPITYPE;\
69 } \
70 };
71
72 HS_MPIPAIRDATATYPE(float, int, MPI_FLOAT_INT)
73 HS_MPIPAIRDATATYPE(double, int, MPI_DOUBLE_INT)
74 HS_MPIPAIRDATATYPE(long, int, MPI_LONG_INT)
75 HS_MPIPAIRDATATYPE(int, int, MPI_2INT)
76 HS_MPIPAIRDATATYPE(short, int, MPI_SHORT_INT)
77 HS_MPIPAIRDATATYPE(long double, int, MPI_LONG_DOUBLE_INT)
78
79#undef HS_MPIPAIRDATATYPE
80
81
82
83 template <typename T>
84 class Mpi_datatype<std::complex<T> > {
85 public:
86 static MPI_Datatype value()
87 {
88 static bool first = true;
89 static MPI_Datatype datatype;
90
91 if (first) {
92 first = false;
93 MPI_Type_contiguous(2, Mpi_datatype<T>::value(), &datatype);
94 MPI_Type_commit(&datatype);
95 }
96
97 return datatype;
98 }
99 };
100
101 template <typename T1, typename T2>
102 class Mpi_pairtype {
103 public:
104 static MPI_Datatype value()
105 {
106 static bool first = true;
107 static MPI_Datatype datatype;
108
109 if (first) {
110 first = false;
111 int block[2];
112 MPI_Aint disp[2];
113 MPI_Datatype type[2];
114
115 block[0] = 1;
116 block[0] = 1;
117 type[0] = Mpi_datatype<T1>::value();
118 type[1] = Mpi_datatype<T2>::value();
119 disp[0] = 0;
120 disp[1] = sizeof(T1);
121
122 MPI_Type_create_struct(2, block, disp, type, &datatype);
123 MPI_Type_commit(&datatype);
124 }
125
126 return datatype;
127 }
128 };
129
134 template <>
135 class Mpi_datatype<bool> {
136 static void bool_LOR(void *in, void *inout, int* len, MPI_Datatype * dptr) {
137 for (int i = 0; i < (*len); i++) {
138 ((static_cast<bool*>(inout))[i]) =
139 ( ((static_cast<bool*>(in))[i]) ||
140 ((static_cast<bool*>(inout))[i]) );
141 }//end for
142 }//end function
143
144
145 static void bool_LAND(void *in, void *inout, int* len, MPI_Datatype * dptr) {
146 for (int i = 0; i < (*len); i++) {
147 ((static_cast<bool*>(inout))[i]) =
148 ( ((static_cast<bool*>(in))[i]) && ((static_cast<bool*>(inout))[i]));
149 }//end for
150 }//end function
151
152 public:
157 static MPI_Op LAND() {
158 static bool first = true;
159 static MPI_Op land;
160 if (first) {
161 first = false;
162 MPI_Op_create(Mpi_datatype<bool>::bool_LAND ,true ,&land);
163 }
164
165 return land;
166 }
167
172 static MPI_Op LOR() {
173 static bool first = true;
174 static MPI_Op lor;
175 if (first) {
176 first = false;
177 MPI_Op_create(Mpi_datatype<bool>::bool_LOR ,true ,&lor);
178 }
179
180 return lor;
181 }
182
186 static MPI_Datatype value() {
187 static bool first = true;
188 static MPI_Datatype datatype;
189 if (first) {
190 first = false;
191 MPI_Type_contiguous(sizeof(bool), MPI_BYTE, &datatype);
192 MPI_Type_commit(&datatype);
193 }
194 return datatype;
195 }
196 };
197
198} //end namespace
199
200#endif
201
static MPI_Op LOR()
User defined MPI_Operation to perform: second[i] = (first[i] || second[i]),.
Definition dtypes.h:172
static MPI_Datatype value()
Definition dtypes.h:186
static MPI_Op LAND()
User defined MPI_Operation to perform: second[i] = (first[i] && second[i]),.
Definition dtypes.h:157
static MPI_Datatype value()
Definition dtypes.h:86
An abstract class used for communicating messages using user-defined datatypes. The user must impleme...
Definition dtypes.h:29
static MPI_Datatype value()
Definition dtypes.h:104
#define HS_MPIDATATYPE(CTYPE, MPITYPE)
Definition dtypes.h:34
#define HS_MPIPAIRDATATYPE(CTYPE1, CTYPE2, MPITYPE)
Definition dtypes.h:62
Collection of Generic Parallel Functions: Sorting, Partitioning, Searching,...
Definition dtypes.h:18