From ba996334664c402a0993a1fca1a8ad45b1b13f09 Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Tue, 11 Jun 2019 16:37:27 -0400 Subject: [PATCH 1/5] Include Func1.h in zerodim.h zerodim.h used to have Func1.h included indirectly, so make it explicit. --- include/cantera/zerodim.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/cantera/zerodim.h b/include/cantera/zerodim.h index 0a74333736..2265f19e9a 100644 --- a/include/cantera/zerodim.h +++ b/include/cantera/zerodim.h @@ -7,7 +7,7 @@ #define CT_INCL_ZERODIM_H // reactor network -#include "zeroD/ReactorNet.h" +#include "cantera/zeroD/ReactorNet.h" // reactors #include "cantera/zeroD/Reservoir.h" @@ -31,4 +31,7 @@ #include "cantera/zeroD/FlowDeviceFactory.h" #include "cantera/zeroD/WallFactory.h" +// func1 +#include "cantera/numerics/Func1.h" + #endif From 851d31bdbe89fb7e2b1eff256fd438ee416f6d18 Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Tue, 11 Jun 2019 16:55:12 -0400 Subject: [PATCH 2/5] Include boost_inc_dir when building the samples --- samples/cxx/SConscript | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/cxx/SConscript b/samples/cxx/SConscript index 2bc2427da4..0a6a91bdb7 100644 --- a/samples/cxx/SConscript +++ b/samples/cxx/SConscript @@ -30,8 +30,7 @@ set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}) buildSample(localenv.Program, pjoin(subdir, name), mglob(localenv, subdir, *extensions), - CPPPATH=['#include'], - LIBS=env['cantera_libs']) + CPPPATH=['#include', env['boost_inc_dir']]) # Note: These Makefiles and SConstruct files are automatically installed # by the "RecursiveInstall" that grabs everything in the cxx directory. From a36b16d0eae38a53ba89c5bdab5fc2cf2739bd1a Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Tue, 11 Jun 2019 17:10:56 -0400 Subject: [PATCH 3/5] CMake use Accelerate even if OpenMP is also used For samples, make sure that OpenMP and Accelerate are not exclusive options on macOS --- samples/cxx/SConscript | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/cxx/SConscript b/samples/cxx/SConscript index 0a6a91bdb7..c614cbd517 100644 --- a/samples/cxx/SConscript +++ b/samples/cxx/SConscript @@ -23,11 +23,12 @@ find_package(OpenMP REQUIRED) set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}) set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}) """ - elif env["OS"] == "Darwin": - localenv["cmake_extra"] = "find_library(ACCELERATE_FRAMEWORK Accelerate)" else: localenv['cmake_extra'] = '' + if env["OS"] == "Darwin": + localenv["cmake_extra"] += "find_library(ACCELERATE_FRAMEWORK Accelerate)" + buildSample(localenv.Program, pjoin(subdir, name), mglob(localenv, subdir, *extensions), CPPPATH=['#include', env['boost_inc_dir']]) From 076dece7d72a7cb23711be7640ec92e78ed07eae Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Tue, 11 Jun 2019 17:14:40 -0400 Subject: [PATCH 4/5] Correct flag and libs for OpenMP on macOS Apple's clang on macOS requires the libomp to link. Apple symlinks gcc to clang, so it can't be detected as clang by executable name --- SConstruct | 14 +++++++++++--- samples/cxx/SConscript | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/SConstruct b/SConstruct index 0567c34993..769c805544 100644 --- a/SConstruct +++ b/SConstruct @@ -253,7 +253,15 @@ defaults.noDebugLinkFlags = '' defaults.warningFlags = '-Wall' defaults.buildPch = False env['pch_flags'] = [] -env['openmp_flag'] = '-fopenmp' # used to generate sample build scripts +env['openmp_flag'] = ['-fopenmp'] # used to generate sample build scripts + +env['using_apple_clang'] = False +# Check if this is actually Apple's clang on macOS +if env['OS'] == 'Darwin': + result = subprocess.check_output([env.subst('$CC'), '--version']).decode('utf-8') + if 'clang' in result.lower() and result.startswith('Apple LLVM'): + env['using_apple_clang'] = True + env['openmp_flag'].insert(0, '-Xpreprocessor') if 'gcc' in env.subst('$CC') or 'gnu-cc' in env.subst('$CC'): defaults.optimizeCcFlags += ' -Wno-inline' @@ -276,13 +284,13 @@ elif env['CC'] == 'cl': # Visual Studio defaults.warningFlags = '/W3' defaults.buildPch = True env['pch_flags'] = ['/FIpch/system.h'] - env['openmp_flag'] = '/openmp' + env['openmp_flag'] = ['/openmp'] elif 'icc' in env.subst('$CC'): defaults.cxxFlags = '-std=c++0x' defaults.ccFlags = '-vec-report0 -diag-disable 1478' defaults.warningFlags = '-Wcheck' - env['openmp_flag'] = '-openmp' + env['openmp_flag'] = ['-openmp'] elif 'clang' in env.subst('$CC'): defaults.ccFlags = '-fcolor-diagnostics' diff --git a/samples/cxx/SConscript b/samples/cxx/SConscript index c614cbd517..d36ade78b4 100644 --- a/samples/cxx/SConscript +++ b/samples/cxx/SConscript @@ -18,6 +18,9 @@ for subdir, name, extensions, openmp in samples: localenv = env.Clone() if openmp: localenv.Append(CXXFLAGS=env['openmp_flag'], LINKFLAGS=env['openmp_flag']) + if env['using_apple_clang']: + localenv.Append(LIBS=['omp']) + localenv['cmake_extra'] = """ find_package(OpenMP REQUIRED) set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}) @@ -29,6 +32,8 @@ set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}) if env["OS"] == "Darwin": localenv["cmake_extra"] += "find_library(ACCELERATE_FRAMEWORK Accelerate)" + localenv.Append(LIBS=env['cantera_libs']) + buildSample(localenv.Program, pjoin(subdir, name), mglob(localenv, subdir, *extensions), CPPPATH=['#include', env['boost_inc_dir']]) From fb14816c2b3806e6bbb6b8aa65c2060c396327bf Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Wed, 12 Jun 2019 13:35:28 -0400 Subject: [PATCH 5/5] Build the samples on the CI services Requires libomp on macOS from homebrew. OpenMP with Visual C/C++ requires the loop index to be a signed type (from OpenMP < 3.0). --- .travis.yml | 3 +++ appveyor.yml | 1 + samples/cxx/openmp_ignition/openmp_ignition.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 139a86f434..5ce1d7ec84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ addons: - scons - boost - python + - libomp ssh_known_hosts: - cantera.org @@ -50,6 +51,7 @@ script: | set -e scons build -j2 python_cmd=/usr/bin/python3 VERBOSE=y python_package=full blas_lapack_libs=lapack,blas optimize=n coverage=y scons test + scons samples scons build sphinx_docs=y doxygen_docs=y sphinx_cmd="/usr/bin/python3 `which sphinx-build`" if [[ "${TRAVIS_PULL_REQUEST}" == "false" ]] && [[ "${TRAVIS_BRANCH}" == "master" ]] && [[ "${TRAVIS_REPO_SLUG}" == "Cantera/cantera" ]]; then openssl aes-256-cbc -k "${ctdeploy_pass}" -in ./doc/ctdeploy_key.enc -out ./doc/ctdeploy_key -d @@ -75,6 +77,7 @@ script: | else scons build -j2 python_cmd=python3 VERBOSE=y python_package=full blas_lapack_libs=lapack,blas optimize=n coverage=y scons test + scons samples fi after_success: | if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then diff --git a/appveyor.yml b/appveyor.yml index 52a7fd912d..14d2070a0c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,6 +11,7 @@ install: build_script: - cmd: C:\Python37-x64\Scripts\scons build -j2 boost_inc_dir=C:\Libraries\boost_1_62_0 debug=n VERBOSE=y python_package=full +- cmd: C:\Python37-x64\Scripts\scons samples test_script: - ps: | diff --git a/samples/cxx/openmp_ignition/openmp_ignition.cpp b/samples/cxx/openmp_ignition/openmp_ignition.cpp index 557fb6de21..d91318b992 100644 --- a/samples/cxx/openmp_ignition/openmp_ignition.cpp +++ b/samples/cxx/openmp_ignition/openmp_ignition.cpp @@ -34,10 +34,10 @@ void run() } // Points at which to compute ignition delay time - size_t nPoints = 50; + int nPoints = 50; vector_fp T0(nPoints); vector_fp ignition_time(nPoints); - for (size_t i = 0; i < nPoints; i++) { + for (int i = 0; i < nPoints; i++) { T0[i] = 1000 + 500 * ((float) i) / ((float) nPoints); } @@ -51,7 +51,7 @@ void run() // thread in cases where the workload is biased, e.g. calculations for low // T0 take longer than calculations for high T0. #pragma omp parallel for schedule(static, 1) - for (size_t i = 0; i < nPoints; i++) { + for (int i = 0; i < nPoints; i++) { // Get the Cantera objects that were initialized for this thread size_t j = omp_get_thread_num(); IdealGasMix& gas = *gases[j]; @@ -76,7 +76,7 @@ void run() // Print the computed ignition delays writelog(" T (K) t_ig (s)\n"); writelog("-------- ----------\n"); - for (size_t i = 0; i < nPoints; i++) { + for (int i = 0; i < nPoints; i++) { writelog("{: 8.1f} {: 10.3e}\n", T0[i], ignition_time[i]); } }