diff --git a/AMDiS/cmake3/AMDIS.cmake.in b/AMDiS/cmake3/AMDIS.cmake.in index 0d3dfa26c24392590c726d57d011e5a76eda8c60..5f4aa43a8f3a983c10a6d7b9a9a03c72199987af 100644 --- a/AMDiS/cmake3/AMDIS.cmake.in +++ b/AMDiS/cmake3/AMDIS.cmake.in @@ -12,7 +12,6 @@ set(AMDIS_NEED_PNG @ENABLE_PNG@) set(AMDIS_NEED_SEQ_PETSC @ENABLE_SEQ_PETSC@) set(BUILD_SHARED_LIBS @BUILD_SHARED_LIBS@) -set(CMAKE_BUILD_TYPE @CMAKE_BUILD_TYPE@) add_library(amdis_base INTERFACE) add_library(AMDiS ALIAS amdis_base) @@ -20,10 +19,14 @@ add_library(AMDiS ALIAS amdis_base) target_compile_definitions(amdis_base INTERFACE) if (AMDIS_NEED_CXX11) - target_enable_cxx11(AMDIS_NEED_CXX11 amdis_base INTERFACE) - if (NOT AMDIS_NEED_CXX11) + target_enable_cxx14(SUPPORTS_CXX14 amdis_base INTERFACE) + if (NOT SUPPORTS_CXX14) + target_enable_cxx11(SUPPORTS_CXX11 amdis_base INTERFACE) + endif () + + if (NOT SUPPORTS_CXX11 AND NOT SUPPORTS_CXX14) message(FATAL_ERROR "AMDiS was compiled with c++11 support, but the current compiler does not support this feature!") - endif (NOT AMDIS_NEED_CXX11) + endif () target_compile_definitions(amdis_base INTERFACE AMDIS_HAS_CXX11=1) else () target_compile_definitions(amdis_base INTERFACE AMDIS_HAS_CXX11=0) diff --git a/AMDiS/cmake3/target_enable_cxx11.cmake b/AMDiS/cmake3/target_enable_cxx11.cmake index 687fb51ecfda7a590d36349271730271d04644fd..13c5819bcd39556bb09c8e922933374ee6758f1c 100644 --- a/AMDiS/cmake3/target_enable_cxx11.cmake +++ b/AMDiS/cmake3/target_enable_cxx11.cmake @@ -1,6 +1,37 @@ include(CheckCXXCompilerFlag) include(CheckCXXSourceCompiles) +macro(target_enable_cxx14 RESULT_VAR _TARGET_ _SCOPE_) + check_cxx_compiler_flag("-std=c++14" COMPILER_SUPPORTS_CXX14_FLAG) + + set(CXX14_CODE " + auto f() { return 1; } + int main(){ + auto f1 = [](auto const& y) { return y; }; + auto y0 = f(); + auto y1 = f1(1); + }") + + if (COMPILER_SUPPORTS_CXX14_FLAG) + set(CMAKE_REQUIRED_FLAGS "-std=c++14") + check_cxx_source_compiles("${CXX14_CODE}" CXX14_COMPILES_WITH_CXX14_FLAG) + set(CMAKE_REQUIRED_FLAGS "") + endif () + + if (COMPILER_SUPPORTS_CXX14_FLAG AND CXX14_COMPILES_WITH_CXX14_FLAG) + target_compile_options(${_TARGET_} ${_SCOPE_} "-std=c++14") + set(${RESULT_VAR} true CACHE BOOL "Enable C++14 compiler features" FORCE) + else () + check_cxx_source_compiles("${CXX14_CODE}" CXX14_COMPILES) + + if (CXX14_COMPILES) + set(${RESULT_VAR} true CACHE BOOL "Enable C++14 compiler features" FORCE) + else () + set(${RESULT_VAR} false CACHE BOOL "Enable C++14 compiler features" FORCE) + endif () + endif () +endmacro(target_enable_cxx14) + macro(target_enable_cxx11 RESULT_VAR _TARGET_ _SCOPE_) check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11_FLAG) diff --git a/AMDiS/src/AMDiS.cc b/AMDiS/src/AMDiS.cc index 897250554df76da57dc5a30df5353445f7d07301..5e97c4a56224bdc010ceab7a59b5b2ecb4b18d3c 100644 --- a/AMDiS/src/AMDiS.cc +++ b/AMDiS/src/AMDiS.cc @@ -115,7 +115,7 @@ namespace AMDiS { Parameters::init(initFileName); } -#ifdef HAVE_PARALLEL_DOMAIN_AMDIS +#if defined(HAVE_PARALLEL_DOMAIN_AMDIS) || defined(HAVE_OPENMP) Parameters::get("parallel->log main rank", Msg::outputMainRank); #endif diff --git a/AMDiS/src/CouplingProblemStat.h b/AMDiS/src/CouplingProblemStat.h index a7d5cabc4da3a78a69fdadeee92e2a0a754a5875..a32073a9af69ab4e4ba1b04d6ecacab7ca193b16 100644 --- a/AMDiS/src/CouplingProblemStat.h +++ b/AMDiS/src/CouplingProblemStat.h @@ -75,8 +75,7 @@ namespace AMDiS { virtual void initialize(Flag initFlag, ProblemStatSeq *adoptProblem = NULL, Flag adoptFlag = INIT_NOTHING) - { FUNCNAME("CouplingProblemStat::initialize()"); - + { super::initialize(initFlag - INIT_MESH); const Flag DEFAULT_INIT = (INIT_FE_SPACE | INIT_MESH | CREATE_MESH | INIT_SYSTEM | INIT_SOLVER | INIT_ESTIMATOR | INIT_MARKER | INIT_FILEWRITER); @@ -130,7 +129,7 @@ namespace AMDiS { problems[i]->componentMeshes.resize(nComponents + nAddComponents); - for (size_t j = 0; j < nComponents + nAddComponents; j++) { + for (int j = 0; j < nComponents + nAddComponents; j++) { // name of the mesh std::string meshName(""); Parameters::get(problems[i]->getName() + "->mesh", meshName); @@ -186,7 +185,7 @@ namespace AMDiS { problems[p]->componentSpaces.resize(nComponents + nAddComponents, NULL); problems[p]->traverseInfo.resize(nComponents); - for (size_t i = 0; i < nComponents + nAddComponents; i++) { + for (int i = 0; i < nComponents + nAddComponents; i++) { std::string componentString = "[" + to_string(i) + "]"; diff --git a/AMDiS/src/Global.cc b/AMDiS/src/Global.cc index bace7aee050dbb5d8f314178504325654d01c6ae..42fc8e60c8e485f2fe6ed453c6be8d21cbed23d6 100644 --- a/AMDiS/src/Global.cc +++ b/AMDiS/src/Global.cc @@ -32,11 +32,14 @@ #ifdef HAVE_PARALLEL_PETSC #include "petsc.h" #endif +#ifdef HAVE_OPENMP +#include <omp.h> +#endif namespace AMDiS { const char *funcName = NULL; -#ifdef HAVE_PARALLEL_DOMAIN_AMDIS +#if defined(HAVE_PARALLEL_DOMAIN_AMDIS) || defined(HAVE_OPENMP) bool Msg::outputMainRank = true; #endif @@ -133,6 +136,10 @@ namespace AMDiS { if (outputMainRank && MPI::COMM_WORLD.Get_rank() != 0) return; #endif +#ifdef HAVE_OPENMP + if (outputMainRank && omp_get_thread_num() != 0) + return; +#endif if (!out) out = &std::cout; @@ -224,6 +231,10 @@ namespace AMDiS { if (outputMainRank && MPI::COMM_WORLD.Get_rank() != 0) return; #endif +#ifdef HAVE_OPENMP + if (outputMainRank && omp_get_thread_num() != 0) + return; +#endif static int old_line = -1; @@ -257,6 +268,10 @@ namespace AMDiS { #if defined(HAVE_PARALLEL_DOMAIN_AMDIS) && defined(NDEBUG) if (outputMainRank && MPI::COMM_WORLD.Get_rank() != 0) return; +#endif +#ifdef HAVE_OPENMP + if (outputMainRank && omp_get_thread_num() != 0) + return; #endif va_list arg; char buff[255]; @@ -278,6 +293,10 @@ namespace AMDiS { if (outputMainRank && MPI::COMM_WORLD.Get_rank() != 0) return; #endif +#ifdef HAVE_OPENMP + if (outputMainRank && omp_get_thread_num() != 0) + return; +#endif va_list arg; char buff[255]; diff --git a/AMDiS/src/Global.h b/AMDiS/src/Global.h index 9c20ce4b368c394b9c9e9ca038d8674e3b159326..18f3967316b34309f0825d396d95db056e44176b 100644 --- a/AMDiS/src/Global.h +++ b/AMDiS/src/Global.h @@ -133,6 +133,8 @@ namespace AMDiS { #else #if HAVE_PARALLEL_DOMAIN_AMDIS #define PRINT_LINE(stream, line) stream << "[" << MPI::COMM_WORLD.Get_rank() << "] " << line +#elif defined(HAVE_OPENMP) +#define PRINT_LINE(stream, line) stream << "[" << omp_get_thread_num() << "] " << line #else #define PRINT_LINE(stream, line) stream << line #endif @@ -331,7 +333,7 @@ namespace AMDiS { } public: -#if HAVE_PARALLEL_DOMAIN_AMDIS +#if defined(HAVE_PARALLEL_DOMAIN_AMDIS) || defined(HAVE_OPENMP) /// In parallel computations, when this variable is true, only the 0 rank will /// print messages to the output stream. Error messages and warnings are always /// printed from all ranks. diff --git a/AMDiS/src/expressions/functorN_expr.hpp b/AMDiS/src/expressions/functorN_expr.hpp index 8692faefb745c8f3f9a586b677c16e4c5ffaf21a..e60ba4d2e1431e22df1fd4a80d83239f7f351605 100644 --- a/AMDiS/src/expressions/functorN_expr.hpp +++ b/AMDiS/src/expressions/functorN_expr.hpp @@ -201,8 +201,7 @@ namespace AMDiS { std::tuple<Terms...> term_tuple; - template <class... Terms_> - LazyOperatorTerms(Terms_... terms_) + LazyOperatorTerms(Terms const&... terms_) : term_tuple(terms_...) { } @@ -249,8 +248,7 @@ namespace AMDiS F f; ///< the functor - template <class... Terms_> - FunctionN(F const& f_, Terms_... terms_) + FunctionN(F const& f_, Terms const&... terms_) : super(terms_...), f(f_) {} // call f.getDegree() function @@ -404,7 +402,7 @@ namespace AMDiS template<typename F, typename... Terms> inline typename result_of::FunctionN<F, Terms...>::type - function_(F const& f, Terms... ts) + function_(F const& f, Terms const&... ts) { return expressions::FunctionN<F, typename traits::to_expr<Terms>::to::type...> (f, traits::to_expr<Terms>::to::get(ts)...); @@ -412,7 +410,7 @@ namespace AMDiS template<typename F, typename... Terms> inline typename result_of::FunctionN<F, Terms...>::type - func(F const& f, Terms... ts) + func(F const& f, Terms const&... ts) { return expressions::FunctionN<F, typename traits::to_expr<Terms>::to::type...> (f, traits::to_expr<Terms>::to::get(ts)...); @@ -420,7 +418,7 @@ namespace AMDiS template<typename F, typename Term0, typename... Terms> inline typename result_of::FunctionN<F, Term0, Terms...>::type - eval(F const& f, Term0 t0, Terms... ts) + eval(F const& f, Term0 t0, Terms const&... ts) { return expressions::FunctionN<F, typename traits::to_expr<Term0>::to::type, typename traits::to_expr<Terms>::to::type...> diff --git a/AMDiS/src/expressions/valueOf.hpp b/AMDiS/src/expressions/valueOf.hpp index cbf17a9a6b0979f5b689232d04157f688a05d542..0306d536604a5646fb6ac48b6ccdf676f236624a 100644 --- a/AMDiS/src/expressions/valueOf.hpp +++ b/AMDiS/src/expressions/valueOf.hpp @@ -212,7 +212,7 @@ namespace AMDiS /// Expressions that extracts the vector-value of a Vector<DOFVector> at QPs - template<template<class> class Vector, typename T, typename Name> + template<template<class...> class Vector, typename T, typename Name> struct ValueOf<Vector<DOFVector<T>*>, Name, typename boost::enable_if<typename traits::is_vector<Vector<T> >::type>::type > : public LazyOperatorTermBase @@ -224,7 +224,12 @@ namespace AMDiS mutable mtl::dense_vector<value_type> vec; mutable Vector<mtl::dense_vector<T> > coeff; - ValueOf(Vector<DOFVector<T>*>& vector) : vecDV(vector) + ValueOf(Vector<DOFVector<T>*> const& vector) : vecDV(vector) + { + resize(coeff, num_rows(vecDV)); + } + + ValueOf(Vector<DOFVector<T>*>&& vector) : vecDV(std::move(vector)) { resize(coeff, num_rows(vecDV)); } @@ -232,7 +237,7 @@ namespace AMDiS template<typename List> inline void insertFeSpaces(List& feSpaces) const { - for (size_t i = 0; i < num_rows(vecDV); i++) + for (size_t i = 0; i < size_t(num_rows(vecDV)); i++) feSpaces.insert(at(vecDV, i)->getFeSpace()); } @@ -247,7 +252,7 @@ namespace AMDiS const BasisFunction *basisFct = NULL) { Vector<mtl::dense_vector<T> > helper; resize(helper, num_rows(vecDV)); - for (size_t i = 0; i < num_rows(vecDV); i++) { + for (size_t i = 0; i < size_t(num_rows(vecDV)); i++) { if (ot && subAssembler) ot->getVectorAtQPs(at(vecDV, i), elInfo, subAssembler, quad, at(helper, i)); else if (quad) @@ -269,7 +274,7 @@ namespace AMDiS vec.change_dim(num_rows(at(helper, 0))); for (size_t iq = 0; iq < num_rows(at(helper, 0)); iq++) { value_type tmp; resize(tmp, num_rows(vecDV)); - for (size_t i = 0; i < num_rows(vecDV); i++) + for (size_t i = 0; i < size_t(num_rows(vecDV)); i++) at(tmp, i) = at(helper, i)[iq]; vec[iq] = tmp; } @@ -415,7 +420,7 @@ namespace AMDiS valueOf(Matrix<DOFVector<T>*> &mat) { return expressions::ValueOf<Matrix<DOFVector<T>*>, _unknown >(mat); } - template<template<class> class Vector, typename T> + template<template<class...> class Vector, typename T> typename boost::enable_if<typename traits::is_vector<Vector<T> >::type, expressions::ValueOf<Vector<DOFVector<T>*>, _unknown > >::type valueOf(Vector<DOFVector<T>*> &vector) diff --git a/AMDiS/src/io/detail/Arh3Writer.h b/AMDiS/src/io/detail/Arh3Writer.h index 61986009adf2fb904f628d59e9d2f08e34298f0c..aa75baa947ce3984724730bb579fc930e80fb606 100644 --- a/AMDiS/src/io/detail/Arh3Writer.h +++ b/AMDiS/src/io/detail/Arh3Writer.h @@ -20,7 +20,7 @@ namespace AMDiS { namespace io { ZLIB = 1, // zlib compression BZIP2 = 2 // bzip2 compression } Value; - }; + } namespace Macroformat { @@ -29,7 +29,7 @@ namespace AMDiS { namespace io { PT_MACROFILE = 1, // pointer to macro file SELF = 2 // pointer to this file, at the end of this file } Value; - }; + } typedef enum{SI08, SI16, SI32, SI64, UI08, UI16, UI32, UI64, SF32, SF64} Valformat; diff --git a/extensions/VectorOperations.h b/extensions/VectorOperations.h index 71dcc888345ade92a4238ad86b9bf5d62e31043b..5616be83c8a37c5567fe09727e68d10ada5a7fb4 100644 --- a/extensions/VectorOperations.h +++ b/extensions/VectorOperations.h @@ -112,7 +112,7 @@ namespace vector_operations { { typename ValueType<Vector>::type value; nullify(value); - for (size_t i = 0; i < num_rows(b); ++i) + for (size_t i = 0; i < size_t(num_rows(b)); ++i) value += sqr(b[i]); return std::sqrt(value); }