inmost_common.h 7.85 KB
Newer Older
Kirill Terekhov's avatar
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 17 18

#define USE_MESH

#define USE_PARTITIONER
//#define USE_PARTITIONER_ZOLTAN
//#define USE_PARTITIONER_PARMETIS

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

120 121 122 123 124 125

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

#if !defined(USE_MPI)
#define INMOST_MPI_Request     int
#define INMOST_MPI_Type        int
#define INMOST_MPI_Comm        int
Kirill Terekhov's avatar
Kirill Terekhov committed
132
#define INMOST_MPI_Group       int
Kirill Terekhov's avatar
Kirill Terekhov committed
133
#define INMOST_MPI_COMM_WORLD  0
134
#define INMOST_MPI_COMM_SELF  0
Kirill Terekhov's avatar
Kirill Terekhov committed
135 136 137 138 139
#define INMOST_MPI_BYTE        0
#define INMOST_MPI_INT         0
#define INMOST_MPI_DOUBLE      0
#define INMOST_MPI_UNSIGNED    0
#define INMOST_MPI_Win         int
140
#define INMOST_MPI_DATATYPE_NULL 0
Kirill Terekhov's avatar
Kirill Terekhov committed
141
#define INMOST_MPI_GROUP_EMPTY 0
Kirill Terekhov's avatar
Kirill Terekhov committed
142 143 144 145
#else
#define INMOST_MPI_Request     MPI_Request
#define INMOST_MPI_Type        MPI_Datatype
#define INMOST_MPI_Comm        MPI_Comm
Kirill Terekhov's avatar
Kirill Terekhov committed
146
#define INMOST_MPI_Group       MPI_Group
Kirill Terekhov's avatar
Kirill Terekhov committed
147
#define INMOST_MPI_COMM_WORLD  MPI_COMM_WORLD
148
#define INMOST_MPI_COMM_SELF   MPI_COMM_SELF
Kirill Terekhov's avatar
Kirill Terekhov committed
149 150 151 152 153
#define INMOST_MPI_BYTE        MPI_BYTE
#define INMOST_MPI_INT         MPI_INT
#define INMOST_MPI_DOUBLE      MPI_DOUBLE
#define INMOST_MPI_UNSIGNED    MPI_UNSIGNED
#define INMOST_MPI_Win         MPI_Win
154
#define INMOST_MPI_DATATYPE_NULL MPI_DATATYPE_NULL
Kirill Terekhov's avatar
Kirill Terekhov committed
155
#define INMOST_MPI_GROUP_EMPTY MPI_GROUP_EMPTY
Kirill Terekhov's avatar
Kirill Terekhov committed
156 157
#endif

Kirill Terekhov's avatar
Kirill Terekhov committed
158 159 160 161 162 163
#if !defined(USE_OMP)
#define INMOST_OMP_LOCK_T      int
#else
#define INMOST_OMP_LOCK_T      omp_lock_t
#endif

164

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

Kirill Terekhov's avatar
Kirill Terekhov committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
#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
#define INMOST_DATA_BIG_ENUM_TYPE   unsigned int
#define BIGENUMUNDEF              UINT_MAX

#define INMOST_MPI_DATA_ENUM_TYPE      INMOST_MPI_UNSIGNED
#define INMOST_MPI_DATA_BIG_ENUM_TYPE  INMOST_MPI_UNSIGNED


186 187 188
/// 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
189 190 191
/// double seconds = Timer();
/// ...some code...
/// seconds = Timer() - seconds;
192
/// std::cout << "Time spent is " << seconds << " seconds." << std::endl;
Kirill Terekhov's avatar
Kirill Terekhov committed
193
double Timer();
Kirill Terekhov's avatar
Kirill Terekhov committed
194 195 196

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

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

#include "container.hpp"
275
//#include "io.hpp"
Kirill Terekhov's avatar
Kirill Terekhov committed
276 277


278 279 280 281 282 283 284 285
namespace INMOST
{
	template<typename Var>
	class AbstractMatrix;
	
	template<typename Var>
	class SubMatrix;
	
286 287 288
	template<typename Var>
	class ConstSubMatrix;
	
289 290 291 292 293 294 295
	template<typename Var, typename Storage = array<Var> >
	class Matrix;
	
	template<typename Var, typename Storage = array<Var> >
	class SymmetricMatrix;
}

296 297 298 299 300 301
#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); }

302

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