blitz Version 1.0.2
Loading...
Searching...
No Matches
blitz.h
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 * blitz/blitz.h Includes all the important header files
4 *
5 * $Id$
6 *
7 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
8 *
9 * This file is a part of Blitz.
10 *
11 * Blitz is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation, either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * Blitz is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * Suggestions: blitz-devel@lists.sourceforge.net
25 * Bugs: blitz-support@lists.sourceforge.net
26 *
27 * For more information, please see the Blitz++ Home Page:
28 * https://sourceforge.net/projects/blitz/
29 *
30 ***************************************************************************/
31
32#ifndef BZ_BLITZ_H
33#define BZ_BLITZ_H
34
35/*
36 * These symbols allow use of the IEEE and System V math libraries
37 * (libm.a and libmsaa.a) on some platforms.
38 */
39
40#ifdef BZ_ENABLE_XOPEN_SOURCE
41 #ifndef _ALL_SOURCE
42 #define _ALL_SOURCE
43 #endif
44 #ifndef _XOPEN_SOURCE
45 #define _XOPEN_SOURCE
46 #endif
47 #ifndef _XOPEN_SOURCE_EXTENDED
48 #define _XOPEN_SOURCE_EXTENDED 1
49 #endif
50#endif
51
52#include <blitz/bzconfig.h>
53#include <blitz/compiler.h> // Compiler-specific directives
54#include <blitz/tuning.h> // Performance tuning
55#include <blitz/tau.h> // Profiling
56
57#ifdef BZ_HAVE_STL
58 #include <string>
59#endif
60
61#ifdef BZ_HAVE_STD
62 #include <iostream>
63 #include <iomanip>
64 #include <cstdio> // sprintf, etc.
65 #include <cmath>
66#else
67 #include <iostream.h>
68 #include <iomanip.h>
69 #include <stdio.h> // sprintf, etc.
70 #include <math.h>
71#endif
72
73#ifdef BZ_HAVE_COMPLEX
74 #include <complex>
75#endif
76
77#define BZ_THROW // Needed in <blitz/numinquire.h>
78
79// This macro is needed to pass template types to macros, since macros
80// don't recognize <> as parentheses.
81#define bzCC(...) __VA_ARGS__
82
83namespace blitz {
84
85#ifdef BZ_HAVE_STD
86 using namespace std;
87#endif
88
89#ifdef BZ_GENERATE_GLOBAL_INSTANCES
90 #define _bz_global
91 #define BZ_GLOBAL_INIT(X) =X
92#else
93 #define _bz_global extern
94 #define BZ_GLOBAL_INIT(X)
95#endif
96
97/* Define types for indexing, depending on whether 64- or 32-bit
98 indices are desired. There are separate typedefs for sizeType and
99 indexType, because it might be useful to have possibility of arrays
100 with 64-bit numbers of elements without paying the size overhead of
101 making all dimensional indexes 64-bit.
102 */
103// Used for dimensional indexes (not implemented yet).
104#ifdef BZ_FULLY64BIT
105#warning 64-bit array dimensions not yet implemented
106typedef ptrdiff_t indexType;
107#else
108typedef int indexType;
109#endif
110typedef size_t sizeType; // Used for memory indexing
111typedef ptrdiff_t diffType; // Used for memory index differences, ie strides
112
113// set the default padding policy
114#ifdef BZ_PAD_ARRAYS
115#define BZ_PADDING_DEFAULT paddedData
116#else
117#define BZ_PADDING_DEFAULT contiguousData
118#endif
119
120}
121
122/*
123 * Thread safety issues. Compiling with -pthread under gcc, or -mt
124 * under solaris, should automatically define _REENTRANT. Also have
125 * support for OpenMP (which defines _OPENMP) or Windows thread
126 * implementation. The --enable-threadsafe configure option now
127 * defines BZ_THREADSAFE. If this is defined but no thread support is
128 * detected when compiling, we call #error below.
129 */
130
131/*
132 * Which mutex implementation should be used for synchronizing
133 * reference counts. Options are Thread Building Block Atomics (which
134 * is preferred over the others), pthreads, OpenMP, or Windows
135 * threads. If we use TBB, the mutex macros are empty since it
136 * requires no locking.
137 */
138#ifdef BZ_THREADSAFE
139 #ifdef BZ_THREADSAFE_USE_TBB
140 #include "tbb/atomic.h"
141 #define BZ_THREADSAFE_USE_ATOMIC
142 #define BZ_REFCOUNT_DECLARE(name) tbb::atomic<int> name;
143 #else
144 #define BZ_REFCOUNT_DECLARE(name) volatile int name;
145 #if defined(_REENTRANT)
146 #define BZ_THREADSAFE_USE_PTHREADS
147 #elif defined (_OPENMP)
148 #define BZ_THREADSAFE_USE_OPENMP
149 #elif defined(_WIN32)
150 #define BZ_THREADSAFE_USE_WINDOWS
151 #else
152 #error Blitz is configured with --enable-threadsafe, but no compiler thread support is found. Did you forget, e.g., "--pthread"?
153 #endif
154 #endif
155#else
156 #define BZ_REFCOUNT_DECLARE(name) int name;
157#endif
158
159
160#ifdef BZ_THREADSAFE_USE_PTHREADS
161 #include <pthread.h>
162
163 #define BZ_MUTEX_DECLARE(name) mutable pthread_mutex_t name;
164 #define BZ_MUTEX_INIT(name) pthread_mutex_init(&name,NULL); mutexLocking_ = true;
165
166 #define BZ_MUTEX_LOCK(name) if (mutexLocking_) pthread_mutex_lock(&name);
167 #define BZ_MUTEX_UNLOCK(name) if (mutexLocking_) pthread_mutex_unlock(&name);
168 #define BZ_MUTEX_DESTROY(name) pthread_mutex_destroy(&name);
169#elif defined (BZ_THREADSAFE_USE_WINDOWS)
170 // Include Windows.h header in case user has not already done so.
171 // Disable Windows min/max macro definitions
172 #define NOMINMAX
173 #include <Windows.h>
174
175 #define BZ_MUTEX_DECLARE(name) mutable CRITICAL_SECTION name;
176 #define BZ_MUTEX_INIT(name) ::InitializeCriticalSection(&name); mutexLocking_ = true;
177 #define BZ_MUTEX_LOCK(name) if (mutexLocking_) ::EnterCriticalSection(&name);
178 #define BZ_MUTEX_UNLOCK(name) if (mutexLocking_) ::LeaveCriticalSection(&name);
179 #define BZ_MUTEX_DESTROY(name) ::DeleteCriticalSection(&name);
180#elif defined (BZ_THREADSAFE_USE_OPENMP)
181 #include <omp.h>
182
183 #define BZ_MUTEX_DECLARE(name) mutable omp_lock_t name;
184 #define BZ_MUTEX_INIT(name) omp_init_lock(&name); mutexLocking_ = true;
185 #define BZ_MUTEX_LOCK(name) if (mutexLocking_) omp_set_lock(&name);
186 #define BZ_MUTEX_UNLOCK(name) if (mutexLocking_) omp_unset_lock(&name);
187 #define BZ_MUTEX_DESTROY(name) omp_destroy_lock(&name);
188#else
189 #define BZ_MUTEX_DECLARE(name)
190 #define BZ_MUTEX_INIT(name)
191 #define BZ_MUTEX_LOCK(name)
192 #define BZ_MUTEX_UNLOCK(name)
193 #define BZ_MUTEX_DESTROY(name)
194#endif
195
196#include <blitz/bzdebug.h> // Debugging macros
197
198#endif // BZ_BLITZ_H
Definition: array-impl.h:66
ptrdiff_t diffType
Definition: blitz.h:111
size_t sizeType
Definition: blitz.h:110
int indexType
Definition: blitz.h:108