MCPcopy Create free account
hub / github.com/cameron314/concurrentqueue / FindProcessorGroupIndex

Function FindProcessorGroupIndex

benchmarks/tbb/tbb_misc_ex.cpp:322–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320#define HoleAdjusted(procIdx, grpIdx) (procIdx + (holeIdx <= grpIdx))
321
322int FindProcessorGroupIndex ( int procIdx ) {
323 // In case of oversubscription spread extra workers in a round robin manner
324 int holeIdx;
325 const int numProcs = theProcessorGroups[ProcessorGroupInfo::NumGroups - 1].numProcsRunningTotal;
326 if ( procIdx >= numProcs - 1 ) {
327 holeIdx = INT_MAX;
328 procIdx = (procIdx - numProcs + 1) % numProcs;
329 }
330 else
331 holeIdx = ProcessorGroupInfo::HoleIndex;
332 __TBB_ASSERT( hardware_concurrency_info == initialization_complete, "FindProcessorGroupIndex is used before AvailableHwConcurrency" );
333 // Approximate the likely group index assuming all groups are of the same size
334 int i = procIdx / theProcessorGroups[0].numProcs;
335 // Make sure the approximation is a valid group index
336 if (i >= ProcessorGroupInfo::NumGroups) i = ProcessorGroupInfo::NumGroups-1;
337 // Now adjust the approximation up or down
338 if ( theProcessorGroups[i].numProcsRunningTotal > HoleAdjusted(procIdx, i) ) {
339 while ( theProcessorGroups[i].numProcsRunningTotal - theProcessorGroups[i].numProcs > HoleAdjusted(procIdx, i) ) {
340 __TBB_ASSERT( i > 0, NULL );
341 --i;
342 }
343 }
344 else {
345 do {
346 ++i;
347 } while ( theProcessorGroups[i].numProcsRunningTotal <= HoleAdjusted(procIdx, i) );
348 }
349 __TBB_ASSERT( i < ProcessorGroupInfo::NumGroups, NULL );
350 return i;
351}
352
353void MoveThreadIntoProcessorGroup( void* hThread, int groupIndex ) {
354 __TBB_ASSERT( hardware_concurrency_info == initialization_complete, "MoveThreadIntoProcessorGroup is used before AvailableHwConcurrency" );

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected