Skip to content

Commit

Permalink
Fix and test for #60 - adding a large number of tasksets with m_SetSi…
Browse files Browse the repository at this point in the history
…ze > square of number of threads
  • Loading branch information
dougbinks committed Feb 27, 2021
1 parent 2b020b2 commit 16291d0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
48 changes: 48 additions & 0 deletions example/TestAll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,54 @@ int main(int argc, const char * argv[])
serialTask.ExecuteRange( range, 0 );
sumSerial = serialTask.m_pPartialSums[0].count;



RunTestFunction(
"Test Lots of TaskSets",
[&]()->bool
{
g_TS.Initialize( baseConfig );

static constexpr uint32_t TASK_RANGE = 65*65;
static constexpr uint32_t TASK_COUNT = 50;


struct TaskSet : public enki::ITaskSet
{
TaskSet() : enki::ITaskSet(TASK_RANGE) {};
virtual void ExecuteRange( TaskSetPartition range_, uint32_t threadnum_ ) override
{
if( range_.start >= TASK_RANGE && range_.end > TASK_RANGE )
{
countErrors.fetch_add(1);
}
}

std::atomic<int32_t> countErrors{ 0 };
};

TaskSet tasks[TASK_COUNT];

for( uint32_t i = 0; i < TASK_COUNT; ++i )
{
g_TS.AddTaskSetToPipe( &tasks[i] );
}

g_TS.WaitforAll();

bool bSuccess = true;
for( uint32_t i = 0; i < TASK_COUNT; ++i )
{
if( tasks[i].countErrors.load( std::memory_order_relaxed ) > 0 )
{
bSuccess = false;
break;
}
}

return bSuccess;
}
);
RunTestFunction(
"Parallel Reduction Sum",
[&]()->bool
Expand Down
3 changes: 2 additions & 1 deletion src/TaskScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,10 @@ void TaskScheduler::SplitAndAddTask( uint32_t threadNum_, SubTaskSet subTask_, u
}
numAdded = 0;
// alter range to run the appropriate fraction
if( taskToAdd.pTask->m_RangeToRun < rangeToSplit_ )
if( taskToAdd.pTask->m_RangeToRun < taskToAdd.partition.end - taskToAdd.partition.start )
{
taskToAdd.partition.end = taskToAdd.partition.start + taskToAdd.pTask->m_RangeToRun;
assert( taskToAdd.partition.end <= taskToAdd.pTask->m_SetSize );
subTask_.partition.start = taskToAdd.partition.end;
}
taskToAdd.pTask->ExecuteRange( taskToAdd.partition, threadNum_ );
Expand Down

0 comments on commit 16291d0

Please sign in to comment.