Skip to content

Commit

Permalink
Fixes and improvements in tree_sampler.
Browse files Browse the repository at this point in the history
* Avoiding unnecessary operations by earlier termination.
* Fixed acyclicity violation with rescue iterations.
* Allowed 'relaxing' maximality, avoiding rescue loops (this is now the default option).

All in all, a 1M node test graph with 1 root is processed about ~10x faster now.
  • Loading branch information
dthuerck committed Apr 12, 2017
1 parent 52ffd64 commit 07eed8d
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 197 deletions.
3 changes: 2 additions & 1 deletion demo/mapmap_demo.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2016-2017, Daniel Thuerck
* Copyright (C) 2016, Daniel Thuerck
* All rights reserved.
*
* This software may be modified and distributed under the terms
Expand Down Expand Up @@ -178,6 +178,7 @@ main(
ctr.spanning_tree_multilevel_after_n_iterations = 5;
ctr.force_acyclic = true;
ctr.min_acyclic_iterations = 5;
ctr.relax_acyclic_maximal = true;

/* construct optimizer */
mapmap.set_graph(graph.get());
Expand Down
17 changes: 9 additions & 8 deletions mapmap/header/mapmap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2016-2017, Daniel Thuerck
* Copyright (C) 2016, Daniel Thuerck
* TU Darmstadt - Graphics, Capture and Massively Parallel Computing
* All rights reserved.
*
Expand Down Expand Up @@ -108,7 +108,7 @@ class mapMAP
_s_t<COSTTYPE, SIMDWIDTH> initial_labelling();
_s_t<COSTTYPE, SIMDWIDTH> opt_step_spanning_tree();
_s_t<COSTTYPE, SIMDWIDTH> opt_step_multilevel();
_s_t<COSTTYPE, SIMDWIDTH> opt_step_acyclic();
_s_t<COSTTYPE, SIMDWIDTH> opt_step_acyclic(bool relax_maximality);
bool check_termination();

protected:
Expand Down Expand Up @@ -182,19 +182,20 @@ class mapMAP
struct mapMAP_control
{
/* switch modes on/off */
bool use_multilevel = true;
bool use_spanning_tree = true;
bool use_acyclic = true;
bool use_multilevel;
bool use_spanning_tree;
bool use_acyclic;

/* multilevel settings */
/* none */

/* spanning tree settings */
uint_t spanning_tree_multilevel_after_n_iterations = 5;
uint_t spanning_tree_multilevel_after_n_iterations;

/* acyclic settings */
bool force_acyclic = true; /* force using acyclic even if terminated */
uint_t min_acyclic_iterations = 5;
bool force_acyclic; /* force using acyclic even if terminated */
uint_t min_acyclic_iterations;
bool relax_acyclic_maximal;
};

NS_MAPMAP_END
Expand Down
11 changes: 7 additions & 4 deletions mapmap/header/tree_sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,27 @@ class TreeSampler
/**
* Select around k roots, satisfying the following conditions:
* - each component is covered by at least one root,
* - if ACYCLIC = true, roots cannot be adjacent nodes,
* - number of components <= number of roots <= number of nodes.
*
* After each component is covered, the remaining nodes
* are sampled according to the components' size.
*
* Conflict checking is deferred to a later stage.
*/
void select_random_roots(const luint_t k, std::vector<luint_t>& roots);

/**
* Samples a maximal (acyclic) coordinate set, given a set
* of roots to grow from. To achieve maximality, additional roots
* of roots to grow from. To achieve maximality, additional roots
* may be included.
*
*
* Note: If a component is not covered by the root set,
* it is also left out of the tree.
*
* Transfers ownership to the caller.
*/
std::unique_ptr<Tree<COSTTYPE>> sample(std::vector<luint_t>& roots,
const bool record_dependencies);
bool record_dependencies, bool relax = true);

public:
const uint_t p_chunk_size = 16;
Expand Down Expand Up @@ -95,6 +96,8 @@ class TreeSampler
std::vector<luint_t> m_rem_degrees;
std::vector<tbb::atomic<luint_t>> m_markers;
std::vector<tbb::atomic<unsigned char>> m_node_locks;
std::vector<tbb::atomic<unsigned char>> m_in_queue;
tbb::atomic<luint_t> m_rem_nodes;
};

template<typename COSTTYPE, bool ACYCLIC>
Expand Down
17 changes: 13 additions & 4 deletions mapmap/source/mapmap.impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2016-2017, Daniel Thuerck
* Copyright (C) 2016, Daniel Thuerck
* TU Darmstadt - Graphics, Capture and Massively Parallel Computing
* All rights reserved.
*
Expand Down Expand Up @@ -235,6 +235,13 @@ throw()
{
/* initialize control flow with standard values */
mapMAP_control std_control;
std_control.use_multilevel = true;
std_control.use_spanning_tree = true;
std_control.use_acyclic = true;
std_control.spanning_tree_multilevel_after_n_iterations = 5;
std_control.force_acyclic = true;
std_control.min_acyclic_iterations = 5;
std_control.relax_acyclic_maximal = true;

return optimize(solution, std_control);
}
Expand Down Expand Up @@ -337,7 +344,7 @@ throw()
{
++ac_it;

m_objective = opt_step_acyclic();
m_objective = opt_step_acyclic(control_flow.relax_acyclic_maximal);

record_time_from_start();
print_status();
Expand Down Expand Up @@ -642,7 +649,8 @@ template<typename COSTTYPE, uint_t SIMDWIDTH, typename UNARY, typename PAIRWISE>
FORCEINLINE
_s_t<COSTTYPE, SIMDWIDTH>
mapMAP<COSTTYPE, SIMDWIDTH, UNARY, PAIRWISE>::
opt_step_acyclic()
opt_step_acyclic(
bool relax_maximality)
{
std::vector<_iv_st<COSTTYPE, SIMDWIDTH>> ac_solution = m_solution;

Expand All @@ -654,7 +662,8 @@ opt_step_acyclic()
sampler.select_random_roots(m_num_roots, roots);

/* grow trees in forest */
std::unique_ptr<Tree<COSTTYPE>> tree = sampler.sample(roots, true);
std::unique_ptr<Tree<COSTTYPE>> tree = sampler.sample(roots, true,
relax_maximality);

/* create tree optimizer (std: DP) and pass parameters and modules */
CombinatorialDynamicProgramming<COSTTYPE, SIMDWIDTH, UNARY,
Expand Down
Loading

0 comments on commit 07eed8d

Please sign in to comment.