inmost_common.h 8.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
8
9
#ifndef INMOST_COMMON_INCLUDED
#define INMOST_COMMON_INCLUDED


#include "inmost_options.h"
#if !defined(INMOST_OPTIONS_CMAKE_INCLUDED)
//no options from cmake -- define minimum
//#define USE_OMP
10
//#define USE_OPENCL
Kirill Terekhov's avatar
Kirill Terekhov committed
11
12
13
14
15
16

#define USE_MESH

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

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

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

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

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

//#define USE_MPI //include mpi for mpi functions
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
36
37
38
//#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
Kirill Terekhov's avatar
Kirill Terekhov committed
39
40
41
#endif //INMOST_OPTIONS_CMAKE_INCLUDED


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

Kirill Terekhov's avatar
Kirill Terekhov committed
50
51
52
// 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
53
#define USE_PARALLEL_STORAGE
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
54

Kirill Terekhov's avatar
Kirill Terekhov committed
55
56
57
// output xml files for debugging of parallel algorithms
// search for style.xsl within examples for comfortable
// view of generated xml files
Kirill Terekhov's avatar
Kirill Terekhov committed
58
//~ #define USE_PARALLEL_WRITE_TIME
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
59

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

Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
66
67
// 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
68

Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
69
70
71
72
73
74
75
76
77
78
// 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
79
80
81
82
83
84
#define __INLINE inline

#if defined(USE_OMP)
#include <omp.h>
#endif
#if defined(USE_MPI)
85
#define NOMINMAX
Kirill Terekhov's avatar
Kirill Terekhov committed
86
#include <mpi.h>
87
#if !defined(MSMPI_VER) && !defined(MPIO_INCLUDE) && defined(USE_MPI_FILE) && !defined(OMPI_PROVIDE_MPI_FILE_INTERFACE)
88
//#include <mpio.h> //some versions of MPI doesn't include that
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
89
#endif
Kirill Terekhov's avatar
Kirill Terekhov committed
90
91
#endif

92
93
94
95
96
97
98
99
#if defined(USE_OPENCL)
#ifdef __APPLE__
#include "OpenCL/opencl.h"
#else
#include "CL/cl.h"
#endif
#endif

Kirill Terekhov's avatar
Kirill Terekhov committed
100
101
102
103
104
105
106
107
108
109
110
111
#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>
112

Kirill Terekhov's avatar
Kirill Terekhov committed
113
#if defined(USE_OMP)
114
115
116
117
118
119
120
#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

121
122
123
124
125
126

#if defined(min)
#undef min
#endif
#if defined(max)
#undef max
127
#endif
Kirill Terekhov's avatar
Kirill Terekhov committed
128
129
130
131
132

#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
133
#define INMOST_MPI_Group       int
Kirill Terekhov's avatar
Kirill Terekhov committed
134
#define INMOST_MPI_COMM_WORLD  0
135
#define INMOST_MPI_COMM_SELF  0
Kirill Terekhov's avatar
Kirill Terekhov committed
136
137
138
139
#define INMOST_MPI_BYTE        0
#define INMOST_MPI_INT         0
#define INMOST_MPI_DOUBLE      0
#define INMOST_MPI_UNSIGNED    0
140
141
#define INMOST_MPI_UNSIGNEDL   0
#define INMOST_MPI_UNSIGNEDLL  0
Kirill Terekhov's avatar
Kirill Terekhov committed
142
#define INMOST_MPI_Win         int
143
#define INMOST_MPI_DATATYPE_NULL 0
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
144
#define INMOST_MPI_GROUP_EMPTY 0
Kirill Terekhov's avatar
Kirill Terekhov committed
145
146
147
148
#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
149
#define INMOST_MPI_Group       MPI_Group
Kirill Terekhov's avatar
Kirill Terekhov committed
150
#define INMOST_MPI_COMM_WORLD  MPI_COMM_WORLD
151
#define INMOST_MPI_COMM_SELF   MPI_COMM_SELF
Kirill Terekhov's avatar
Kirill Terekhov committed
152
153
154
155
#define INMOST_MPI_BYTE        MPI_BYTE
#define INMOST_MPI_INT         MPI_INT
#define INMOST_MPI_DOUBLE      MPI_DOUBLE
#define INMOST_MPI_UNSIGNED    MPI_UNSIGNED
156
157
#define INMOST_MPI_UNSIGNEDL   MPI_UNSIGNED_LONG
#define INMOST_MPI_UNSIGNEDLL  MPI_UNSIGNED_LONG_LONG 
Kirill Terekhov's avatar
Kirill Terekhov committed
158
#define INMOST_MPI_Win         MPI_Win
159
#define INMOST_MPI_DATATYPE_NULL MPI_DATATYPE_NULL
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
160
#define INMOST_MPI_GROUP_EMPTY MPI_GROUP_EMPTY
Kirill Terekhov's avatar
Kirill Terekhov committed
161
162
#endif

Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
163
164
165
166
167
168
#if !defined(USE_OMP)
#define INMOST_OMP_LOCK_T      int
#else
#define INMOST_OMP_LOCK_T      omp_lock_t
#endif

169

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

Kirill Terekhov's avatar
Kirill Terekhov committed
172
173
174
175
176
177
178
179
180
181
182
183
#define INMOST_DATA_INTEGER_TYPE  int           
#define INMOST_DATA_REAL_TYPE     double        
#define INMOST_DATA_BULK_TYPE     unsigned char //this should be one byte long

#define INMOST_MPI_DATA_INTEGER_TYPE  INMOST_MPI_INT
#define INMOST_MPI_DATA_REAL_TYPE     INMOST_MPI_DOUBLE
#define INMOST_MPI_DATA_BULK_TYPE     INMOST_MPI_BYTE



#define INMOST_DATA_ENUM_TYPE       unsigned int
#define ENUMUNDEF                 UINT_MAX
184
185
#define INMOST_DATA_BIG_ENUM_TYPE   unsigned long long
#define BIGENUMUNDEF              ULLONG_MAX
Kirill Terekhov's avatar
Kirill Terekhov committed
186
187

#define INMOST_MPI_DATA_ENUM_TYPE      INMOST_MPI_UNSIGNED
188
#define INMOST_MPI_DATA_BIG_ENUM_TYPE  INMOST_MPI_UNSIGNEDLL
Kirill Terekhov's avatar
Kirill Terekhov committed
189
190


191
192
193
/// 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
194
195
196
/// double seconds = Timer();
/// ...some code...
/// seconds = Timer() - seconds;
197
/// std::cout << "Time spent is " << seconds << " seconds." << std::endl;
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
198
double Timer();
Kirill Terekhov's avatar
Kirill Terekhov committed
199
200
201

namespace INMOST
{
202
203
204
205
206
	/// 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
207
208
	enum ErrorType 
	{
209
		/// The list of errors connected to mesh consistency.
Kirill Terekhov's avatar
Kirill Terekhov committed
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
		Failure=100,
		NoTagPosition,
		WrongDataType,
		WrongElementType,
		BadTag,
		BadBulkType,
		NoData,
		TagNotInitialized,
		TagNotFound, 
		TagExists, 
		TagForOtherMesh,
		ElementForOtherMesh,
		ImpossibleConn,
		NoElementType,
		NoMultiElement,
		NoMeshElement,
		NoEsetElement,
		DimensionIsFixed,
		NullInElementSet,		
		NoSpaceForMarker,
		ElementBelongsToNobody,

232
		/// The list of general type errors.
Kirill Terekhov's avatar
Kirill Terekhov committed
233
234
235
236
237
238
239
240
241
242
243
		BadFileName,
		BadFile,		
		CorruptedIerarchy,
		CorruptedOrdering,
		IterForOtherMesh,
		UndefinedBehaviorInGeometry,
		DimensionIsNotSupportedByGeometry,
		NoParallelMode,
		BadParameter,
		TopologyCheckError,
		
244
		/// The list of errors may occur in the Linear Solver.
Kirill Terekhov's avatar
Kirill Terekhov committed
245
246
247
248
249
250
251
252
		ErrorInSolver = 400,
		DataCorruptedInSolver,
		DifferentCommunicatorInSolver,
		MatrixNotSetInSolver,
		InconsistentSizesInSolver,
		IndexesAreDifferentInSolver,
		PrepareMatrixFirst,
		CannotReusePreconditionerOfDifferentSize,
253
		SolverNotFound,
Dmitry Bagaev's avatar
Dmitry Bagaev committed
254
		SolverUnsupportedOperation,
255
		SolverUnknownParameter,
Dmitry Bagaev's avatar
Dmitry Bagaev committed
256
		SolverNonExistentParameters,
257
258
259
260
		SolverCopyNullException,
		SolverCopyException,
        SolverAssignNullException,
        SolverAssignException,
Kirill Terekhov's avatar
Kirill Terekhov committed
261
		
262
		/// The list of errors may occur in the Partitioner.
Kirill Terekhov's avatar
Kirill Terekhov committed
263
264
265
266
		ErrorInPartitioner = 500,
		UnknownWeightSize,
		DistributionTagWasNotFilled,
		
267
268
269
270
271
272
		/// The list of errros that may occur in linear algebra
		MatrixError = 600,
		MatrixCholeskySolveFail,
		MatrixSolveFail,
		MatrixPseudoSolveFail,
		
273
		/// The very tail of the errors list.
Kirill Terekhov's avatar
Kirill Terekhov committed
274
275
276
277
278
279
		NotImplemented = 1000,
		Impossible
	};
}

#include "container.hpp"
Kirill Terekhov's avatar
Kirill Terekhov committed
280
//#include "io.hpp"
Kirill Terekhov's avatar
Kirill Terekhov committed
281
282


283
284
285
286
287
288
289
290
namespace INMOST
{
	template<typename Var>
	class AbstractMatrix;
	
	template<typename Var>
	class SubMatrix;
	
Kirill Terekhov's avatar
Kirill Terekhov committed
291
292
293
	template<typename Var>
	class ConstSubMatrix;
	
294
295
296
297
298
299
	template<typename Var>
	class BlockOfMatrix;
	
	template<typename Var>
	class ConstBlockOfMatrix;
	
300
301
302
303
304
305
306
	template<typename Var, typename Storage = array<Var> >
	class Matrix;
	
	template<typename Var, typename Storage = array<Var> >
	class SymmetricMatrix;
}

307
308
309
310
311
312
#include <cfloat>

static int __isnan__(double x) { return x != x; }
static int __isinf__(double x) { return fabs(x) > DBL_MAX; }
static int __isbad(double x) { return __isnan__(x) || __isinf__(x); }

313

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