diff --git a/emper/Emper.hpp b/emper/Emper.hpp index 34b0459e41d0d139069a4141beeb7ddcf427bca6..ff3c27f2acb554bf93888d2f3c9105d44b714d8e 100644 --- a/emper/Emper.hpp +++ b/emper/Emper.hpp @@ -2,12 +2,16 @@ // Copyright © 2020-2021 Florian Schmaus #pragma once +#include <cstddef> #include <string> #include "emper-config.h" namespace emper { +static const size_t WS_VICTIM_COUNT = EMPER_WS_VICTIM_COUNT; +static const size_t WS_VICTIM_DENOMINATOR = EMPER_WS_VICTIM_DENOMINATOR; + static const bool STATS = #ifdef EMPER_STATS true diff --git a/emper/strategies/AbstractWorkStealingScheduler.cpp b/emper/strategies/AbstractWorkStealingScheduler.cpp index fa954ad6ef596d9b5ee05c1be4300823cc163e62..83ca87697bed3529b67f7e2ae5a5b544c06bcb39 100644 --- a/emper/strategies/AbstractWorkStealingScheduler.cpp +++ b/emper/strategies/AbstractWorkStealingScheduler.cpp @@ -212,8 +212,17 @@ popBottom: const workerid_t checkAnywhereQueueAt = workerCount * CHECK_ANYWHERE_QUEUE_AT_PERCENTAGE; workerid_t startWorkerId = currentWorker->nextRandomWorkerId(); - // TODO: See how reducing the loop bound affects things. - for (workerid_t i = 0; i < workerCount; ++i) { + // TODO: See how changing the victim count affects things. + const workerid_t victimCount = [&] { + if constexpr (emper::WS_VICTIM_COUNT) + return emper::WS_VICTIM_COUNT; + else if constexpr (emper::WS_VICTIM_DENOMINATOR) + return workerCount / emper::WS_VICTIM_DENOMINATOR; + else + return workerCount; + }(); + + for (workerid_t i = 0; i < victimCount; ++i) { workerid_t victim = (startWorkerId + i) % workerCount; // Don't steal from ourselves. diff --git a/meson.build b/meson.build index aeaf05dc19077c2eaa5c0b53b41ba4213a091b14..570e785654663c63ed51ea952cce7b9d035a0a84 100644 --- a/meson.build +++ b/meson.build @@ -75,6 +75,14 @@ conf_data.set('EMPER_' + locked_unbounded_queue_impl.to_upper() + '_LOCKED_UNBOU default_scheduling_strategy = get_option('default_scheduling_strategy') conf_data.set('EMPER_DEFAULT_SCHEDULING_STRATEGY_' + default_scheduling_strategy.to_upper(), true) +ws_victim_count = get_option('work_stealing_victim_count') +ws_victim_denominator = get_option('work_stealing_victim_denominator') +if ws_victim_count != 0 and ws_victim_denominator !=0 + error('work_stealing_victim_count and work_stealing_victim_denominator are mutally exclusive') +endif +conf_data.set('EMPER_WS_VICTIM_COUNT', ws_victim_count) +conf_data.set('EMPER_WS_VICTIM_DENOMINATOR', ws_victim_denominator) + log_level = get_option('log_level') if log_level == 'automatic' # output only error messages in release builds diff --git a/meson_options.txt b/meson_options.txt index 2a6e56270107e580b83c8b1cb551ee69f23a12e6..7eef4ea722c0c9cd7659e08fd11e9eb99a5e7f09 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -93,6 +93,18 @@ option( ], value: 'work_stealing', ) +option( + 'work_stealing_victim_count', + type: 'integer', + value: 0, + description: 'Absolute count of victims tried in the work-stealing' +) +option( + 'work_stealing_victim_denominator', + type: 'integer', + value: 0, + description: 'Fraction of all workers to steal work from' +) option( 'overflow_queue', type: 'boolean',