diff --git a/src/core/tamaas.hh b/src/core/tamaas.hh index c272afd..a97c5c3 100644 --- a/src/core/tamaas.hh +++ b/src/core/tamaas.hh @@ -1,176 +1,167 @@ /** * @mainpage Welcome to Tamaas ! * * @section Introduction * Tamaas is a spectral-boundary-element based contact library. It is made with * love to be fast and friendly! * * @author Guillaume Anciaux * @author Lucas Frérot * @author Valentine Rey * * @section LICENSE * * Copyright (©) 2016-2017 EPFL (Ecole Polytechnique Fédérale de * Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des * Solides) * * Tamaas is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Tamaas. If not, see . * */ /* -------------------------------------------------------------------------- */ #ifndef __TAMAAS_HH__ #define __TAMAAS_HH__ /* -------------------------------------------------------------------------- */ #include #include #include #include #include #include /* -------------------------------------------------------------------------- */ #ifdef USE_CUDA #include "unified_allocator.hh" #include #endif /// Namespace macros #define __BEGIN_TAMAAS__ namespace tamaas { #define __END_TAMAAS__ } /// Standard definitions pulled from C++14 namespace std { #if __cplusplus < 201402L /// exchange template T exchange(T& obj, U&& new_value) { T old_value = move(obj); obj = forward(new_value); return old_value; } /// make_unique template unique_ptr make_unique(Args&&... args) { return unique_ptr(new T(forward(args)...)); } #endif } /* -------------------------------------------------------------------------- */ __BEGIN_TAMAAS__ /* -------------------------------------------------------------------------- */ #ifdef USE_CUDA #define DEFAULT_ALLOCATOR UnifiedAllocator #define CUDA_LAMBDA __device__ __host__ #else #define DEFAULT_ALLOCATOR std::allocator #define __global__ #define __host__ #define __device__ #define CUDA_LAMBDA #endif /// Common types definitions using Real = double; using UInt = unsigned int; using Int = int; #ifdef USE_CUDA template using complex = thrust::complex; #else template using complex = std::complex; #endif using Complex = complex; static constexpr Real zero_threshold = 1e-14; /* -------------------------------------------------------------------------- */ /// initialize tamaas (0 threads => let OMP_NUM_THREADS decide) void initialize(UInt num_threads = 0); /// cleanup tamaas void finalize(); /* -------------------------------------------------------------------------- */ -// template -// __device__ __host__ complex conjugate(const complex & z) { -// #ifdef USE_CUDA -// return thrust::conj(z); -// #else -// return std::conj(z); -// #endif -// } - #ifdef USE_CUDA using ::thrust::conj; using ::thrust::sqrt; using ::thrust::norm; #endif using ::std::conj; using ::std::sqrt; using ::std::norm; /* -------------------------------------------------------------------------- */ /// Generic exception class class Exception : public std::exception { public: /// Constructor Exception(const std::string & mesg):msg(mesg) {} virtual const char* what() const noexcept { return msg.c_str(); } virtual ~Exception() = default; private: std::string msg; }; /* -------------------------------------------------------------------------- */ /// Enumeration of reduction operations enum class operation { plus, times, min, max }; /* -------------------------------------------------------------------------- */ __END_TAMAAS__ /* -------------------------------------------------------------------------- */ #define TAMAAS_EXCEPTION(mesg) { \ std::stringstream sstr; \ sstr \ << __FILE__ \ << ":" << __LINE__ << ":FATAL: " \ << mesg << std::endl; \ std::cerr.flush(); \ throw ::tamaas::Exception(sstr.str()); \ } #define SURFACE_FATAL(mesg) TAMAAS_EXCEPTION(mesg) #if defined(TAMAAS_DEBUG) #define TAMAAS_ASSERT(cond, reason) do { \ if (!(cond)) { \ TAMAAS_EXCEPTION(#cond " assert failed: " << reason); \ } } while(0) #define TAMAAS_DEBUG_EXCEPTION(reason) TAMAAS_EXCEPTION(reason) #else #define TAMAAS_ASSERT(cond, reason) #define TAMAAS_DEBUG_EXCEPTION(reason) #endif #define TAMAAS_ACCESSOR(var, type, name) type & get##name() { return var; } \ void set##name(const type & new_var) { var = new_var; } /* -------------------------------------------------------------------------- */ #endif // TAMAAS_HH