common.hpp

Go to the documentation of this file.
00001 /*************************************************************************
00002  * Copyright (C) 2011 by Saleh Dindar and the Swarm-NG Development Team  *
00003  *                                                                       *
00004  * This program is free software; you can redistribute it and/or modify  *
00005  * it under the terms of the GNU General Public License as published by  *
00006  * the Free Software Foundation; either version 3 of the License.        *
00007  *                                                                       *
00008  * This program is distributed in the hope that it will be useful,       *
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00011  * GNU General Public License for more details.                          *
00012  *                                                                       *
00013  * You should have received a copy of the GNU General Public License     *
00014  * along with this program; if not, write to the                         *
00015  * Free Software Foundation, Inc.,                                       *
00016  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00017  ************************************************************************/
00018 
00037 #pragma once
00038 
00039 #ifdef __CUDACC__
00040         // GCC 4.7 bug workaround
00041         #undef _GLIBCXX_ATOMIC_BUILTINS
00042         #undef _GLIBCXX_USE_INT128
00043 #endif
00044 
00045 
00046 // Standard C++ Library
00047 #include <cassert>
00048 #include <cmath>
00049 #include <stdint.h>
00050 #include <cstring>
00051 #include <cstdio>
00052 
00053 // STL
00054 #include <iostream>
00055 #include <fstream>
00056 #include <string>
00057 #include <stdexcept>
00058 #include <map>
00059 #include <vector>
00060 #include <set>
00061 #include <algorithm>
00062 #include <limits>
00063 #ifndef __CUDACC__ 
00064 
00065         // CUDA 2.2 C++ bug workaround
00066         #include <sstream>
00067         #include <valarray>
00068 #endif
00069 
00070 // Boost Libraries
00071 #include <boost/shared_ptr.hpp>
00072 #include <boost/bind.hpp>
00073 
00074 using boost::shared_ptr;
00075 
00076 // CUDA libraries
00077 #include <cuda.h>
00078 #include <cuda_runtime.h>
00079 
00080 
00081 // POSIX headers
00082 #include <errno.h>
00083 #include <sys/types.h>
00084 #include <sys/stat.h>
00085 #include <time.h>
00086 
00087 #include "runtime_error.hpp"
00088 
00089 //
00090 // Struct alignment is handled differently between the CUDA compiler and other
00091 // compilers (e.g. GCC, MS Visual C++ .NET)
00092 //
00093 #ifdef __CUDACC__
00094         #define ALIGN(x)  __align__(x)
00095 #else
00096         #if defined(_MSC_VER) && (_MSC_VER >= 1300)
00097                 // Visual C++ .NET and later
00098                 #define ALIGN(x) __declspec(align(x))
00099         #else
00100                 #if defined(__GNUC__)
00101                         // GCC
00102                         #define ALIGN(x)  __attribute__ ((aligned (x)))
00103                 #else
00104                 // all other compilers
00105                         #define ALIGN(x)
00106                 #endif
00107         #endif
00108 #endif
00109 
00111 #define $$(x) (std::cerr << __FILE__ << "(" << __FUNCTION__ << "):" << __LINE__ << " |> " << (x) << std::endl)
00112 
00113 #define $PRINT(x) (std::cerr << __FILE__ <<  __LINE__ << ": " << x << std::endl)
00114 
00116 #define $_(x) (std::cerr << __FILE__ << "(" << __FUNCTION__ << "):" << __LINE__ <<  " " << (#x) << " = " << (x) << std::endl)
00117 
00119 #define $$$ (std::cerr << __FILE__ << "(" << __FUNCTION__ << "):" << __LINE__ << " @@ " << std::endl)
00120 #define SYNC cudaThreadSynchronize()
00121 

doxygen