inmost_common.h 9.16 KB
Newer Older
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
1

Kirill Terekhov's avatar
Kirill Terekhov committed
2
3
4
5
6
7
#ifndef INMOST_COMMON_INCLUDED
#define INMOST_COMMON_INCLUDED


#include "inmost_options.h"
#if !defined(INMOST_OPTIONS_CMAKE_INCLUDED)
8
#pragma message("CMake options are not used")
Kirill Terekhov's avatar
Kirill Terekhov committed
9
10
//no options from cmake -- define minimum
//#define USE_OMP
11
//#define USE_OPENCL
Kirill Terekhov's avatar
Kirill Terekhov committed
12
13
14
15
16
17

#define USE_MESH

#define USE_PARTITIONER
//#define USE_PARTITIONER_ZOLTAN
//#define USE_PARTITIONER_PARMETIS
18
//#define USE_PARTITIONER_METIS
Kirill Terekhov's avatar
Kirill Terekhov committed
19
20

#define USE_SOLVER
Kirill Terekhov's avatar
Kirill Terekhov committed
21
//#define USE_SOLVER_METIS
Kirill Terekhov's avatar
Kirill Terekhov committed
22
//#define USE_SOLVER_PETSC
Kirill Terekhov's avatar
Kirill Terekhov committed
23
//#define USE_SOLVER_TRILINOS
Kirill Terekhov's avatar
Kirill Terekhov committed
24
25
//#define USE_SOLVER_ANI

Kirill Terekhov's avatar
Kirill Terekhov committed
26
27
28
29
30
31

#define USE_NONLINEAR
//#define USE_NONLINEAR_PETSC
//#define USE_NONLINEAR_TRILINOS
//#define USE_NONLINEAR_SUNDIALS

Kirill Terekhov's avatar
Kirill Terekhov committed
32
#define USE_AUTODIFF
Kirill Terekhov's avatar
Kirill Terekhov committed
33
//#define USE_AUTODIFF_ASMJIT
Kirill Terekhov's avatar
Kirill Terekhov committed
34
35
36
//#define USE_AUTODIFF_EXPRESSION_TEMPLATES

//#define USE_MPI //include mpi for mpi functions
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
37
38
39
//#define USE_MPI_P2P //use (probably) more effective mpi-2 algorithms
//#define USE_MPI_FILE //use MPI_File_xxx functionality
//#define USE_MPI2 //set of your version produce warnings
40
41
42

//#define USE_INT64
#define USE_FP64
Kirill Terekhov's avatar
Kirill Terekhov committed
43
44
45
#endif //INMOST_OPTIONS_CMAKE_INCLUDED


Kirill Terekhov's avatar
Kirill Terekhov committed
46
47
48
// a very expensive check for debug purposes, 
// when you release marker checks all the elements
// that no element is marked by released marker
49
50
51
// in Mesh::Init function change two variables:
// check_shared_mrk  - check shared markers.
// check_private_mrk - check private markers.
52
//#define CHECKS_MARKERS
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
53

Kirill Terekhov's avatar
Kirill Terekhov committed
54
55
56
// use additional sets to store elements for parallel
// exchanges, otherwise it will recompute those elements
// which is quite expensive
Kirill Terekhov's avatar
Kirill Terekhov committed
57
#define USE_PARALLEL_STORAGE
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
58

Kirill Terekhov's avatar
Kirill Terekhov committed
59
60
61
// output xml files for debugging of parallel algorithms
// search for style.xsl within examples for comfortable
// view of generated xml files
62
#define USE_PARALLEL_WRITE_TIME
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
63

Kirill Terekhov's avatar
Kirill Terekhov committed
64
// this will revert Mesh::PrepareReceiveInner to always
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
65
// use MPI point to point functionality disregarding problem type
Kirill Terekhov's avatar
Kirill Terekhov committed
66
// read comments in Mesh::SetParallelStrategy for more info
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
67
68
// USE_MPI_P2P must be enabled for feature to work
//#define PREFFER_MPI_P2P
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
69

Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
70
71
// this will write out shared set of elements that lay between processors in GMV format
//#define DEBUG_COMPUTE_SHARED_SKIN_SET
Kirill Terekhov's avatar
Kirill Terekhov committed
72

Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
73
74
75
76
77
78
79
80
81
82
// this controls how sparse data will be allocated,
// when difinition is not commented memory will be always consumed
// by data structure needed to support sparse data,
// otherwise data structure will be allocated only when
// sparse data is presenet
//#define LAZY_SPARSE_ALLOCATION

// this will force array class to use 12 bytes instead of 16 bytes
#define PACK_ARRAY

Kirill Terekhov's avatar
Kirill Terekhov committed
83
84
85
86
87
88
#define __INLINE inline

#if defined(USE_OMP)
#include <omp.h>
#endif
#if defined(USE_MPI)
89
#define NOMINMAX
90
#define OMPI_SKIP_MPICXX 1
Kirill Terekhov's avatar
Kirill Terekhov committed
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
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
94
#endif
Kirill Terekhov's avatar
Kirill Terekhov committed
95
96
#endif

97
98
99
100
101
102
103
104
#if defined(USE_OPENCL)
#ifdef __APPLE__
#include "OpenCL/opencl.h"
#else
#include "CL/cl.h"
#endif
#endif

Kirill Terekhov's avatar
Kirill Terekhov committed
105
106
107
108
109
110
111
112
113
114
115
116
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
117

Kirill Terekhov's avatar
Kirill Terekhov committed
118
#if defined(USE_OMP)
119
120
121
122
123
124
125
#define OMP_THREAD omp_get_thread_num()
#define MAX_THREADS omp_get_max_threads()
#else //USE_OMP
#define OMP_THREAD 0
#define MAX_THREADS 1
#endif //USE_OMP

126
127
128
129
130
131

#if defined(min)
#undef min
#endif
#if defined(max)
#undef max
132
#endif
Kirill Terekhov's avatar
Kirill Terekhov committed
133
134
135
136
137

#if !defined(USE_MPI)
#define INMOST_MPI_Request     int
#define INMOST_MPI_Type        int
#define INMOST_MPI_Comm        int
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
138
#define INMOST_MPI_Group       int
Kirill Terekhov's avatar
Kirill Terekhov committed
139
#define INMOST_MPI_COMM_WORLD  0
140
#define INMOST_MPI_COMM_SELF   0
Kirill Terekhov's avatar
Kirill Terekhov committed
141
142
#define INMOST_MPI_BYTE        0
#define INMOST_MPI_INT         0
143
144
#define INMOST_MPI_INT64_T     0
#define INMOST_MPI_UINT64_T    0
Kirill Terekhov's avatar
Kirill Terekhov committed
145
#define INMOST_MPI_DOUBLE      0
146
#define INMOST_MPI_FLOAT       0
Kirill Terekhov's avatar
Kirill Terekhov committed
147
#define INMOST_MPI_UNSIGNED    0
148
149
#define INMOST_MPI_UNSIGNEDL   0
#define INMOST_MPI_UNSIGNEDLL  0
Kirill Terekhov's avatar
Kirill Terekhov committed
150
#define INMOST_MPI_Win         int
151
#define INMOST_MPI_DATATYPE_NULL 0
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
152
#define INMOST_MPI_GROUP_EMPTY 0
Kirill Terekhov's avatar
Kirill Terekhov committed
153
154
155
156
#else
#define INMOST_MPI_Request     MPI_Request
#define INMOST_MPI_Type        MPI_Datatype
#define INMOST_MPI_Comm        MPI_Comm
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
157
#define INMOST_MPI_Group       MPI_Group
Kirill Terekhov's avatar
Kirill Terekhov committed
158
#define INMOST_MPI_COMM_WORLD  MPI_COMM_WORLD
159
#define INMOST_MPI_COMM_SELF   MPI_COMM_SELF
Kirill Terekhov's avatar
Kirill Terekhov committed
160
161
#define INMOST_MPI_BYTE        MPI_BYTE
#define INMOST_MPI_INT         MPI_INT
162
163
#define INMOST_MPI_INT64_T     MPI_INT64_T
#define INMOST_MPI_UINT64_T    MPI_UINT64_T
Kirill Terekhov's avatar
Kirill Terekhov committed
164
#define INMOST_MPI_DOUBLE      MPI_DOUBLE
165
#define INMOST_MPI_FLOAT       MPI_FLOAT
Kirill Terekhov's avatar
Kirill Terekhov committed
166
#define INMOST_MPI_UNSIGNED    MPI_UNSIGNED
167
168
#define INMOST_MPI_UNSIGNEDL   MPI_UNSIGNED_LONG
#define INMOST_MPI_UNSIGNEDLL  MPI_UNSIGNED_LONG_LONG 
Kirill Terekhov's avatar
Kirill Terekhov committed
169
#define INMOST_MPI_Win         MPI_Win
170
#define INMOST_MPI_DATATYPE_NULL MPI_DATATYPE_NULL
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
171
#define INMOST_MPI_GROUP_EMPTY MPI_GROUP_EMPTY
Kirill Terekhov's avatar
Kirill Terekhov committed
172
173
#endif

Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
174
175
176
177
178
179
#if !defined(USE_OMP)
#define INMOST_OMP_LOCK_T      int
#else
#define INMOST_OMP_LOCK_T      omp_lock_t
#endif

180

Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
181
#define INMOST_MPI_SIZE           int //in case MPI standard changes and compiler gives tons of warnings
Kirill Terekhov's avatar
Kirill Terekhov committed
182

Kirill Terekhov's avatar
Kirill Terekhov committed
183
#define INMOST_DATA_BULK_TYPE     unsigned char //this should be one byte long
184
#define INMOST_MPI_DATA_BULK_TYPE     INMOST_MPI_BYTE
Kirill Terekhov's avatar
Kirill Terekhov committed
185

186
187
#if defined(USE_FP64)
#define INMOST_DATA_REAL_TYPE     double
Kirill Terekhov's avatar
Kirill Terekhov committed
188
#define INMOST_MPI_DATA_REAL_TYPE     INMOST_MPI_DOUBLE
189
190
191
192
193
#else //USE_FP64
#define INMOST_DATA_REAL_TYPE     float
#define INMOST_MPI_DATA_REAL_TYPE     INMOST_MPI_FLOAT
#endif //USE_FP64

Kirill Terekhov's avatar
Kirill Terekhov committed
194

195
196
197
198
#if defined(USE_INT64)
#define INMOST_DATA_INTEGER_TYPE   int64_t
#define INMOST_DATA_ENUM_TYPE      uint64_t
#define INMOST_DATA_BIG_ENUM_TYPE  uint64_t
Kirill Terekhov's avatar
Kirill Terekhov committed
199

200
201
202
#ifndef UINT64_MAX
#define UINT64_MAX ULLONG_MAX
#endif //UINT64_MAX
Kirill Terekhov's avatar
Kirill Terekhov committed
203

204
205
206
#define ENUMUNDEF                 UINT64_MAX
#define BIGENUMUNDEF              UINT64_MAX

207

208
209
210
211
212
#define INMOST_MPI_DATA_INTEGER_TYPE   INMOST_MPI_INT64_T
#define INMOST_MPI_DATA_ENUM_TYPE      INMOST_MPI_UINT64_T
#define INMOST_MPI_DATA_BIG_ENUM_TYPE  INMOST_MPI_UINT64_T
#else //USE_INT64
#define INMOST_DATA_INTEGER_TYPE    int           
Kirill Terekhov's avatar
Kirill Terekhov committed
213
#define INMOST_DATA_ENUM_TYPE       unsigned int
214
#define INMOST_DATA_BIG_ENUM_TYPE   unsigned long long
Kirill Terekhov's avatar
Kirill Terekhov committed
215

216
217
218
219
#define ENUMUNDEF                     UINT_MAX
#define BIGENUMUNDEF                  ULLONG_MAX

#define INMOST_MPI_DATA_INTEGER_TYPE   INMOST_MPI_INT
Kirill Terekhov's avatar
Kirill Terekhov committed
220
#define INMOST_MPI_DATA_ENUM_TYPE      INMOST_MPI_UNSIGNED
221
#define INMOST_MPI_DATA_BIG_ENUM_TYPE  INMOST_MPI_UNSIGNEDLL
222
#endif //USE_INT64
Kirill Terekhov's avatar
Kirill Terekhov committed
223

224
225
226
/// Cross-platform timer that return current time in seconds.
/// The timer is similar to MPI_Wtime() and omp_get_wtime() but is independent on both flags USE_MPI and USE_OMP.
///
Kirill Terekhov's avatar
Kirill Terekhov committed
227
228
229
/// double seconds = Timer();
/// ...some code...
/// seconds = Timer() - seconds;
230
/// std::cout << "Time spent is " << seconds << " seconds." << std::endl;
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
231
double Timer();
Kirill Terekhov's avatar
Kirill Terekhov committed
232
233
234

