summaryrefslogtreecommitdiff
path: root/src/Hasse_complex/include/gudhi/Hasse_complex.h
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-01-08 10:41:29 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-01-08 10:41:29 +0000
commitd3280484c8faa248ac2834401272d8b53b6d1866 (patch)
treeaf694174aed0afec21a6e2c4fde2653d5f5e104e /src/Hasse_complex/include/gudhi/Hasse_complex.h
parentd91d9248c66451a765f58b6d03db2124b52c3ae2 (diff)
parentde4811fa72c90b38357bbddec3d2ea5b282642b3 (diff)
tbb branch merge. Link with Intel TBB for parallel programmation.
Reduce persistence UT timings. Add parallel_rips_persistence compilatino and test. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@954 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4623c6a0c31d2b9574e2bb33836261fc26a89555
Diffstat (limited to 'src/Hasse_complex/include/gudhi/Hasse_complex.h')
-rw-r--r--src/Hasse_complex/include/gudhi/Hasse_complex.h44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/Hasse_complex/include/gudhi/Hasse_complex.h b/src/Hasse_complex/include/gudhi/Hasse_complex.h
index 67079687..38887264 100644
--- a/src/Hasse_complex/include/gudhi/Hasse_complex.h
+++ b/src/Hasse_complex/include/gudhi/Hasse_complex.h
@@ -29,6 +29,12 @@
#include <utility> // for pair
#include <vector>
+#include <gudhi/allocator.h>
+
+#ifdef GUDHI_USE_TBB
+#include <tbb/parallel_for.h>
+#endif
+
namespace Gudhi {
template < class HasseCpx >
@@ -38,8 +44,7 @@ struct Hasse_simplex {
template< class Complex_ds >
Hasse_simplex(Complex_ds & cpx
, typename Complex_ds::Simplex_handle sh)
- : key_(cpx.key(sh))
- , filtration_(cpx.filtration(sh))
+ : filtration_(cpx.filtration(sh))
, boundary_() {
boundary_.reserve(cpx.dimension(sh) + 1);
for (auto b_sh : cpx.boundary_simplex_range(sh)) {
@@ -49,7 +54,7 @@ struct Hasse_simplex {
Hasse_simplex(typename HasseCpx::Simplex_key key
, typename HasseCpx::Filtration_value fil
- , std::vector<typename HasseCpx::Simplex_handle> boundary)
+ , std::vector<typename HasseCpx::Simplex_handle> const& boundary)
: key_(key)
, filtration_(fil)
, boundary_(boundary) { }
@@ -97,20 +102,24 @@ class Hasse_complex {
template < class Complex_ds >
Hasse_complex(Complex_ds & cpx)
- : complex_()
+ : complex_(cpx.num_simplices())
, vertices_()
, threshold_(cpx.filtration())
, num_vertices_()
, dim_max_(cpx.dimension()) {
- complex_.reserve(cpx.num_simplices());
- int idx = 0;
- for (auto cpx_sh : cpx.filtration_simplex_range()) {
- complex_.push_back(Hasse_simp(cpx, cpx_sh));
- if (dimension(idx) == 0) {
+ int size = complex_.size();
+#ifdef GUDHI_USE_TBB
+ tbb::parallel_for(0,size,[&](int idx){new (&complex_[idx]) Hasse_simp(cpx, cpx.simplex(idx));});
+ for (int idx=0; idx<size; ++idx)
+ if (complex_[idx].boundary_.empty())
+ vertices_.push_back(idx);
+#else
+ for (int idx=0; idx<size; ++idx) {
+ new (&complex_[idx]) Hasse_simp(cpx, cpx.simplex(idx));
+ if (complex_[idx].boundary_.empty())
vertices_.push_back(idx);
- }
- ++idx;
}
+#endif
}
Hasse_complex()
@@ -187,14 +196,15 @@ class Hasse_complex {
}
void initialize_filtration() {
+ // Setting the keys is done by pcoh, Simplex_tree doesn't do it either.
+#if 0
Simplex_key key = 0;
- for (auto & h_simp : complex_) {
- h_simp.key_ = key;
- ++key;
- }
+ for (auto & h_simp : complex_)
+ h_simp.key_ = key++;
+#endif
}
- std::vector< Hasse_simp > complex_;
+ std::vector< Hasse_simp, Gudhi::no_init_allocator<Hasse_simp> > complex_;
std::vector<Simplex_handle> vertices_;
Filtration_value threshold_;
size_t num_vertices_;
@@ -218,7 +228,7 @@ std::istream& operator>>(std::istream & is
// read all simplices in the file as a list of vertices
while (read_hasse_simplex(is, boundary, fil)) {
// insert every simplex in the simplex tree
- hcpx.complex_.push_back(Hasse_simplex< Hasse_complex<T1, T2, T3> >(key, fil, boundary));
+ hcpx.complex_.emplace_back(key, fil, boundary);
if (max_dim < hcpx.dimension(key)) {
max_dim = hcpx.dimension(key);