Skip to content

[AbstractWorkStealingScheduler] Get rid of "rand() % workerCount"

Maxim Onciul requested to merge random-worker-id into master

The "rand() % workerCount" constructed used in the work-stealing scheduler is flawed. It has a bias toward lower worker IDs due the modulo operation. This is something I always wanted to get rid of, but never found the time to do it. Until know.

Get rid of it and replace it with std::uniform_int_distribution<workerid_t> (as field the Worker instance).

The changes in AbstractWorkStealingScheduler.cpp look more than they are actually. I had to introduce a new scope since to the goto instruction would otherwise skip the initialization of currentWorker.

The main changes in AbstractWorkStealingScheduler are

  • use currentWorker->nextRandomWorkerId() (instead of the flawed construct)
  • currentWorker->getWorkerId() (instead of Runtime::getWorkerId())

Merge request reports

Loading