namespace INMOST
{
235
236
237
238
239
	/// Types of errors may occur in INMOST.
	/// All of these error are fatal ones.
	/// If error is detected then "throw" exception is generated.
	/// The names of the error type are very intuitive and self-explained ones.
	/// Use "try{...} catch{...}" blocks to implement exception handling.
Kirill Terekhov's avatar
Kirill Terekhov committed
240
241
	enum ErrorType 
	{
242
		/// The list of errors connected to mesh consistency.
Kirill Terekhov's avatar
Kirill Terekhov committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
		Failure=100,
		NoTagPosition,
		WrongDataType,
		WrongElementType,
		BadTag,
		BadBulkType,
		NoData,
		TagNotInitialized,
		TagNotFound, 
		TagExists, 
		TagForOtherMesh,
		ElementForOtherMesh,
		ImpossibleConn,
		NoElementType,
		NoMultiElement,
		NoMeshElement,
		NoEsetElement,
		DimensionIsFixed,
		NullInElementSet,		
		NoSpaceForMarker,
		ElementBelongsToNobody,

265
		/// The list of general type errors.
Kirill Terekhov's avatar
Kirill Terekhov committed
266
267
268
269
270
271
272
273
274
275
276
		BadFileName,
		BadFile,		
		CorruptedIerarchy,
		CorruptedOrdering,
		IterForOtherMesh,
		UndefinedBehaviorInGeometry,
		DimensionIsNotSupportedByGeometry,
		NoParallelMode,
		BadParameter,
		TopologyCheckError,
		
277
		/// The list of errors may occur in the Linear Solver.
Kirill Terekhov's avatar
Kirill Terekhov committed
278
279
280
281
282
283
284
285
		ErrorInSolver = 400,
		DataCorruptedInSolver,
		DifferentCommunicatorInSolver,
		MatrixNotSetInSolver,
		InconsistentSizesInSolver,
		IndexesAreDifferentInSolver,
		PrepareMatrixFirst,
		CannotReusePreconditionerOfDifferentSize,
286
		SolverNotFound,
Dmitry Bagaev's avatar
Dmitry Bagaev committed
287
		SolverUnsupportedOperation,
288
		SolverUnknownParameter,
Dmitry Bagaev's avatar
Dmitry Bagaev committed
289
		SolverNonExistentParameters,
290
291
292
293
		SolverCopyNullException,
		SolverCopyException,
        SolverAssignNullException,
        SolverAssignException,
Kirill Terekhov's avatar
Kirill Terekhov committed
294
		
295
		/// The list of errors may occur in the Partitioner.
Kirill Terekhov's avatar
Kirill Terekhov committed
296
297
298
299
		ErrorInPartitioner = 500,
		UnknownWeightSize,
		DistributionTagWasNotFilled,
		
300
301
302
303
304
305
		/// The list of errros that may occur in linear algebra
		MatrixError = 600,
		MatrixCholeskySolveFail,
		MatrixSolveFail,
		MatrixPseudoSolveFail,
		
306
		/// The very tail of the errors list.
Kirill Terekhov's avatar
Kirill Terekhov committed
307
308
309
310
311
312
		NotImplemented = 1000,
		Impossible
	};
}

#include "container.hpp"
Kirill Terekhov's avatar
Kirill Terekhov committed
313
//#include "io.hpp"
Kirill Terekhov's avatar
Kirill Terekhov committed
314
315


316
317
318
319
320
321
322
323
namespace INMOST
{
	template<typename Var>
	class AbstractMatrix;
	
	template<typename Var>
	class SubMatrix;
	
Kirill Terekhov's avatar
Kirill Terekhov committed
324
325
326
	template<typename Var>
	class ConstSubMatrix;
	
327
328
329
330
331
332
	template<typename Var>
	class BlockOfMatrix;
	
	template<typename Var>
	class ConstBlockOfMatrix;
	
333
334
335
336
337
338
339
	template<typename Var, typename Storage = array<Var> >
	class Matrix;
	
	template<typename Var, typename Storage = array<Var> >
	class SymmetricMatrix;
}

340
341
#include <cfloat>

342
343
344
__INLINE bool __isnan__(double x) { return x != x; }
__INLINE bool __isinf__(double x) { return fabs(x) > DBL_MAX; }
__INLINE bool __isbad(double x) { return __isnan__(x) || __isinf__(x); }
345

346

Kirill Terekhov's avatar
Kirill Terekhov committed
347
#endif //INMOST_COMMON_INCLUDED