Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions examples/TimeTBB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
* @date November 6, 2013
*/

#include <gtsam/global_includes.h>
#include <gtsam/base/Matrix.h>
#include <gtsam/global_includes.h>

#include <map>
#include <algorithm>
#include <iostream>
#include <map>
#include <random>

using namespace std;
using namespace gtsam;
Expand Down Expand Up @@ -53,18 +55,30 @@ struct WorkerWithoutAllocation
{
vector<double>& results;

WorkerWithoutAllocation(vector<double>& results) : results(results) {}
WorkerWithoutAllocation(vector<double>& results)
: results(results), gen(rd()), dis(-1.0, 1.0) {}

// Copy constructor for TBB
WorkerWithoutAllocation(const WorkerWithoutAllocation& other)
: results(other.results), gen(rd()), dis(-1.0, 1.0) {}

void operator()(const tbb::blocked_range<size_t>& r) const
{
for(size_t i = r.begin(); i != r.end(); ++i)
{
FixedMatrix m1 = FixedMatrix::Random();
FixedMatrix m2 = FixedMatrix::Random();
FixedMatrix m1;
FixedMatrix m2;
std::generate(m1.data(), m1.data() + m1.size(),
[&]() { return dis(gen); });
std::generate(m2.data(), m2.data() + m2.size(),
[&]() { return dis(gen); });
FixedMatrix prod = m1 * m2;
results[i] = prod.norm();
}
}
std::random_device rd;
mutable std::minstd_rand gen;
mutable std::uniform_real_distribution<double> dis;
};

/* ************************************************************************* */
Expand All @@ -86,9 +100,11 @@ map<int, double> testWithoutMemoryAllocation(int num_threads)
tbb::tick_count t0 = tbb::tick_count::now();

// Run parallel code (as a task group) inside of task arena
arena.execute([&]{
tg.run_and_wait([&]{
tbb::parallel_for(tbb::blocked_range<size_t>(0, numberOfProblems), WorkerWithoutAllocation(results));
arena.execute([&] {
tg.run_and_wait([&] {
tbb::parallel_for(
tbb::blocked_range<size_t>(0, numberOfProblems, grainSize),
WorkerWithoutAllocation(results));
});
});

Expand All @@ -105,7 +121,12 @@ struct WorkerWithAllocation
{
vector<double>& results;

WorkerWithAllocation(vector<double>& results) : results(results) {}
WorkerWithAllocation(vector<double>& results)
: results(results), gen(rd()), dis(-1.0, 1.0) {}

// Copy constructor for TBB
WorkerWithAllocation(const WorkerWithAllocation& other)
: results(other.results), gen(rd()), dis(-1.0, 1.0) {}

void operator()(const tbb::blocked_range<size_t>& r) const
{
Expand All @@ -119,8 +140,10 @@ struct WorkerWithAllocation
double *proddata = allocator.allocate(problemSize * problemSize);
Eigen::Map<Matrix> prod(proddata, problemSize, problemSize);

m1 = Eigen::Matrix4d::Random(problemSize, problemSize);
m2 = Eigen::Matrix4d::Random(problemSize, problemSize);
std::generate(m1.data(), m1.data() + m1.size(),
[&]() { return dis(gen); });
std::generate(m2.data(), m2.data() + m2.size(),
[&]() { return dis(gen); });
prod = m1 * m2;
results[i] = prod.norm();

Expand All @@ -129,6 +152,10 @@ struct WorkerWithAllocation
allocator.deallocate(proddata, problemSize * problemSize);
}
}

std::random_device rd;
mutable std::minstd_rand gen;
mutable std::uniform_real_distribution<double> dis;
};

/* ************************************************************************* */
Expand All @@ -150,9 +177,11 @@ map<int, double> testWithMemoryAllocation(int num_threads)
tbb::tick_count t0 = tbb::tick_count::now();

// Run parallel code (as a task group) inside of task arena
arena.execute([&]{
tg.run_and_wait([&]{
tbb::parallel_for(tbb::blocked_range<size_t>(0, numberOfProblems), WorkerWithAllocation(results));
arena.execute([&] {
tg.run_and_wait([&] {
tbb::parallel_for(
tbb::blocked_range<size_t>(0, numberOfProblems, grainSize),
WorkerWithAllocation(results));
});
});

Expand Down
6 changes: 6 additions & 0 deletions gtsam/geometry/Gal3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
* refer to the aforementioned paper.
*/

// GCC bug workaround
#if defined(__GNUC__) && __GNUC__ == 15
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif

#include <gtsam/base/Matrix.h>
#include <gtsam/base/numericalDerivative.h>
#include <gtsam/geometry/Event.h>
Expand Down
Loading