@@ -213,9 +213,15 @@ void memoryCheck(size_t nPoints) {
213
213
* @param nThreads : Optional argument of number of threads to use.
214
214
*/
215
215
ConnectedComponentLabeling::ConnectedComponentLabeling (const size_t &startId, std::optional<int > nThreads)
216
- : m_startId(startId), m_nThreads(std::move(nThreads)) {
217
- if (m_nThreads.has_value () && m_nThreads.value () < 0 ) {
218
- throw std::invalid_argument (" Cannot request that CCL runs with less than one thread!" );
216
+ : m_startId(startId) {
217
+ if (nThreads.has_value ()) {
218
+ if (nThreads.value () < 0 ) {
219
+ throw std::invalid_argument (" Cannot request that CCL runs with less than one thread!" );
220
+ } else {
221
+ m_nThreadsToUse = nThreads.value (); // Follow explicit instructions if provided.
222
+ }
223
+ } else {
224
+ m_nThreadsToUse = API::FrameworkManager::Instance ().getNumOMPThreads (); // Figure it out.
219
225
}
220
226
}
221
227
@@ -237,18 +243,6 @@ size_t ConnectedComponentLabeling::getStartLabelId() const { return m_startId; }
237
243
*/
238
244
ConnectedComponentLabeling::~ConnectedComponentLabeling () = default ;
239
245
240
- /* *
241
- * Get the number of threads available
242
- * @return : Number of available threads
243
- */
244
- int ConnectedComponentLabeling::getNThreads () const {
245
- if (m_nThreads.has_value ()) {
246
- return m_nThreads.value (); // Follow explicit instructions if provided.
247
- } else {
248
- return API::FrameworkManager::Instance ().getNumOMPThreads (); // Figure it out.
249
- }
250
- }
251
-
252
246
/* *
253
247
* Perform the work of the CCL algorithm
254
248
* - Pre filtering of background
@@ -273,20 +267,18 @@ ClusterMap ConnectedComponentLabeling::calculateDisjointTree(const IMDHistoWorks
273
267
274
268
// For each process maintains pair of index from within process bounds to
275
269
// index outside process bounds
276
- const int nThreadsToUse = getNThreads ();
277
-
278
- if (nThreadsToUse > 1 ) {
279
- auto iterators = ws->createIterators (nThreadsToUse);
280
- const size_t maxClustersPossible = calculateMaxClusters (ws.get (), nThreadsToUse);
270
+ if (m_nThreadsToUse > 1 ) {
271
+ auto iterators = ws->createIterators (m_nThreadsToUse);
272
+ const size_t maxClustersPossible = calculateMaxClusters (ws.get (), m_nThreadsToUse);
281
273
282
- std::vector<VecEdgeIndexPair> parallelEdgeVec (nThreadsToUse );
274
+ std::vector<VecEdgeIndexPair> parallelEdgeVec (m_nThreadsToUse );
283
275
284
- std::vector<std::map<size_t , std::shared_ptr<Cluster>>> parallelClusterMapVec (nThreadsToUse );
276
+ std::vector<std::map<size_t , std::shared_ptr<Cluster>>> parallelClusterMapVec (m_nThreadsToUse );
285
277
286
278
// ------------- Stage One. Local CCL in parallel.
287
279
g_log.debug (" Parallel solve local CCL" );
288
280
// PARALLEL_FOR_NO_WSP_CHECK()
289
- for (int i = 0 ; i < nThreadsToUse ; ++i) {
281
+ for (int i = 0 ; i < m_nThreadsToUse ; ++i) {
290
282
API::IMDIterator *iterator = iterators[i].get ();
291
283
boost::scoped_ptr<BackgroundStrategy> strategy (baseStrategy->clone ()); // local strategy
292
284
VecEdgeIndexPair &edgeVec = parallelEdgeVec[i]; // local edge indexes
@@ -334,8 +326,8 @@ ClusterMap ConnectedComponentLabeling::calculateDisjointTree(const IMDHistoWorks
334
326
335
327
for (auto &indexPairVec : parallelEdgeVec) {
336
328
for (auto &iit : indexPairVec) {
337
- DisjointElement &a = neighbourElements[iit.get <0 >()];
338
- DisjointElement &b = neighbourElements[iit.get <1 >()];
329
+ const DisjointElement &a = neighbourElements[iit.get <0 >()];
330
+ const DisjointElement &b = neighbourElements[iit.get <1 >()];
339
331
clusterRegister.merge (a, b);
340
332
}
341
333
}
0 commit comments