Go to the documentation of this file. 1 #ifndef PARGEMSLR_UTILS_H
2 #define PARGEMSLR_UTILS_H
12 #include <type_traits>
19 #define PARGEMSLR_FIRM_CHKERR(ierr) {{if(ierr){printf("Err value: %d on MPI rank %d\n",ierr, parallel_log::_grank);assert(!(ierr));};}}
21 #ifdef PARGEMSLR_DEBUG
22 #define PARGEMSLR_ERROR(message) {printf("Error: %s on MPI rank %d\n", message, parallel_log::_grank);assert(0);}
23 #define PARGEMSLR_CHKERR(ierr) {{if(ierr){printf("Err value: %d\n",ierr);assert(!(ierr));};}}
24 #define PARGEMSLR_PRINT_DEBUG(conda, condb, ...) {if(conda==condb) {printf("DEBUG: ");printf(__VA_ARGS__);}}
26 #define PARGEMSLR_ERROR(message) {printf("Error: %s on MPI rank %d\n", message, parallel_log::_grank);}
27 #define PARGEMSLR_CHKERR(ierr) {;}
28 #define PARGEMSLR_PRINT_DEBUG(conda, condb, ...) {;}
30 #ifdef PARGEMSLR_NO_WARNING
31 #define PARGEMSLR_WARNING(message) {;}
33 #define PARGEMSLR_WARNING(message) {printf("Warning: %s on MPI rank %d\n", message, parallel_log::_grank);}
36 #define PARGEMSLR_PRINT(...) fprintf(pargemslr::pargemslr_global::_out_file, __VA_ARGS__);
38 #ifndef PARGEMSLR_SUCCESS
39 #define PARGEMSLR_SUCCESS 0
40 #define PARGEMSLR_RETURN_METIS_INSUFFICIENT_NDOM 1
41 #define PARGEMSLR_RETURN_METIS_NO_INTERIOR 2
42 #define PARGEMSLR_RETURN_METIS_PROBLEM_TOO_SMALL 3
43 #define PARGEMSLR_RETURN_PARILU_NO_INTERIOR 10
44 #define PARGEMSLR_ERROR_INVALED_OPTION 100
45 #define PARGEMSLR_ERROR_INVALED_PARAM 101
46 #define PARGEMSLR_ERROR_IO_ERROR 102
47 #define PARGEMSLR_ERROR_ILU_EMPTY_ROW 103
48 #define PARGEMSLR_ERROR_DOUBLE_INIT_FREE 104 // call init function for multiple times
49 #define PARGEMSLR_ERROR_COMPILER 105
50 #define PARGEMSLR_ERROR_FUNCTION_CALL_ERR 106
51 #define PARGEMSLR_ERROR_MEMORY_LOCATION 107
54 #define PARGEMSLR_CAST( type, val) reinterpret_cast<type>((val))
77 #define PARGEMSLR_IO_SIZE 180
82 #define PARGEMSLR_IO_PRECOND_GLOBAL_PRECOND 0
84 #define PARGEMSLR_IO_PRECOND_LOCAL_REPCOND1 1
86 #define PARGEMSLR_IO_PRECOND_LOCAL_REPCOND1_LEVEL 2
88 #define PARGEMSLR_IO_PRECOND_LOCAL_REPCOND2 3
91 #define PARGEMSLR_IO_PRECOND_LOCAL_REPCOND3 4
93 #define PARGEMSLR_IO_PRECOND_LOCAL_SMOOTHER1 5
98 #define PARGEMSLR_IO_SOLVER_OPTION 10
99 #define PARGEMSLR_IO_SOLVER_KDIM 11
100 #define PARGEMSLR_IO_SOLVER_MAXITS 12
101 #define PARGEMSLR_IO_SOLVER_TOL 13
102 #define PARGEMSLR_IO_SOLVER_ATOL 14
107 #define PARGEMSLR_IO_PREPOSS_NLEV_GLOBAL 20
109 #define PARGEMSLR_IO_PREPOSS_NLEV_LOCAL 21
111 #define PARGEMSLR_IO_PREPOSS_NCOMP_GLOBAL 22
113 #define PARGEMSLR_IO_PREPOSS_NCOMP_LOCAL 23
115 #define PARGEMSLR_IO_PREPOSS_PARTITION_GLOBAL 24
117 #define PARGEMSLR_IO_PREPOSS_PARTITION_LOCAL 25
119 #define PARGEMSLR_IO_PREPOSS_MINSEP 26
121 #define PARGEMSLR_IO_PREPOSS_KMIN_GLOBAL 27
123 #define PARGEMSLR_IO_PREPOSS_KMIN_LOCAL 28
125 #define PARGEMSLR_IO_PREPOSS_KFACTOR_GLOBAL 29
127 #define PARGEMSLR_IO_PREPOSS_KFACTOR_LOCAL 30
129 #define PARGEMSLR_IO_PREPOSS_VTXSEP_GLOBAL 31
131 #define PARGEMSLR_IO_PREPOSS_VTXSEP_LOCAL 32
133 #define PARGEMSLR_IO_PREPOSS_METIS_REFINE 33
135 #define PARGEMSLR_IO_PREPOSS_GLOBAL_PARTITION 34
140 #define PARGEMSLR_IO_ILU_DROPTOL_B_GLOBAL 40
142 #define PARGEMSLR_IO_ILU_DROPTOL_B_LOCAL 41
144 #define PARGEMSLR_IO_ILU_DROPTOL_EF_GLOBAL 42
146 #define PARGEMSLR_IO_ILU_DROPTOL_EF_LOCAL 43
148 #define PARGEMSLR_IO_ILU_DROPTOL_C_GLOBAL 44
150 #define PARGEMSLR_IO_ILU_DROPTOL_C_LOCAL 45
152 #define PARGEMSLR_IO_ILU_DROPTOL_S_GLOBAL 46
154 #define PARGEMSLR_IO_ILU_DROPTOL_S_LOCAL 47
156 #define PARGEMSLR_IO_ILU_ROWNNZ_B_GLOBAL 48
158 #define PARGEMSLR_IO_ILU_ROWNNZ_B_LOCAL 49
160 #define PARGEMSLR_IO_ILU_ROWNNZ_C_GLOBAL 50
162 #define PARGEMSLR_IO_ILU_ROWNNZ_C_LOCAL 51
164 #define PARGEMSLR_IO_ILU_LFIL_B_GLOBAL 52
166 #define PARGEMSLR_IO_ILU_LFIL_B_LOCAL 53
168 #define PARGEMSLR_IO_ILU_LFIL_C_GLOBAL 54
170 #define PARGEMSLR_IO_ILU_LFIL_C_LOCAL 55
172 #define PARGEMSLR_IO_ILU_ROWNNZ_S_GLOBAL 56
174 #define PARGEMSLR_IO_ILU_ROWNNZ_S_LOCAL 57
176 #define PARGEMSLR_IO_ILU_PERM_OPTION_GLOBAL 58
178 #define PARGEMSLR_IO_ILU_PERM_OPTION_LOCAL 59
180 #define PARGEMSLR_IO_ILU_OMP_OPTION_GLOBAL 60
182 #define PARGEMSLR_IO_ILU_OMP_OPTION_LOCAL 61
187 #define PARGEMSLR_IO_LR_ARNOLDI_OPTION1_GLOBAL 70
189 #define PARGEMSLR_IO_LR_ARNOLDI_OPTION2_GLOBAL 71
191 #define PARGEMSLR_IO_LR_ARNOLDI_OPTION1_LOCAL 72
193 #define PARGEMSLR_IO_LR_ARNOLDI_OPTION2_LOCAL 73
195 #define PARGEMSLR_IO_LR_RANK1_GLOBAL 74
197 #define PARGEMSLR_IO_LR_RANK2_GLOBAL 75
199 #define PARGEMSLR_IO_LR_RANK1_LOCAL 76
201 #define PARGEMSLR_IO_LR_RANK2_LOCAL 77
203 #define PARGEMSLR_IO_LR_RANK_FACTOR1_GLOBAL 78
205 #define PARGEMSLR_IO_LR_RANK_FACTOR2_GLOBAL 79
207 #define PARGEMSLR_IO_LR_RANK_FACTOR1_LOCAL 80
209 #define PARGEMSLR_IO_LR_RANK_FACTOR2_LOCAL 81
211 #define PARGEMSLR_IO_LR_ARNOLDI_FACTOR1_GLOBAL 82
213 #define PARGEMSLR_IO_LR_ARNOLDI_FACTOR2_GLOBAL 83
215 #define PARGEMSLR_IO_LR_ARNOLDI_FACTOR1_LOCAL 84
217 #define PARGEMSLR_IO_LR_ARNOLDI_FACTOR2_LOCAL 85
219 #define PARGEMSLR_IO_LR_TOL_EIG1_GLOBAL 86
221 #define PARGEMSLR_IO_LR_TOL_EIG2_GLOBAL 87
223 #define PARGEMSLR_IO_LR_TOL_EIG1_LOCAL 88
225 #define PARGEMSLR_IO_LR_TOL_EIG2_LOCAL 89
227 #define PARGEMSLR_IO_LR_MAXITS1_GLOBAL 90
229 #define PARGEMSLR_IO_LR_MAXITS2_GLOBAL 91
231 #define PARGEMSLR_IO_LR_MAXITS1_LOCAL 92
233 #define PARGEMSLR_IO_LR_MAXITS2_LOCAL 93
235 #define PARGEMSLR_IO_LR_TR_FACTOR 94
237 #define PARGEMSLR_IO_LR_TOL_ORTH 95
239 #define PARGEMSLR_IO_LR_TOL_REORTH 96
241 #define PARGEMSLR_IO_LR_RAND_INIT_GUESS 97
243 #define PARGEMSLR_IO_LR_RANK_C_NITER 98
245 #define PARGEMSLR_IO_LR_ARNOLDI_OPTIONA 99
247 #define PARGEMSLR_IO_LR_RANK_A 100
249 #define PARGEMSLR_IO_LR_RANK_FACTORA 101
251 #define PARGEMSLR_IO_LR_ARNOLDI_FACTORA 102
253 #define PARGEMSLR_IO_LR_TOL_EIGA 103
255 #define PARGEMSLR_IO_LR_MAXITSA 104
260 #define PARGEMSLR_IO_SCHUR_ENABLE 130
262 #define PARGEMSLR_IO_SCHUR_ITER_TOL 131
264 #define PARGEMSLR_IO_SCHUR_MAXITS 132
269 #define PARGEMSLR_IO_ADVANCED_DIAG_SHIFT 140
271 #define PARGEMSLR_IO_ADVANCED_GLOBAL_SOLVE 141
273 #define PARGEMSLR_IO_ADVANCED_USE_COMPLEX_SHIFT 142
275 #define PARGEMSLR_IO_ADVANCED_RESIDUAL_ITERS 143
277 #define PARGEMSLR_IO_ADVANCED_GRAM_SCHMIDT 144
279 #define PARGEMSLR_IO_ADVANCED_DIAG_SHIFT_MODIFIED 145
284 #define PARGEMSLR_IO_GENERAL_PRINT_LEVEL 150
288 #define PARGEMSLR_IO_POLY_ORDER 160
292 #define PARGEMSLR_IO_PARALLEL_NPROCX 170
293 #define PARGEMSLR_IO_PARALLEL_NPROCY 171
294 #define PARGEMSLR_IO_PARALLEL_NPROCZ 172
295 #define PARGEMSLR_IO_PARALLEL_NDOMX 173
296 #define PARGEMSLR_IO_PARALLEL_NDOMY 174
297 #define PARGEMSLR_IO_PARALLEL_NDOMZ 175
416 double* PargemslrSetDefaultParameterArray(
double *params);
454 kUnknownPrecision = -1,
469 template <
typename T>
491 bool operator()(T
const &a, T
const &b)
const {
return a.val > b.val; }
504 bool operator()(T
const &a, T
const &b)
const {
return a.val < b.val; }
514 template <
typename T>
515 T PargemslrMax(T a, T b);
524 template <
typename T>
525 T PargemslrMin(T a, T b);
533 template <
typename T>
534 typename std::enable_if<!PargemslrIsComplex<T>::value, T>::type
535 PargemslrAbs(
const T &a);
543 float PargemslrAbs(
const complexs &a);
551 double PargemslrAbs(
const complexd &a);
559 template <
typename T>
560 typename std::enable_if<!PargemslrIsComplex<T>::value, T>::type
561 PargemslrReal(
const T &a);
569 float PargemslrReal(
const complexs &a);
577 double PargemslrReal(
const complexd &a);
585 template <
typename T>
586 typename std::enable_if<!PargemslrIsComplex<T>::value, T>::type
587 PargemslrConj(
const T &a);
595 template <
typename T>
596 typename std::enable_if<PargemslrIsComplex<T>::value, T>::type
597 PargemslrConj(
const T &a);
605 template <
typename T>
606 typename std::enable_if<PargemslrIsInteger<T>::value,
int>::type
607 PargemslrValueRandHost(T &a);
615 template <
typename T>
616 typename std::enable_if<PargemslrIsReal<T>::value,
int>::type
617 PargemslrValueRandHost(T &a);
625 template <
typename T>
626 typename std::enable_if<PargemslrIsComplex<T>::value,
int>::type
627 PargemslrValueRandHost(T &a);
635 int PargemslrPrintSpace(
int width);
643 int PargemslrPrintDashLine(
int width);
652 template <
typename T>
653 typename std::enable_if<PargemslrIsInteger<T>::value,
int>::type
654 PargemslrPrintValueHost(T val,
int width);
663 template <
typename T>
664 typename std::enable_if<PargemslrIsReal<T>::value,
int>::type
665 PargemslrPrintValueHost(T val,
int width);
674 template <
typename T>
675 typename std::enable_if<PargemslrIsComplex<T>::value,
int>::type
676 PargemslrPrintValueHost(T val,
int width);
684 void PargemslrReadFirstWord(
char *pin,
char **pout);
696 int PargemslrReadInputArg(
const char *argname,
int amount,
float *val,
int argc,
char **argv);
708 int PargemslrReadInputArg(
const char *argname,
int amount,
double *val,
int argc,
char **argv);
720 int PargemslrReadInputArg(
const char *argname,
int amount,
complexs *val,
int argc,
char **argv);
732 int PargemslrReadInputArg(
const char *argname,
int amount,
complexd *val,
int argc,
char **argv);
744 int PargemslrReadInputArg(
const char *argname,
int amount,
int *val,
int argc,
char **argv);
755 int PargemslrReadInputArg(
const char *argname,
char *val,
int argc,
char **argv);
766 int PargemslrReadInputArg(
const char *argname,
bool *val,
int argc,
char **argv);
776 int PargemslrReadInputArg(
const char *argname,
int argc,
char **argv);
787 template <
typename T>
789 PargemslrPlotData(T* ydata,
int length,
int numx,
int numy);
799 template <
typename T>
800 typename std::enable_if<PargemslrIsComplex<T>::value,
int>::type
801 PargemslrPlotData(T* ydata,
int length,
int numx,
int numy);
809 int PargemslrSetOutputFile(
const char *filename);
static int _gram_schmidt
Gram schmidt option for the eigenvalue solver.
Definition: utils.hpp:406
The data structure for parallel computing, including data structures for MPI and CUDA.
Definition: utils.hpp:307
static double * _params
The global parameters' array.
Definition: utils.hpp:398
The complex value data structure.
static int _metis_refine
Numter of Metis refine (for ParMetis).
Definition: utils.hpp:332
Tell if a value is a parallel data structure.
Definition: utils.hpp:444
The operator > for CompareStruct.
Definition: utils.hpp:490
static std::mt19937 _mersenne_twister_engine
Mersenne_twister_engine.
Definition: utils.hpp:380
static std::uniform_int_distribution< int > _uniform_int_distribution
Uniform_int_distribution.
Definition: utils.hpp:386
static double _tr_factor
Thick-restart factor for thick-restart Arnoldi.
Definition: utils.hpp:350
static double _expand_fact
Expand factor, used when expand vectors with PushBack.
Definition: utils.hpp:314
static std::random_device _random_device
Used to obtain a seed for the random number engine.
Definition: utils.hpp:374
static double _metis_loading_balance_tol
The tolorance for loading balance when apply the parallel kway partition.
Definition: utils.hpp:338
The template class complex.
Definition: complex.hpp:24
static int _dash_line_width
Default width of the dashline in the output.
Definition: utils.hpp:368
static int _openmp_min_loopsize
Disable OpenMP in some cases when a loop size is too small.
Definition: utils.hpp:326
static FILE * _out_file
The output file, default is stdout.
Definition: utils.hpp:392
Tell if a value is in double precision.
Definition: utils.hpp:433
static double _reorth_tol
The tolorance for re-orthogonalization for Arnoldi.
Definition: utils.hpp:362
The operator < for CompareStruct.
Definition: utils.hpp:503
static int _minsep
Min size of the edge separator.
Definition: utils.hpp:344
Tell if a value is a complex value.
Definition: complex.hpp:684
static int _coo_reserve_fact
Reserved size of COO matrix, default is nrow * _coo_reserve_fact.
Definition: utils.hpp:320
Tell if a value is integer.
Definition: utils.hpp:422
static double _orth_tol
The tolorance for orthogonalization for Arnoldi.
Definition: utils.hpp:356
PrecisionEnum
The precision enum.
Definition: utils.hpp:453
The struct of for sorting.
Definition: utils.hpp:471