Skip to content

Commit d13e76f

Browse files
committed
very first implementation of the parallel topology optimization
1 parent fe871bd commit d13e76f

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

tree/tree.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,33 +2311,32 @@ RealNumType cmaple::Tree::improveEntireTreeParallel(const TreeSearchType tree_se
23112311

23122312
std::cout << "All threads found " << all_SPR_found_vec.size() << " SPR moves." << std::endl;
23132313

2314+
// sort all SPRs found in a descending order of the lh improvement
2315+
std::sort(all_SPR_found_vec.begin(), all_SPR_found_vec.end(),
2316+
[](const auto &a, const auto &b) {
2317+
return a.second > b.second;
2318+
});
2319+
23142320
// restore the fixed_blengths
23152321
fixed_blengths = bk_fixed_blengths;
2316-
23172322

23182323
// dummy variables
23192324
RealNumType total_improvement = 0;
2320-
PositionType num_nodes = 0;
2321-
PositionType count_node_1K = 0;
23222325

2323-
2324-
// only process outdated node to avoid traversing the same part of the tree
2325-
// multiple times
2326-
/* if (node.isOutdated() && node.getSPRCount() <= 5) {
2327-
2328-
2329-
// update total_improvement
2330-
total_improvement += improvement;
2331-
2332-
// Show log every 1000 nodes
2333-
++num_nodes;
2334-
if (cmaple::verbose_mode >= cmaple::VB_MED && num_nodes - count_node_1K >= 1000
2335-
&& tree_search_type != FAST_TREE_SEARCH) {
2336-
std::cout << "Processed topology for " << convertIntToString(num_nodes)
2337-
<< " nodes." << std::endl;
2338-
count_node_1K = num_nodes;
2339-
}
2340-
}*/
2326+
// sequentially search and apply SPRs on nodes found in the above step
2327+
for (const auto &item : all_SPR_found_vec) {
2328+
const cmaple::Index& index = item.first;
2329+
PhyloNode& node = nodes[index.getVectorIndex()];
2330+
2331+
// search and apply SPR on that node
2332+
std::vector<std::pair<cmaple::Index, double>> SPR_found_vec;
2333+
RealNumType improvement =
2334+
improveSubTree<num_states>(index, node,
2335+
tree_search_type, short_range_search, SPR_found_vec);
2336+
2337+
// update total_improvement
2338+
total_improvement += improvement;
2339+
}
23412340

23422341
return total_improvement;
23432342
}

0 commit comments

Comments
 (0)