@@ -57,7 +57,8 @@ struct BuildSnnGraphOptions {
57
57
SnnWeightScheme weighting_scheme = SnnWeightScheme::RANKED;
58
58
59
59
/* *
60
- * See `set_num_threads()`.
60
+ * Number of threads to use.
61
+ * The parallelization scheme is defined by `knncolle::parallelize()`.
61
62
*/
62
63
int num_threads = 1 ;
63
64
};
@@ -160,27 +161,12 @@ void build_snn_graph(size_t num_cells, GetNeighbors_ get_neighbors, GetIndex_ ge
160
161
std::vector<std::vector<Node_> > edge_stores (num_cells);
161
162
std::vector<std::vector<Weight_> > weight_stores (num_cells);
162
163
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 {
172
165
std::vector<Weight_> current_score (num_cells);
173
166
std::vector<Node_> current_added;
174
167
current_added.reserve (num_cells);
175
168
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
182
169
for (size_t j = start, end = start + length; j < end; ++j) {
183
- #endif
184
170
const Node_ j_cast = j;
185
171
186
172
const auto & current_neighbors = get_neighbors (j);
@@ -253,14 +239,8 @@ void build_snn_graph(size_t num_cells, GetNeighbors_ get_neighbors, GetIndex_ ge
253
239
otherscore = 0 ;
254
240
}
255
241
current_added.clear ();
256
-
257
- #ifndef SCRAN_CUSTOM_PARALLEL
258
- }
259
- }
260
- #else
261
242
}
262
- }, num_cells, options.num_threads );
263
- #endif
243
+ });
264
244
265
245
// Collating the total number of edges.
266
246
size_t nedges = 0 ;
@@ -309,8 +289,8 @@ BuildSnnGraphResults<Node_, Weight_> build_snn_graph(const knncolle::NeighborLis
309
289
BuildSnnGraphResults<Node_, Weight_> output;
310
290
build_snn_graph (
311
291
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 ; },
314
294
options,
315
295
output
316
296
);
0 commit comments