Merged in feature/cleanupBase (pull request #154)

Some cleanup in base
release/4.3a0
Frank Dellaert 2015-06-14 20:42:13 -07:00
commit 51433c1ec2
5 changed files with 84 additions and 69 deletions

View File

@ -17,8 +17,7 @@
*/ */
#pragma once #pragma once
#include <gtsam/config.h> // Configuration from CMake
#include <gtsam/global_includes.h>
#if !defined GTSAM_ALLOCATOR_BOOSTPOOL && !defined GTSAM_ALLOCATOR_TBB && !defined GTSAM_ALLOCATOR_STL #if !defined GTSAM_ALLOCATOR_BOOSTPOOL && !defined GTSAM_ALLOCATOR_TBB && !defined GTSAM_ALLOCATOR_STL
# ifdef GTSAM_USE_TBB # ifdef GTSAM_USE_TBB
@ -85,4 +84,4 @@ namespace gtsam
}; };
} }
} }

View File

@ -19,9 +19,9 @@
#pragma once #pragma once
#include <gtsam/base/FastDefaultAllocator.h> #include <gtsam/base/FastDefaultAllocator.h>
#include <map>
#include <boost/serialization/nvp.hpp> #include <boost/serialization/nvp.hpp>
#include <boost/serialization/map.hpp> #include <boost/serialization/map.hpp>
#include <map>
namespace gtsam { namespace gtsam {

View File

@ -61,13 +61,13 @@ VerticalBlockMatrix SymmetricBlockMatrix::choleskyPartial(
// Split conditional // Split conditional
// Create one big conditionals with many frontal variables. // Create one big conditionals with many frontal variables.
gttic(Construct_conditional); gttic(Construct_conditional);
const size_t varDim = offset(nFrontals); const size_t varDim = offset(nFrontals);
VerticalBlockMatrix Ab = VerticalBlockMatrix::LikeActiveViewOf(*this, varDim); VerticalBlockMatrix Ab = VerticalBlockMatrix::LikeActiveViewOf(*this, varDim);
Ab.full() = matrix_.topRows(varDim); Ab.full() = matrix_.topRows(varDim);
Ab.full().triangularView<Eigen::StrictlyLower>().setZero(); Ab.full().triangularView<Eigen::StrictlyLower>().setZero();
gttoc(Construct_conditional); gttoc(Construct_conditional);
gttic(Remaining_factor); gttic(Remaining_factor);
// Take lower-right block of Ab_ to get the remaining factor // Take lower-right block of Ab_ to get the remaining factor

View File

@ -16,24 +16,28 @@
* @date Oct 5, 2010 * @date Oct 5, 2010
*/ */
#include <math.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>
#include <gtsam/base/debug.h> #include <gtsam/base/debug.h>
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <boost/algorithm/string/replace.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <cmath>
#include <cstddef>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <stdexcept>
#include <utility>
namespace gtsam { namespace gtsam {
namespace internal { namespace internal {
GTSAM_EXPORT boost::shared_ptr<TimingOutline> timingRoot( GTSAM_EXPORT boost::shared_ptr<TimingOutline> gTimingRoot(
new TimingOutline("Total", getTicTocID("Total"))); new TimingOutline("Total", getTicTocID("Total")));
GTSAM_EXPORT boost::weak_ptr<TimingOutline> timingCurrent(timingRoot); GTSAM_EXPORT boost::weak_ptr<TimingOutline> gCurrentTimer(gTimingRoot);
/* ************************************************************************* */ /* ************************************************************************* */
// Implementation of TimingOutline // Implementation of TimingOutline
@ -50,8 +54,8 @@ void TimingOutline::add(size_t usecs, size_t usecsWall) {
} }
/* ************************************************************************* */ /* ************************************************************************* */
TimingOutline::TimingOutline(const std::string& label, size_t myId) : TimingOutline::TimingOutline(const std::string& label, size_t id) :
myId_(myId), t_(0), tWall_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), myOrder_( id_(id), t_(0), tWall_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), myOrder_(
0), lastChildOrder_(0), label_(label) { 0), lastChildOrder_(0), label_(label) {
#ifdef GTSAM_USING_NEW_BOOST_TIMERS #ifdef GTSAM_USING_NEW_BOOST_TIMERS
timer_.stop(); timer_.stop();
@ -153,7 +157,7 @@ const boost::shared_ptr<TimingOutline>& TimingOutline::child(size_t child,
} }
/* ************************************************************************* */ /* ************************************************************************* */
void TimingOutline::ticInternal() { void TimingOutline::tic() {
#ifdef GTSAM_USING_NEW_BOOST_TIMERS #ifdef GTSAM_USING_NEW_BOOST_TIMERS
assert(timer_.is_stopped()); assert(timer_.is_stopped());
timer_.start(); timer_.start();
@ -169,7 +173,7 @@ void TimingOutline::ticInternal() {
} }
/* ************************************************************************* */ /* ************************************************************************* */
void TimingOutline::tocInternal() { void TimingOutline::toc() {
#ifdef GTSAM_USING_NEW_BOOST_TIMERS #ifdef GTSAM_USING_NEW_BOOST_TIMERS
assert(!timer_.is_stopped()); assert(!timer_.is_stopped());
@ -212,7 +216,6 @@ void TimingOutline::finishedIteration() {
} }
/* ************************************************************************* */ /* ************************************************************************* */
// Generate or retrieve a unique global ID number that will be used to look up tic_/toc statements
size_t getTicTocID(const char *descriptionC) { size_t getTicTocID(const char *descriptionC) {
const std::string description(descriptionC); const std::string description(descriptionC);
// Global (static) map from strings to ID numbers and current next ID number // Global (static) map from strings to ID numbers and current next ID number
@ -232,37 +235,33 @@ size_t getTicTocID(const char *descriptionC) {
} }
/* ************************************************************************* */ /* ************************************************************************* */
void ticInternal(size_t id, const char *labelC) { void tic(size_t id, const char *labelC) {
const std::string label(labelC); const std::string label(labelC);
if (ISDEBUG("timing-verbose"))
std::cout << "gttic_(" << id << ", " << label << ")" << std::endl;
boost::shared_ptr<TimingOutline> node = // boost::shared_ptr<TimingOutline> node = //
timingCurrent.lock()->child(id, label, timingCurrent); gCurrentTimer.lock()->child(id, label, gCurrentTimer);
timingCurrent = node; gCurrentTimer = node;
node->ticInternal(); node->tic();
} }
/* ************************************************************************* */ /* ************************************************************************* */
void tocInternal(size_t id, const char *label) { void toc(size_t id, const char *label) {
if (ISDEBUG("timing-verbose")) boost::shared_ptr<TimingOutline> current(gCurrentTimer.lock());
std::cout << "gttoc(" << id << ", " << label << ")" << std::endl; if (id != current->id_) {
boost::shared_ptr<TimingOutline> current(timingCurrent.lock()); gTimingRoot->print();
if (id != current->myId_) {
timingRoot->print();
throw std::invalid_argument( throw std::invalid_argument(
(boost::format( (boost::format(
"gtsam timing: Mismatched tic/toc: gttoc(\"%s\") called when last tic was \"%s\".") "gtsam timing: Mismatched tic/toc: gttoc(\"%s\") called when last tic was \"%s\".")
% label % current->label_).str()); % label % current->label_).str());
} }
if (!current->parent_.lock()) { if (!current->parent_.lock()) {
timingRoot->print(); gTimingRoot->print();
throw std::invalid_argument( throw std::invalid_argument(
(boost::format( (boost::format(
"gtsam timing: Mismatched tic/toc: extra gttoc(\"%s\"), already at the root") "gtsam timing: Mismatched tic/toc: extra gttoc(\"%s\"), already at the root")
% label).str()); % label).str());
} }
current->tocInternal(); current->toc();
timingCurrent = current->parent_; gCurrentTimer = current->parent_;
} }
} // namespace internal } // namespace internal

View File

@ -17,12 +17,15 @@
*/ */
#pragma once #pragma once
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/version.hpp>
#include <gtsam/global_includes.h>
#include <gtsam/base/FastMap.h> #include <gtsam/base/FastMap.h>
#include <gtsam/dllexport.h>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/version.hpp>
#include <cstddef>
#include <string>
// This file contains the GTSAM timing instrumentation library, a low-overhead method for // This file contains the GTSAM timing instrumentation library, a low-overhead method for
// learning at a medium-fine level how much time various components of an algorithm take // learning at a medium-fine level how much time various components of an algorithm take
@ -125,16 +128,21 @@
namespace gtsam { namespace gtsam {
namespace internal { namespace internal {
// Generate/retrieve a unique global ID number that will be used to look up tic/toc statements
GTSAM_EXPORT size_t getTicTocID(const char *description); GTSAM_EXPORT size_t getTicTocID(const char *description);
GTSAM_EXPORT void ticInternal(size_t id, const char *label);
GTSAM_EXPORT void tocInternal(size_t id, const char *label); // Create new TimingOutline child for gCurrentTimer, make it gCurrentTimer, and call tic method
GTSAM_EXPORT void tic(size_t id, const char *label);
// Call toc on gCurrentTimer and then set gCurrentTimer to the parent of gCurrentTimer
GTSAM_EXPORT void toc(size_t id, const char *label);
/** /**
* Timing Entry, arranged in a tree * Timing Entry, arranged in a tree
*/ */
class GTSAM_EXPORT TimingOutline { class GTSAM_EXPORT TimingOutline {
protected: protected:
size_t myId_; size_t id_;
size_t t_; size_t t_;
size_t tWall_; size_t tWall_;
double t2_ ; ///< cache the \sum t_i^2 double t2_ ; ///< cache the \sum t_i^2
@ -176,29 +184,38 @@ namespace gtsam {
void print2(const std::string& outline = "", const double parentTotal = -1.0) const; void print2(const std::string& outline = "", const double parentTotal = -1.0) const;
const boost::shared_ptr<TimingOutline>& const boost::shared_ptr<TimingOutline>&
child(size_t child, const std::string& label, const boost::weak_ptr<TimingOutline>& thisPtr); child(size_t child, const std::string& label, const boost::weak_ptr<TimingOutline>& thisPtr);
void ticInternal(); void tic();
void tocInternal(); void toc();
void finishedIteration(); void finishedIteration();
GTSAM_EXPORT friend void tocInternal(size_t id, const char *label); GTSAM_EXPORT friend void toc(size_t id, const char *label);
}; // \TimingOutline }; // \TimingOutline
/** /**
* No documentation * Small class that calls internal::tic at construction, and internol::toc when destroyed
*/ */
class AutoTicToc { class AutoTicToc {
private: private:
size_t id_; size_t id_;
const char *label_; const char* label_;
bool isSet_; bool isSet_;
public:
AutoTicToc(size_t id, const char* label) : id_(id), label_(label), isSet_(true) { ticInternal(id_, label_); } public:
void stop() { tocInternal(id_, label_); isSet_ = false; } AutoTicToc(size_t id, const char* label)
~AutoTicToc() { if(isSet_) stop(); } : id_(id), label_(label), isSet_(true) {
tic(id_, label_);
}
void stop() {
toc(id_, label_);
isSet_ = false;
}
~AutoTicToc() {
if (isSet_) stop();
}
}; };
GTSAM_EXTERN_EXPORT boost::shared_ptr<TimingOutline> timingRoot; GTSAM_EXTERN_EXPORT boost::shared_ptr<TimingOutline> gTimingRoot;
GTSAM_EXTERN_EXPORT boost::weak_ptr<TimingOutline> timingCurrent; GTSAM_EXTERN_EXPORT boost::weak_ptr<TimingOutline> gCurrentTimer;
} }
// Tic and toc functions that are always active (whether or not ENABLE_TIMING is defined) // Tic and toc functions that are always active (whether or not ENABLE_TIMING is defined)
@ -210,7 +227,7 @@ namespace gtsam {
// tic // tic
#define gttic_(label) \ #define gttic_(label) \
static const size_t label##_id_tic = ::gtsam::internal::getTicTocID(#label); \ static const size_t label##_id_tic = ::gtsam::internal::getTicTocID(#label); \
::gtsam::internal::AutoTicToc label##_obj = ::gtsam::internal::AutoTicToc(label##_id_tic, #label) ::gtsam::internal::AutoTicToc label##_obj(label##_id_tic, #label)
// toc // toc
#define gttoc_(label) \ #define gttoc_(label) \
@ -228,26 +245,26 @@ namespace gtsam {
// indicate iteration is finished // indicate iteration is finished
inline void tictoc_finishedIteration_() { inline void tictoc_finishedIteration_() {
::gtsam::internal::timingRoot->finishedIteration(); } ::gtsam::internal::gTimingRoot->finishedIteration(); }
// print // print
inline void tictoc_print_() { inline void tictoc_print_() {
::gtsam::internal::timingRoot->print(); } ::gtsam::internal::gTimingRoot->print(); }
// print mean and standard deviation // print mean and standard deviation
inline void tictoc_print2_() { inline void tictoc_print2_() {
::gtsam::internal::timingRoot->print2(); } ::gtsam::internal::gTimingRoot->print2(); }
// get a node by label and assign it to variable // get a node by label and assign it to variable
#define tictoc_getNode(variable, label) \ #define tictoc_getNode(variable, label) \
static const size_t label##_id_getnode = ::gtsam::internal::getTicTocID(#label); \ static const size_t label##_id_getnode = ::gtsam::internal::getTicTocID(#label); \
const boost::shared_ptr<const ::gtsam::internal::TimingOutline> variable = \ const boost::shared_ptr<const ::gtsam::internal::TimingOutline> variable = \
::gtsam::internal::timingCurrent.lock()->child(label##_id_getnode, #label, ::gtsam::internal::timingCurrent); ::gtsam::internal::gCurrentTimer.lock()->child(label##_id_getnode, #label, ::gtsam::internal::gCurrentTimer);
// reset // reset
inline void tictoc_reset_() { inline void tictoc_reset_() {
::gtsam::internal::timingRoot.reset(new ::gtsam::internal::TimingOutline("Total", ::gtsam::internal::getTicTocID("Total"))); ::gtsam::internal::gTimingRoot.reset(new ::gtsam::internal::TimingOutline("Total", ::gtsam::internal::getTicTocID("Total")));
::gtsam::internal::timingCurrent = ::gtsam::internal::timingRoot; } ::gtsam::internal::gCurrentTimer = ::gtsam::internal::gTimingRoot; }
#ifdef ENABLE_TIMING #ifdef ENABLE_TIMING
#define gttic(label) gttic_(label) #define gttic(label) gttic_(label)