Swarm-NG  1.1
common.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2011 by Saleh Dindar and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
37 #pragma once
38 
39 #ifdef __CUDACC__
40  // GCC 4.7 bug workaround
41  #if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 7))
42  #undef _GLIBCXX_ATOMIC_BUILTINS
43  #endif
44  #undef _GLIBCXX_USE_INT128
45 #endif
46 
47 
48 // Standard C++ Library
49 #include <cassert>
50 #include <cmath>
51 #include <stdint.h>
52 #include <cstring>
53 #include <cstdio>
54 
55 // STL
56 #include <iostream>
57 #include <fstream>
58 #include <string>
59 #include <stdexcept>
60 #include <map>
61 #include <vector>
62 #include <set>
63 #include <algorithm>
64 #include <limits>
65 #ifndef __CUDACC__
66 
67  // CUDA 2.2 C++ bug workaround
68  #include <sstream>
69  #include <valarray>
70 #endif
71 
72 // TODO: this is a dirty fix
73 #ifdef __CUDACC__
74 //#define __int128 long long
75 #undef __SIZEOF_INT128__
76 #endif
77 
78 // Boost Libraries
79 #include <boost/shared_ptr.hpp>
80 #include <boost/bind.hpp>
81 
82 using boost::shared_ptr;
83 
84 
85 // CUDA libraries
86 #include <cuda.h>
87 #include <cuda_runtime.h>
88 
89 
90 // POSIX headers
91 #include <errno.h>
92 #include <sys/types.h>
93 #include <sys/stat.h>
94 #include <time.h>
95 
96 #include "runtime_error.hpp"
97 
98 //
99 // Struct alignment is handled differently between the CUDA compiler and other
100 // compilers (e.g. GCC, MS Visual C++ .NET)
101 //
102 #ifdef __CUDACC__
103  #define ALIGN(x) __align__(x)
104 #else
105  #if defined(_MSC_VER) && (_MSC_VER >= 1300)
106  // Visual C++ .NET and later
107  #define ALIGN(x) __declspec(align(x))
108  #else
109  #if defined(__GNUC__)
110  // GCC
111  #define ALIGN(x) __attribute__ ((aligned (x)))
112  #else
113  // all other compilers
114  #define ALIGN(x)
115  #endif
116  #endif
117 #endif
118 
120 #define $$(x) (std::cerr << __FILE__ << "(" << __FUNCTION__ << "):" << __LINE__ << " |> " << (x) << std::endl)
121 
122 #define $PRINT(x) (std::cerr << __FILE__ << __LINE__ << ": " << x << std::endl)
123 
125 #define $_(x) (std::cerr << __FILE__ << "(" << __FUNCTION__ << "):" << __LINE__ << " " << (#x) << " = " << (x) << std::endl)
126 
128 #define $$$ (std::cerr << __FILE__ << "(" << __FUNCTION__ << "):" << __LINE__ << " @@ " << std::endl)
129 #define SYNC cudaThreadSynchronize()
130