diff --git a/.travis.sh b/.travis.sh index 3cec20f53..5de2d8e69 100755 --- a/.travis.sh +++ b/.travis.sh @@ -1,7 +1,7 @@ #!/bin/bash # common tasks before either build or test -function prepare () +function configure() { set -e # Make sure any error makes the script to return an error code set -x # echo @@ -14,21 +14,23 @@ function prepare () rm -fr $BUILD_DIR || true mkdir $BUILD_DIR && cd $BUILD_DIR - if [ -z "$CMAKE_BUILD_TYPE" ]; then - CMAKE_BUILD_TYPE=Debug - fi - - if [ -z "$GTSAM_ALLOW_DEPRECATED_SINCE_V4" ]; then - GTSAM_ALLOW_DEPRECATED_SINCE_V4=OFF - fi - if [ ! -z "$GCC_VERSION" ]; then - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$GCC_VERSION 60 \ - --slave /usr/bin/g++ g++ /usr/bin/g++-$GCC_VERSION - sudo update-alternatives --set gcc /usr/bin/gcc-$GCC_VERSION + export CC=gcc-$GCC_VERSION + export CXX=g++-$GCC_VERSION fi + + # GTSAM_BUILD_WITH_MARCH_NATIVE=OFF: to avoid crashes in builder VMs + cmake $SOURCE_DIR \ + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} \ + -DGTSAM_BUILD_TESTS=${GTSAM_BUILD_TESTS:-OFF} \ + -DGTSAM_BUILD_UNSTABLE=${GTSAM_BUILD_UNSTABLE:-ON} \ + -DGTSAM_BUILD_EXAMPLES_ALWAYS=${GTSAM_BUILD_EXAMPLES_ALWAYS:-ON} \ + -DGTSAM_ALLOW_DEPRECATED_SINCE_V4=${GTSAM_ALLOW_DEPRECATED_SINCE_V4:-OFF} \ + -DGTSAM_BUILD_WITH_MARCH_NATIVE=OFF \ + -DCMAKE_VERBOSE_MAKEFILE=ON } + # common tasks after either build or test function finish () { @@ -41,17 +43,12 @@ function finish () # compile the code with the intent of populating the cache function build () { - prepare + export GTSAM_BUILD_EXAMPLES_ALWAYS=ON + export GTSAM_BUILD_TESTS=OFF - cmake $SOURCE_DIR \ - -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \ - -DGTSAM_BUILD_TESTS=OFF \ - -DGTSAM_BUILD_UNSTABLE=$GTSAM_BUILD_UNSTABLE \ - -DGTSAM_BUILD_EXAMPLES_ALWAYS=ON \ - -DGTSAM_ALLOW_DEPRECATED_SINCE_V4=$GTSAM_ALLOW_DEPRECATED_SINCE_V4 + configure - # Actual build: - VERBOSE=1 make -j2 + make -j2 finish } @@ -59,14 +56,10 @@ function build () # run the tests function test () { - prepare + export GTSAM_BUILD_EXAMPLES_ALWAYS=OFF + export GTSAM_BUILD_TESTS=ON - cmake $SOURCE_DIR \ - -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \ - -DGTSAM_BUILD_TESTS=ON \ - -DGTSAM_BUILD_UNSTABLE=$GTSAM_BUILD_UNSTABLE \ - -DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF \ - -DGTSAM_ALLOW_DEPRECATED_SINCE_V4=OFF + configure # Actual build: make -j2 check @@ -79,7 +72,7 @@ case $1 in -b) build ;; - -t) + -t) test ;; esac diff --git a/.travis.yml b/.travis.yml index 1e2d6760a..bcb6ceb4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,12 @@ addons: apt: sources: - ubuntu-toolchain-r-test + - sourceline: 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main' + key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' packages: - - g++-8 - - clang-3.8 - - build-essential - - pkg-config + - g++-9 + - clang-9 + - build-essential pkg-config - cmake - libpython-dev python-numpy - libboost-all-dev @@ -28,8 +29,14 @@ stages: - compile - test +env: + global: + - MAKEFLAGS="-j2" + - CCACHE_SLOPPINESS=pch_defines,time_macros + # Compile stage without building examples/tests to populate the caches. jobs: +# -------- STAGE 1: COMPILE ----------- include: # on Mac, GCC - stage: compile @@ -68,46 +75,45 @@ jobs: - stage: compile os: linux compiler: clang - env: CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_UNSTABLE=OFF + env: CC=clang-9 CXX=clang++-9 CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_UNSTABLE=OFF script: bash .travis.sh -b - stage: compile os: linux compiler: clang - env: CMAKE_BUILD_TYPE=Release + env: CC=clang-9 CXX=clang++-9 CMAKE_BUILD_TYPE=Release script: bash .travis.sh -b # on Linux, with deprecated ON to make sure that path still compiles - stage: compile os: linux compiler: clang - env: CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_UNSTABLE=OFF GTSAM_ALLOW_DEPRECATED_SINCE_V4=ON + env: CC=clang-9 CXX=clang++-9 CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_UNSTABLE=OFF GTSAM_ALLOW_DEPRECATED_SINCE_V4=ON script: bash .travis.sh -b - -# Matrix configuration: -os: - - osx - - linux -compiler: - - gcc - - clang -env: - global: - - MAKEFLAGS="-j2" - - CCACHE_SLOPPINESS=pch_defines,time_macros - - GTSAM_ALLOW_DEPRECATED_SINCE_V4=OFF - - GTSAM_BUILD_UNSTABLE=ON - matrix: - - CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_UNSTABLE=OFF - - CMAKE_BUILD_TYPE=Release -script: - - bash .travis.sh -t - -matrix: - exclude: - # Exclude g++ debug on Linux as it consistently times out - - os: linux - compiler: gcc - env : CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_UNSTABLE=OFF - # Exclude clang on Linux/clang in release until issue #57 is solved - - os: linux - compiler: clang - env : CMAKE_BUILD_TYPE=Release +# -------- STAGE 2: TESTS ----------- +# on Mac, GCC + - stage: test + os: osx + compiler: clang + env: CMAKE_BUILD_TYPE=Release + script: bash .travis.sh -t + - stage: test + os: osx + compiler: clang + env: CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_UNSTABLE=OFF + script: bash .travis.sh -t + - stage: test + os: linux + compiler: gcc + env: CMAKE_BUILD_TYPE=Release + script: bash .travis.sh -t +# Exclude g++ debug on Linux as it consistently times out +# - stage: test +# os: linux +# compiler: gcc +# env: CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_UNSTABLE=OFF +# script: bash .travis.sh -t +# Exclude clang on Linux/clang in release until issue #57 is solved +# - stage: test +# os: linux +# compiler: clang +# env: CC=clang-9 CXX=clang++-9 CMAKE_BUILD_TYPE=Release +# script: bash .travis.sh -t diff --git a/CMakeLists.txt b/CMakeLists.txt index 732717141..2af6341ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -434,7 +434,7 @@ add_subdirectory(timing) # Build gtsam_unstable if (GTSAM_BUILD_UNSTABLE) add_subdirectory(gtsam_unstable) -endif(GTSAM_BUILD_UNSTABLE) +endif() # Matlab toolbox if (GTSAM_INSTALL_MATLAB_TOOLBOX) diff --git a/gtsam/base/ConcurrentMap.h b/gtsam/base/ConcurrentMap.h index b8388057d..2d7cbd6db 100644 --- a/gtsam/base/ConcurrentMap.h +++ b/gtsam/base/ConcurrentMap.h @@ -29,14 +29,22 @@ # undef max # undef ERROR +#include // std::hash() + // Use TBB concurrent_unordered_map for ConcurrentMap -# define CONCURRENT_MAP_BASE tbb::concurrent_unordered_map +template +using ConcurrentMapBase = tbb::concurrent_unordered_map< + KEY, + VALUE, + std::hash + >; #else // If we're not using TBB, use a FastMap for ConcurrentMap -# include -# define CONCURRENT_MAP_BASE gtsam::FastMap +#include +template +using ConcurrentMapBase = gtsam::FastMap; #endif @@ -57,11 +65,11 @@ namespace gtsam { * @addtogroup base */ template -class ConcurrentMap : public CONCURRENT_MAP_BASE { +class ConcurrentMap : public ConcurrentMapBase { public: - typedef CONCURRENT_MAP_BASE Base; + typedef ConcurrentMapBase Base; /** Default constructor */ ConcurrentMap() {} diff --git a/gtsam/base/DSFMap.h b/gtsam/base/DSFMap.h index dfce185dc..1d6bfdefa 100644 --- a/gtsam/base/DSFMap.h +++ b/gtsam/base/DSFMap.h @@ -115,8 +115,8 @@ class DSFMap { /// Small utility class for representing a wrappable pairs of ints. class IndexPair : public std::pair { public: - IndexPair(): std::pair(0,0) {} - IndexPair(size_t i, size_t j) : std::pair(i,j) {} + inline IndexPair(): std::pair(0,0) {} + inline IndexPair(size_t i, size_t j) : std::pair(i,j) {} inline size_t i() const { return first; }; inline size_t j() const { return second; }; }; diff --git a/gtsam/base/GenericValue.h b/gtsam/base/GenericValue.h index 52899fe45..aee6c0e62 100644 --- a/gtsam/base/GenericValue.h +++ b/gtsam/base/GenericValue.h @@ -89,12 +89,9 @@ public: /** * Create a duplicate object returned as a pointer to the generic Value interface. - * For the sake of performance, this function use singleton pool allocator instead of the normal heap allocator. - * The result must be deleted with Value::deallocate_, not with the 'delete' operator. */ virtual Value* clone_() const { - void *place = boost::singleton_pool::malloc(); - GenericValue* ptr = new (place) GenericValue(*this); // calls copy constructor to fill in + GenericValue* ptr = new GenericValue(*this); // calls copy constructor to fill in return ptr; } @@ -102,8 +99,7 @@ public: * Destroy and deallocate this object, only if it was originally allocated using clone_(). */ virtual void deallocate_() const { - this->~GenericValue(); // Virtual destructor cleans up the derived object - boost::singleton_pool::free((void*) this); // Release memory from pool + delete this; } /** @@ -118,10 +114,7 @@ public: // Call retract on the derived class using the retract trait function const T retractResult = traits::Retract(GenericValue::value(), delta); - // Create a Value pointer copy of the result - void* resultAsValuePlace = - boost::singleton_pool::malloc(); - Value* resultAsValue = new (resultAsValuePlace) GenericValue(retractResult); + Value* resultAsValue = new GenericValue(retractResult); // Return the pointer to the Value base class return resultAsValue; @@ -172,12 +165,6 @@ public: return *this; } - private: - - /// Fake Tag struct for singleton pool allocator. In fact, it is never used! - struct PoolTag { - }; - private: /** Serialization function */ diff --git a/gtsam/base/ThreadsafeException.h b/gtsam/base/ThreadsafeException.h index ff82ff27c..15a76fbf1 100644 --- a/gtsam/base/ThreadsafeException.h +++ b/gtsam/base/ThreadsafeException.h @@ -22,6 +22,7 @@ #include // for GTSAM_USE_TBB #include +#include #include #include @@ -117,7 +118,7 @@ public: }; /// Thread-safe runtime error exception -class RuntimeErrorThreadsafe: public ThreadsafeException { +class GTSAM_EXPORT RuntimeErrorThreadsafe: public ThreadsafeException { public: /// Construct with a string describing the exception RuntimeErrorThreadsafe(const std::string& description) : diff --git a/gtsam/base/timing.h b/gtsam/base/timing.h index 557500e73..972bb45f7 100644 --- a/gtsam/base/timing.h +++ b/gtsam/base/timing.h @@ -196,7 +196,7 @@ namespace gtsam { /** * Small class that calls internal::tic at construction, and internol::toc when destroyed */ - class AutoTicToc { + class GTSAM_EXPORT AutoTicToc { private: size_t id_; const char* label_; diff --git a/gtsam/nonlinear/NonlinearOptimizerParams.h b/gtsam/nonlinear/NonlinearOptimizerParams.h index 9757cca73..65fdd1c92 100644 --- a/gtsam/nonlinear/NonlinearOptimizerParams.h +++ b/gtsam/nonlinear/NonlinearOptimizerParams.h @@ -31,7 +31,7 @@ namespace gtsam { /** The common parameters for Nonlinear optimizers. Most optimizers * deriving from NonlinearOptimizer also subclass the parameters. */ -class NonlinearOptimizerParams { +class GTSAM_EXPORT NonlinearOptimizerParams { public: /** See NonlinearOptimizerParams::verbosity */ enum Verbosity { @@ -52,7 +52,7 @@ public: virtual ~NonlinearOptimizerParams() { } - GTSAM_EXPORT virtual void print(const std::string& str = "") const; + virtual void print(const std::string& str = "") const; size_t getMaxIterations() const { return maxIterations; } double getRelativeErrorTol() const { return relativeErrorTol; } @@ -68,8 +68,8 @@ public: verbosity = verbosityTranslator(src); } - GTSAM_EXPORT static Verbosity verbosityTranslator(const std::string &s) ; - GTSAM_EXPORT static std::string verbosityTranslator(Verbosity value) ; + static Verbosity verbosityTranslator(const std::string &s) ; + static std::string verbosityTranslator(Verbosity value) ; /** See NonlinearOptimizerParams::linearSolverType */ enum LinearSolverType { @@ -144,10 +144,10 @@ public: } private: - GTSAM_EXPORT std::string linearSolverTranslator(LinearSolverType linearSolverType) const; - GTSAM_EXPORT LinearSolverType linearSolverTranslator(const std::string& linearSolverType) const; - GTSAM_EXPORT std::string orderingTypeTranslator(Ordering::OrderingType type) const; - GTSAM_EXPORT Ordering::OrderingType orderingTypeTranslator(const std::string& type) const; + std::string linearSolverTranslator(LinearSolverType linearSolverType) const; + LinearSolverType linearSolverTranslator(const std::string& linearSolverType) const; + std::string orderingTypeTranslator(Ordering::OrderingType type) const; + Ordering::OrderingType orderingTypeTranslator(const std::string& type) const; }; // For backward compatibility: diff --git a/gtsam/symbolic/SymbolicBayesTree.h b/gtsam/symbolic/SymbolicBayesTree.h index 5f7bdde7e..e28f28764 100644 --- a/gtsam/symbolic/SymbolicBayesTree.h +++ b/gtsam/symbolic/SymbolicBayesTree.h @@ -30,7 +30,7 @@ namespace gtsam { /* ************************************************************************* */ /// A clique in a SymbolicBayesTree - class SymbolicBayesTreeClique : + class GTSAM_EXPORT SymbolicBayesTreeClique : public BayesTreeCliqueBase { public: @@ -45,7 +45,7 @@ namespace gtsam { /* ************************************************************************* */ /// A Bayes tree that represents the connectivity between variables but is not associated with any /// probability functions. - class SymbolicBayesTree : + class GTSAM_EXPORT SymbolicBayesTree : public BayesTree { private: @@ -59,7 +59,7 @@ namespace gtsam { SymbolicBayesTree() {} /** check equality */ - GTSAM_EXPORT bool equals(const This& other, double tol = 1e-9) const; + bool equals(const This& other, double tol = 1e-9) const; private: /** Serialization function */ diff --git a/gtsam_unstable/partition/GenericGraph.h b/gtsam_unstable/partition/GenericGraph.h index ec0027635..3dc640e97 100644 --- a/gtsam_unstable/partition/GenericGraph.h +++ b/gtsam_unstable/partition/GenericGraph.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "PartitionWorkSpace.h"