INMOST
A toolkit for distributed mathematical modeling
inmost_common.h
1 
2 #ifndef INMOST_COMMON_INCLUDED
3 #define INMOST_COMMON_INCLUDED
4 
5 
6 #include "inmost_options.h"
7 #if !defined(INMOST_OPTIONS_CMAKE_INCLUDED)
8 #pragma message("CMake options are not used")
9 //no options from cmake -- define minimum
10 //#define USE_OMP
11 //#define USE_OPENCL
12 
13 #define USE_MESH
14 
15 #define USE_PARTITIONER
16 //#define USE_PARTITIONER_ZOLTAN
17 //#define USE_PARTITIONER_PARMETIS
18 //#define USE_PARTITIONER_METIS
19 
20 #define USE_SOLVER
21 //#define USE_SOLVER_METIS
22 //#define USE_SOLVER_PETSC
23 //#define USE_SOLVER_TRILINOS
24 //#define USE_SOLVER_ANI
25 
26 
27 #define USE_NONLINEAR
28 //#define USE_NONLINEAR_PETSC
29 //#define USE_NONLINEAR_TRILINOS
30 //#define USE_NONLINEAR_SUNDIALS
31 
32 #define USE_AUTODIFF
33 //#define USE_AUTODIFF_ASMJIT
34 //#define USE_AUTODIFF_EXPRESSION_TEMPLATES
35 
36 //#define USE_MPI //include mpi for mpi functions
37 //#define USE_MPI_P2P //use (probably) more effective mpi-2 algorithms
38 //#define USE_MPI_FILE //use MPI_File_xxx functionality
39 //#define USE_MPI2 //set of your version produce warnings
40 
41 //#define USE_INT64
42 #define USE_FP64
43 #endif //INMOST_OPTIONS_CMAKE_INCLUDED
44 
45 
46 // a very expensive check for debug purposes,
47 // when you release marker checks all the elements
48 // that no element is marked by released marker
49 // in Mesh::Init function change two variables:
50 // check_shared_mrk - check shared markers.
51 // check_private_mrk - check private markers.
52 //#define CHECKS_MARKERS
53 
54 // use additional sets to store elements for parallel
55 // exchanges, otherwise it will recompute those elements
56 // which is quite expensive
57 #define USE_PARALLEL_STORAGE
58 
59 // output xml files for debugging of parallel algorithms
60 // search for style.xsl within examples for comfortable
61 // view of generated xml files
62 //#define USE_PARALLEL_WRITE_TIME
63 
64 // this will revert Mesh::PrepareReceiveInner to always
65 // use MPI point to point functionality disregarding problem type
66 // read comments in Mesh::SetParallelStrategy for more info
67 // USE_MPI_P2P must be enabled for feature to work
68 //#define PREFFER_MPI_P2P
69 
70 // this will write out shared set of elements that lay between processors in GMV format
71 //#define DEBUG_COMPUTE_SHARED_SKIN_SET
72 
73 // this controls how sparse data will be allocated,
74 // when definition is not commented memory will be always consumed
75 // by data structure needed to support sparse data,
76 // otherwise data structure will be allocated only when
77 // sparse data is present
78 //#define LAZY_SPARSE_ALLOCATION
79 
80 // this will force array class to use 12 bytes instead of 16 bytes
81 #define PACK_ARRAY
82 
83 #define __INLINE inline
84 
85 #if defined(USE_OMP)
86 #include <omp.h>
87 #endif
88 #if defined(USE_MPI)
89 #define NOMINMAX
90 #define OMPI_SKIP_MPICXX 1
91 #include <mpi.h>
92 #if !defined(MSMPI_VER) && !defined(MPIO_INCLUDE) && defined(USE_MPI_FILE) && !defined(OMPI_PROVIDE_MPI_FILE_INTERFACE)
93 //#include <mpio.h> //some versions of MPI doesn't include that
94 #endif
95 #endif
96 
97 #if defined(USE_OPENCL)
98 #ifdef __APPLE__
99 #include "OpenCL/opencl.h"
100 #else
101 #include "CL/cl.h"
102 #endif
103 #endif
104 
105 #include <string>
106 #include <vector>
107 #include <set>
108 #include <map>
109 #include <list>
110 #include <algorithm>
111 #include <cmath>
112 #include <iostream>
113 #include <fstream>
114 #include <stdlib.h>
115 #include <stdio.h>
116 #include <limits.h>
117 #include <complex>
118 
119 #if defined(USE_OMP)
120 #define OMP_THREAD omp_get_thread_num()
121 #define MAX_THREADS omp_get_max_threads()
122 #else //USE_OMP
123 #define OMP_THREAD 0
124 #define MAX_THREADS 1
125 #endif //USE_OMP
126 
127 
128 #if defined(min)
129 #undef min
130 #endif
131 #if defined(max)
132 #undef max
133 #endif
134 
135 #if !defined(USE_MPI)
136 #define INMOST_MPI_Request int
137 #define INMOST_MPI_Type int
138 #define INMOST_MPI_Comm int
139 #define INMOST_MPI_Group int
140 #define INMOST_MPI_COMM_WORLD 0
141 #define INMOST_MPI_COMM_SELF 0
142 #define INMOST_MPI_BYTE 0
143 #define INMOST_MPI_INT 0
144 #define INMOST_MPI_INT64_T 0
145 #define INMOST_MPI_UINT64_T 0
146 #define INMOST_MPI_DOUBLE 0
147 #define INMOST_MPI_FLOAT 0
148 #define INMOST_MPI_UNSIGNED 0
149 #define INMOST_MPI_UNSIGNEDL 0
150 #define INMOST_MPI_UNSIGNEDLL 0
151 #define INMOST_MPI_Win int
152 #define INMOST_MPI_DATATYPE_NULL 0
153 #define INMOST_MPI_GROUP_EMPTY 0
154 #else
155 #define INMOST_MPI_Request MPI_Request
156 #define INMOST_MPI_Type MPI_Datatype
157 #define INMOST_MPI_Comm MPI_Comm
158 #define INMOST_MPI_Group MPI_Group
159 #define INMOST_MPI_COMM_WORLD MPI_COMM_WORLD
160 #define INMOST_MPI_COMM_SELF MPI_COMM_SELF
161 #define INMOST_MPI_BYTE MPI_BYTE
162 #define INMOST_MPI_INT MPI_INT
163 #define INMOST_MPI_INT64_T MPI_INT64_T
164 #define INMOST_MPI_UINT64_T MPI_UINT64_T
165 #define INMOST_MPI_DOUBLE MPI_DOUBLE
166 #define INMOST_MPI_FLOAT MPI_FLOAT
167 #define INMOST_MPI_UNSIGNED MPI_UNSIGNED
168 #define INMOST_MPI_UNSIGNEDL MPI_UNSIGNED_LONG
169 #define INMOST_MPI_UNSIGNEDLL MPI_UNSIGNED_LONG_LONG
170 #define INMOST_MPI_Win MPI_Win
171 #define INMOST_MPI_DATATYPE_NULL MPI_DATATYPE_NULL
172 #define INMOST_MPI_GROUP_EMPTY MPI_GROUP_EMPTY
173 #endif
174 
175 #if !defined(USE_OMP)
176 #define INMOST_OMP_LOCK_T int
177 #else
178 #define INMOST_OMP_LOCK_T omp_lock_t
179 #endif
180 
181 
182 #define INMOST_MPI_SIZE int //in case MPI standard changes and compiler gives tons of warnings
183 
184 #define INMOST_DATA_BULK_TYPE unsigned char //this should be one byte long
185 #define INMOST_MPI_DATA_BULK_TYPE INMOST_MPI_BYTE
186 
187 #if defined(USE_FP64)
188 #define INMOST_DATA_REAL_TYPE double
189 #define INMOST_MPI_DATA_REAL_TYPE INMOST_MPI_DOUBLE
190 #define INMOST_DATA_CPLX_TYPE std::complex<double>
191 #else //USE_FP64
192 #define INMOST_DATA_REAL_TYPE float
193 #define INMOST_MPI_DATA_REAL_TYPE INMOST_MPI_FLOAT
194 #define INMOST_DATA_CPLX_TYPE std::complex<float>
195 #endif //USE_FP64
196 
197 __INLINE static INMOST_DATA_REAL_TYPE fabs(const INMOST_DATA_CPLX_TYPE & Arg) { return std::abs(Arg); }
198 __INLINE static INMOST_DATA_REAL_TYPE conj(INMOST_DATA_REAL_TYPE Arg) { return Arg; }
199 
200 #if defined(USE_INT64)
201 #define INMOST_DATA_INTEGER_TYPE int64_t
202 #define INMOST_DATA_ENUM_TYPE uint64_t
203 #define INMOST_DATA_BIG_ENUM_TYPE uint64_t
204 
205 #ifndef UINT64_MAX
206 #define UINT64_MAX ULLONG_MAX
207 #endif //UINT64_MAX
208 
209 #define ENUMUNDEF UINT64_MAX
210 #define BIGENUMUNDEF UINT64_MAX
211 
212 
213 #define INMOST_MPI_DATA_INTEGER_TYPE INMOST_MPI_INT64_T
214 #define INMOST_MPI_DATA_ENUM_TYPE INMOST_MPI_UINT64_T
215 #define INMOST_MPI_DATA_BIG_ENUM_TYPE INMOST_MPI_UINT64_T
216 #else //USE_INT64
217 #define INMOST_DATA_INTEGER_TYPE int
218 #define INMOST_DATA_ENUM_TYPE unsigned int
219 #define INMOST_DATA_BIG_ENUM_TYPE unsigned long long
220 
221 #define ENUMUNDEF UINT_MAX
222 #define BIGENUMUNDEF ULLONG_MAX
223 
224 #define INMOST_MPI_DATA_INTEGER_TYPE INMOST_MPI_INT
225 #define INMOST_MPI_DATA_ENUM_TYPE INMOST_MPI_UNSIGNED
226 #define INMOST_MPI_DATA_BIG_ENUM_TYPE INMOST_MPI_UNSIGNEDLL
227 #endif //USE_INT64
228 
236 double Timer();
237 
238 namespace INMOST
239 {
245  enum ErrorType
246  {
248  Failure=100,
249  NoTagPosition,
250  WrongDataType,
251  WrongElementType,
252  BadTag,
253  BadBulkType,
254  NoData,
255  TagNotInitialized,
256  TagNotFound,
257  TagExists,
258  TagForOtherMesh,
259  ElementForOtherMesh,
260  ImpossibleConn,
261  NoElementType,
262  NoMultiElement,
263  NoMeshElement,
264  NoEsetElement,
265  DimensionIsFixed,
266  NullInElementSet,
267  NoSpaceForMarker,
268  ElementBelongsToNobody,
269 
271  BadFileName,
272  BadFile,
273  CorruptedIerarchy,
274  CorruptedOrdering,
275  IterForOtherMesh,
276  UndefinedBehaviorInGeometry,
277  DimensionIsNotSupportedByGeometry,
278  NoParallelMode,
279  BadParameter,
280  TopologyCheckError,
281 
283  ErrorInSolver = 400,
284  DataCorruptedInSolver,
285  DifferentCommunicatorInSolver,
286  MatrixNotSetInSolver,
287  InconsistentSizesInSolver,
288  IndexesAreDifferentInSolver,
289  PrepareMatrixFirst,
290  CannotReusePreconditionerOfDifferentSize,
291  SolverNotFound,
292  SolverUnsupportedOperation,
293  SolverUnknownParameter,
294  SolverNonExistentParameters,
295  SolverCopyNullException,
296  SolverCopyException,
297  SolverAssignNullException,
298  SolverAssignException,
299 
301  ErrorInPartitioner = 500,
302  UnknownWeightSize,
303  DistributionTagWasNotFilled,
304 
306  MatrixError = 600,
307  MatrixCholeskySolveFail,
308  MatrixSolveFail,
309  MatrixPseudoSolveFail,
310 
312  NotImplemented = 1000,
313  Impossible
314  };
315 }
316 
317 #include "container.hpp"
318 //#include "io.hpp"
319 
320 
321 namespace INMOST
322 {
323  template<typename Var>
324  class AbstractMatrixReadOnly;
325 
326  template<typename Var>
327  class AbstractMatrix;
328 
329  template<typename Var>
330  class MatrixUnit;
331 
332  template<typename Var>
333  class MatrixRow;
334 
335  template<typename Var>
336  class MatrixCol;
337 
338  template<typename Var>
339  class MatrixDiag;
340 
341  template<typename Var>
342  class ConstMatrixRepack;
343 
344  template<typename Var>
345  class MatrixRepack;
346 
347  template<typename Var>
348  class SubMatrix;
349 
350  template<typename Var>
351  class ConstSubMatrix;
352 
353  template<typename Var>
354  class BlockOfMatrix;
355 
356  template<typename Var>
357  class ConstBlockOfMatrix;
358 
359  template<typename Var>
360  class MatrixConcatRows;
361 
362  template<typename Var>
363  class ConstMatrixConcatRows;
364 
365  template<typename VarA, typename VarB, typename VarR>
366  class ConstMatrixConcatRows2;
367 
368  template<typename Var>
369  class MatrixConcatCols;
370 
371  template<typename Var>
372  class ConstMatrixConcatCols;
373 
374  template<typename VarA, typename VarB, typename VarR>
375  class ConstMatrixConcatCols2;
376 
377  template<typename Var>
378  class MatrixUnaryMinus;
379 
380  template<typename VarA, typename VarB>
381  class MatrixSum;
382 
383  template<typename VarA, typename VarB>
384  class MatrixDifference;
385 
386  template<typename Var>
387  class MatrixTranspose;
388 
389  template<typename Var>
390  class ConstMatrixTranspose;
391 
392  template<typename Var>
393  class ConstMatrixConjugate;
394 
395  template<typename Var>
396  class ConstMatrixConjugateTranspose;
397 
398  template<typename VarA, typename VarB>
399  class KroneckerProduct;
400 
401  template<typename VarA, typename VarB, typename VarR>
402  class MatrixMulCoef;
403 
404  template<typename VarA, typename VarB, typename VarR>
405  class MatrixDivCoef;
406 
407  template<typename VarA, typename VarB, typename VarR>
408  class MatrixMulShellCoef;
409 
410  template<typename VarA, typename VarB, typename VarR>
411  class MatrixDivShellCoef;
412 
413  template<typename VarA, typename VarB, typename VarR>
414  class MatrixMul;
415 
416  template<typename Var, typename Storage = std::vector<Var> >
417  class Matrix;
418 
419  template<typename Var, typename Storage = std::vector<Var> >
420  class SymmetricMatrix;
421 
422  class value_reference;
423 }
424 
425 #include <cfloat>
426 
427 __INLINE bool __isnan__(double x) { return x != x; }
428 __INLINE bool __isinf__(double x) { return fabs(x) > DBL_MAX; }
429 __INLINE bool __isbad(double x) { return __isnan__(x) || __isinf__(x); }
430 
431 //in Utils/mem.cpp
432 size_t getPeakRSS();
433 size_t getCurrentRSS();
434 
435 #endif //INMOST_COMMON_INCLUDED