48 template<
class labelListType,
class neiOp,
class filterOp>
51 labelListType& result,
52 const label startingIndex,
53 const neiOp& neighbourCalculator,
54 const filterOp& selector
59 result.append(startingIndex);
63 front.
append(startingIndex);
66 boolList alreadySelected(neighbourCalculator.size(),
false);
75 neighbourCalculator(eLabel, neighbours);
79 const label nei = neighbours[neiI];
83 if( alreadySelected[nei] )
88 alreadySelected[nei] =
true;
153 template<
class labelListType,
class neiOp,
class filterOp>
156 labelListType& elementInGroup,
157 const neiOp& neighbourCalculator,
158 const filterOp& selector
163 elementInGroup.setSize(neighbourCalculator.size());
177 # pragma omp parallel num_threads(nThreads)
180 const label chunkSize =
181 Foam::max(1, neighbourCalculator.size() / nThreads);
184 const label threadI = omp_get_thread_num();
186 const label threadI(0);
191 const label minEl = threadI * chunkSize;
193 label maxEl = minEl + chunkSize;
194 if( threadI == (nThreads - 1) )
195 maxEl =
Foam::max(maxEl, neighbourCalculator.size());
197 label& groupI = nGroupsAtThread[threadI];
200 for(
label elI=minEl;elI<maxEl;++elI)
202 if( elementInGroup[elI] != -1 )
207 elementInGroup[elI] = groupI;
211 while( front.
size() )
216 neighbourCalculator(eLabel, neighbours);
220 const label nei = neighbours[neiI];
222 if( (nei < 0) || (elementInGroup[nei] != -1) )
225 if( (nei < minEl) || (nei >= maxEl) )
229 threadCommPairs.
append(std::make_pair(elI, nei));
231 else if( selector(nei) )
234 elementInGroup[nei] = groupI;
248 forAll(nGroupsAtThread, i)
249 nGroups += nGroupsAtThread[i];
256 for(
label i=0;i<threadI;++i)
257 startGroup += nGroupsAtThread[i];
259 for(
label elI=minEl;elI<maxEl;++elI)
260 elementInGroup[elI] += startGroup;
268 forAll(threadCommPairs, cfI)
270 const std::pair<label, label>& lp = threadCommPairs[cfI];
271 const label groupI = elementInGroup[lp.first];
272 const label neiGroup = elementInGroup[lp.second];
274 if( (neiGroup >= nGroups) || (groupI >= nGroups) )
276 <<
" groupI " << groupI <<
" are >= than "
281 localNeiGroups[groupI].appendIfNotIn(neiGroup);
282 localNeiGroups[neiGroup].appendIfNotIn(groupI);
287 # pragma omp critical
290 neighbouringGroups.
setSize(nGroups);
292 forAll(localNeiGroups, groupI)
304 forAll(neighbouringGroups, i)
308 helper[j] = neighbouringGroups(i, j);
312 neighbouringGroups[i] = helper;
318 globalGroupLabel.
setSize(nGroups);
319 globalGroupLabel = -1;
324 forAll(neighbouringGroups, groupI)
326 if( globalGroupLabel[groupI] != -1 )
338 forAll(connectedGroups, gI)
339 globalGroupLabel[connectedGroups[gI]] = counter;
346 forAll(neighbouringGroups, groupI)
348 if( globalGroupLabel[groupI] != -1 )
351 forAllRow(neighbouringGroups, groupI, ngI)
352 globalGroupLabel[neighbouringGroups(groupI, ngI)] = counter;
367 label startGroup(0), totalNumGroups(0);
370 totalNumGroups += nGroupsAtProc[procI];
373 startGroup += nGroupsAtProc[procI];
377 forAll(globalGroupLabel, groupI)
378 globalGroupLabel[groupI] += startGroup;
385 std::map<label, DynList<label> > neiGroups;
387 neighbourCalculator.collectGroups
429 forAll(globalNeiGroups, procI)
443 allGroupsNewLabel.
setSize(totalNumGroups);
444 allGroupsNewLabel = -1;
449 if( allGroupsNewLabel[groupI] != -1 )
461 forAll(connectedGroups, gI)
462 allGroupsNewLabel[connectedGroups[gI]] = counter;
475 forAll(globalGroupLabel, groupI)
477 const label ngI = globalGroupLabel[groupI];
478 globalGroupLabel[groupI] = allGroupsNewLabel[ngI];
484 # pragma omp parallel for schedule(dynamic, 50)
486 forAll(elementInGroup, elI)
488 if( elementInGroup[elI] < 0 )
491 elementInGroup[elI] = globalGroupLabel[elementInGroup[elI]];