SuperLU Distributed 9.0.0
gpu3d
luAuxStructTemplated.hpp
Go to the documentation of this file.
1#pragma once
2#include <mpi.h>
3#include "superlu_defs.h"
4#include "superlu_zdefs.h"
5template<typename Ftype>
9 // Add other members as needed
10};
11struct complex;
12template <typename T>
13MPI_Datatype get_mpi_type()
14{
15 throw std::runtime_error("Unsupported type");
16}
17
18template <>
19MPI_Datatype get_mpi_type<int>()
20{
21 return MPI_INT;
22}
23
24template <>
25MPI_Datatype get_mpi_type<float>()
26{
27 return MPI_FLOAT;
28}
29
30template <>
32{
33 return MPI_DOUBLE;
34}
35
36// template <>
37// MPI_Datatype get_mpi_type<complex>()
38// {
39// return MPI_C_COMPLEX;
40// }
41
42template <>
44{
45 return MPI_C_DOUBLE_COMPLEX;
46}
47
48// AnormType<double>
49
50template <typename Ftype>
51using AnormType = typename std::conditional<
52 std::is_same<Ftype, float>::value,
53 float,
54 typename std::conditional<
55 std::is_same<Ftype, double>::value || std::is_same<Ftype, doublecomplex>::value,
56 double,
57 float // Default to float
58 >::type
59>::type;
60
61template <typename Ftype>
62using threshPivValType = typename std::conditional<
63 std::is_same<Ftype, float>::value,
64 float,
65 typename std::conditional<
66 std::is_same<Ftype, double>::value || std::is_same<Ftype, doublecomplex>::value,
67 double,
68 float // Default to float
69 >::type
70>::type;
71
72// template <typename Ftype>
73// using trf3dpartitionType
74template <typename Ftype>
75using trf3dpartitionType = typename std::conditional<
76 std::is_same<Ftype, double>::value,
78 typename std::conditional<
79 std::is_same<Ftype, float>::value,
81 typename std::conditional<
82 std::is_same<Ftype, doublecomplex>::value,
84 void
85 >::type
86 >::type
87>::type;
88
89template <typename Ftype>
90using LUStruct_type = typename std::conditional<
91 std::is_same<Ftype, double>::value,
93 typename std::conditional<
94 std::is_same<Ftype, float>::value,
96 typename std::conditional<
97 std::is_same<Ftype, doublecomplex>::value,
99 void
100 >::type
101 >::type
102>::type;
103
104template <typename Ftype>
105using LocalLU_type = typename std::conditional<
106 std::is_same<Ftype, double>::value,
108 typename std::conditional<
109 std::is_same<Ftype, float>::value,
111 typename std::conditional<
112 std::is_same<Ftype, doublecomplex>::value,
114 void
115 >::type
116 >::type
117>::type;
118
119template <typename Ftype>
120using LUValSubBuf_type = typename std::conditional<
121 std::is_same<Ftype, double>::value,
123 typename std::conditional<
124 std::is_same<Ftype, float>::value,
126 typename std::conditional<
127 std::is_same<Ftype, doublecomplex>::value,
129 void
130 >::type
131 >::type
132>::type;
133
134template <typename Ftype>
135using diagFactBufs_type = typename std::conditional<
136 std::is_same<Ftype, double>::value,
138 typename std::conditional<
139 std::is_same<Ftype, float>::value,
141 typename std::conditional<
142 std::is_same<Ftype, doublecomplex>::value,
144 void
145 >::type
146 >::type
147>::type;
148
149// Define one<T> for different types double(1.0), float(1.0f), doublecomplex(1.0, 0.0), complex(1.0f, 0.0f)
150// Generic template for one
151template<typename T>
152T one();
153
154// Specialization for double
155template<>
156double one<double>() {
157 return 1.0;
158}
159
160// Specialization for float
161template<>
162float one<float>() {
163 return 1.0f;
164}
165
166// Specialization for std::complex<double>
167template<>
169 doublecomplex z = {1.0, 0.0};
170 return z;
171}
172
173
174template<typename T>
176
177// Specialization for double
178template<>
180 return 0.0;
181}
182
183// Specialization for float
184template<>
186 return 0.0f;
187}
188
189// Specialization for std::complex<double>
190template<>
192 doublecomplex z = {0.0, 0.0};
193 return z;
194}
195
196template <typename T>
197__device__
198T atomicAddT(T* address, T val);
199
200// Specialization for double
201template<>
202double atomicAddT<double>(double* address, double val) {
203 return atomicAdd(address, val);
204}
205
206// Specialization for float
207template<>
208float atomicAddT<float>(float* address, float val) {
209 return atomicAdd(address, val);
210}
211
212// Specialization for std::complex<double>
213template<>
215 // doublecomplex out = *address;
216
217 atomicAdd (&address->r, val.r);
218 atomicAdd (&address->i, val.i);
219 return *address;
220}
221
222
223// External Operator Overload for '-'
224__host__ __device__
226 return {a.r - b.r, a.i - b.i};
227}
228
229// External Operator Overload for '=='
230__host__ __device__
231bool operator==(const doublecomplex& a, const doublecomplex& b) {
232 return (a.r == b.r) && (a.i == b.i);
233}
234
235// External Operator Overload for '/'
236__host__ __device__
238 double denom = b.r * b.r + b.i * b.i;
239 return {(a.r * b.r + a.i * b.i) / denom, (a.i * b.r - a.r * b.i) / denom};
240}
241
242__host__ __device__
244 return {-a.r, -a.i};
245}
246
247// Note: The assignment operator '=' cannot be overloaded as an external operator.
248// It must be a member function.
249
250// External Operator Overload for '*='
251__host__ __device__
253 double tr = a.r * b.r - a.i * b.i;
254 double ti = a.r * b.i + a.i * b.r;
255 a.r = tr;
256 a.i = ti;
257 return a;
258}
259
260// External Operator Overload for '-='
261__host__ __device__
263 a.r -= b.r;
264 a.i -= b.i;
265 return a;
266}
267
268
269// Template for general case (not yet defined)
270// template<typename T>
271// double sqnorm(T value);
272
273// // Specialization for float
274// template<>
275double sqnorm(float value) {
276 return (double) value * (double) value;
277}
278
279// Specialization for double
280// template<>
281double sqnorm(double value) {
282 return value * value;
283}
284
285// Specialization for doublecomplex
286// template<>
287double sqnorm(doublecomplex value) {
288 return value.r * value.r + value.i * value.i;
289}
290
291
292// template <typename Ftype>
293// void setDiagToThreshold(Ftype* diagptr, threshPivValType<Ftype> thresh);
294
295
296// template <>
297void setDiagToThreshold(double* diagptr, double thresh) {
298 if (*diagptr < 0)
299 *diagptr = -thresh;
300 else
301 *diagptr = thresh;
302}
303
304// template <>
305void setDiagToThreshold(float* diagptr, float thresh) {
306 if (*diagptr < 0)
307 *diagptr = -thresh;
308 else
309 *diagptr = thresh;
310 // *diagptr = thresh;
311}
312
313
314void setDiagToThreshold(doublecomplex* diagptr, double thresh) {
315 doublecomplex z = {thresh, 0.0};
316 if (diagptr->r < 0)
317 *diagptr = -z;
318 else
319 *diagptr = z;
320
321 *diagptr = z;
322}
323
__host__ __device__ bool operator==(const doublecomplex &a, const doublecomplex &b)
Definition: luAuxStructTemplated.hpp:231
doublecomplex zeroT< doublecomplex >()
Definition: luAuxStructTemplated.hpp:191
MPI_Datatype get_mpi_type< double >()
Definition: luAuxStructTemplated.hpp:31
MPI_Datatype get_mpi_type< float >()
Definition: luAuxStructTemplated.hpp:25
typename std::conditional< std::is_same< Ftype, double >::value, dLocalLU_t, typename std::conditional< std::is_same< Ftype, float >::value, sLocalLU_t, typename std::conditional< std::is_same< Ftype, doublecomplex >::value, zLocalLU_t, void >::type >::type >::type LocalLU_type
Definition: luAuxStructTemplated.hpp:117
typename std::conditional< std::is_same< Ftype, double >::value, dLUstruct_t, typename std::conditional< std::is_same< Ftype, float >::value, sLUstruct_t, typename std::conditional< std::is_same< Ftype, doublecomplex >::value, zLUstruct_t, void >::type >::type >::type LUStruct_type
Definition: luAuxStructTemplated.hpp:102
doublecomplex one< doublecomplex >()
Definition: luAuxStructTemplated.hpp:168
typename std::conditional< std::is_same< Ftype, double >::value, dtrf3Dpartition_t, typename std::conditional< std::is_same< Ftype, float >::value, strf3Dpartition_t, typename std::conditional< std::is_same< Ftype, doublecomplex >::value, ztrf3Dpartition_t, void >::type >::type >::type trf3dpartitionType
Definition: luAuxStructTemplated.hpp:87
MPI_Datatype get_mpi_type< doublecomplex >()
Definition: luAuxStructTemplated.hpp:43
T one()
typename std::conditional< std::is_same< Ftype, float >::value, float, typename std::conditional< std::is_same< Ftype, double >::value||std::is_same< Ftype, doublecomplex >::value, double, float >::type >::type threshPivValType
Definition: luAuxStructTemplated.hpp:70
T zeroT()
double zeroT< double >()
Definition: luAuxStructTemplated.hpp:179
typename std::conditional< std::is_same< Ftype, double >::value, dLUValSubBuf_t, typename std::conditional< std::is_same< Ftype, float >::value, sLUValSubBuf_t, typename std::conditional< std::is_same< Ftype, doublecomplex >::value, zLUValSubBuf_t, void >::type >::type >::type LUValSubBuf_type
Definition: luAuxStructTemplated.hpp:132
__device__ T atomicAddT(T *address, T val)
double atomicAddT< double >(double *address, double val)
Definition: luAuxStructTemplated.hpp:202
typename std::conditional< std::is_same< Ftype, float >::value, float, typename std::conditional< std::is_same< Ftype, double >::value||std::is_same< Ftype, doublecomplex >::value, double, float >::type >::type AnormType
Definition: luAuxStructTemplated.hpp:59
float one< float >()
Definition: luAuxStructTemplated.hpp:162
double sqnorm(float value)
Definition: luAuxStructTemplated.hpp:275
double one< double >()
Definition: luAuxStructTemplated.hpp:156
MPI_Datatype get_mpi_type()
Definition: luAuxStructTemplated.hpp:13
MPI_Datatype get_mpi_type< int >()
Definition: luAuxStructTemplated.hpp:19
float atomicAddT< float >(float *address, float val)
Definition: luAuxStructTemplated.hpp:208
__host__ __device__ doublecomplex operator-(const doublecomplex &a, const doublecomplex &b)
Definition: luAuxStructTemplated.hpp:225
__host__ __device__ doublecomplex & operator*=(doublecomplex &a, const doublecomplex &b)
Definition: luAuxStructTemplated.hpp:252
__host__ __device__ doublecomplex & operator-=(doublecomplex &a, const doublecomplex &b)
Definition: luAuxStructTemplated.hpp:262
__host__ __device__ doublecomplex operator/(const doublecomplex &a, const doublecomplex &b)
Definition: luAuxStructTemplated.hpp:237
void setDiagToThreshold(double *diagptr, double thresh)
Definition: luAuxStructTemplated.hpp:297
typename std::conditional< std::is_same< Ftype, double >::value, ddiagFactBufs_t, typename std::conditional< std::is_same< Ftype, float >::value, sdiagFactBufs_t, typename std::conditional< std::is_same< Ftype, doublecomplex >::value, zdiagFactBufs_t, void >::type >::type >::type diagFactBufs_type
Definition: luAuxStructTemplated.hpp:147
doublecomplex atomicAddT< doublecomplex >(doublecomplex *address, doublecomplex val)
Definition: luAuxStructTemplated.hpp:214
float zeroT< float >()
Definition: luAuxStructTemplated.hpp:185
Definition: superlu_ddefs.h:310
Definition: superlu_ddefs.h:340
Definition: superlu_ddefs.h:97
Definition: superlu_ddefs.h:467
Definition: luAuxStructTemplated.hpp:6
Ftype * BlockLFactor
Definition: luAuxStructTemplated.hpp:7
Ftype * BlockUFactor
Definition: luAuxStructTemplated.hpp:8
Definition: dcomplex.h:30
double i
Definition: dcomplex.h:30
double r
Definition: dcomplex.h:30
Definition: superlu_ddefs.h:318
Definition: superlu_sdefs.h:310
Definition: superlu_sdefs.h:340
Definition: superlu_sdefs.h:97
Definition: superlu_sdefs.h:467
Definition: superlu_sdefs.h:318
Definition: superlu_zdefs.h:310
Definition: superlu_zdefs.h:340
Definition: superlu_zdefs.h:97
Definition: superlu_zdefs.h:467
Definition: superlu_zdefs.h:318
Definitions which are precision-neutral.
Distributed SuperLU data types and function prototypes.