Skip to content

Commit 4a3ec08

Browse files
committed
Switch to knncolle::parallelize() to simplify parallelization.
1 parent 053a87a commit 4a3ec08

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

include/scran_graph_cluster/build_snn_graph.hpp

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ struct BuildSnnGraphOptions {
5757
SnnWeightScheme weighting_scheme = SnnWeightScheme::RANKED;
5858

5959
/**
60-
* See `set_num_threads()`.
60+
* Number of threads to use.
61+
* The parallelization scheme is defined by `knncolle::parallelize()`.
6162
*/
6263
int num_threads = 1;
6364
};
@@ -160,27 +161,12 @@ void build_snn_graph(size_t num_cells, GetNeighbors_ get_neighbors, GetIndex_ ge
160161
std::vector<std::vector<Node_> > edge_stores(num_cells);
161162
std::vector<std::vector<Weight_> > weight_stores(num_cells);
162163

163-
#ifndef SCRAN_CUSTOM_PARALLEL
164-
#ifdef _OPENMP
165-
#pragma omp parallel num_threads(options.num_threads)
166-
#endif
167-
{
168-
#else
169-
SCRAN_CUSTOM_PARALLEL([&](size_t, size_t start, size_t length) -> void {
170-
#endif
171-
164+
knncolle::parallelize(options.num_threads, num_cells, [&](int, size_t start, size_t length) -> void {
172165
std::vector<Weight_> current_score(num_cells);
173166
std::vector<Node_> current_added;
174167
current_added.reserve(num_cells);
175168

176-
#ifndef SCRAN_CUSTOM_PARALLEL
177-
#ifdef _OPENMP
178-
#pragma omp for
179-
#endif
180-
for (size_t j = 0; j < num_cells; ++j) {
181-
#else
182169
for (size_t j = start, end = start + length; j < end; ++j) {
183-
#endif
184170
const Node_ j_cast = j;
185171

186172
const auto& current_neighbors = get_neighbors(j);
@@ -253,14 +239,8 @@ void build_snn_graph(size_t num_cells, GetNeighbors_ get_neighbors, GetIndex_ ge
253239
otherscore = 0;
254240
}
255241
current_added.clear();
256-
257-
#ifndef SCRAN_CUSTOM_PARALLEL
258-
}
259-
}
260-
#else
261242
}
262-
}, num_cells, options.num_threads);
263-
#endif
243+
});
264244

265245
// Collating the total number of edges.
266246
size_t nedges = 0;
@@ -309,8 +289,8 @@ BuildSnnGraphResults<Node_, Weight_> build_snn_graph(const knncolle::NeighborLis
309289
BuildSnnGraphResults<Node_, Weight_> output;
310290
build_snn_graph(
311291
neighbors.size(),
312-
[&](size_t i) -> const std::vector<Index_>& { return neighbors[i].first; },
313-
[](Index_ x) -> Node_ { return x; },
292+
[&](size_t i) -> const auto& { return neighbors[i]; },
293+
[](const auto& x) -> Node_ { return x.first; },
314294
options,
315295
output
316296
);

0 commit comments

Comments
 (0)