From 3f458c3456429c93c105ba9cc9f8088f2b258719 Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Tue, 30 Dec 2014 11:05:02 +0100 Subject: [PATCH] mtapi_c: added simple load balancing --- mtapi_c/src/embb_mtapi_task_t.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mtapi_c/src/embb_mtapi_task_t.c b/mtapi_c/src/embb_mtapi_task_t.c index 29ac633..f04830d 100644 --- a/mtapi_c/src/embb_mtapi_task_t.c +++ b/mtapi_c/src/embb_mtapi_task_t.c @@ -209,9 +209,23 @@ static mtapi_task_hndl_t embb_mtapi_task_start( task->queue.id = EMBB_MTAPI_IDPOOL_INVALID_ID; } - /* load balancing is unsupported right now, - so always choose action 0 */ + /* load balancing: choose action with minimum tasks */ action_index = 0; + for (mtapi_uint_t ii = 0; ii < local_job->num_actions; ii++) { + if (embb_mtapi_action_pool_is_handle_valid( + node->action_pool, local_job->actions[ii])) { + embb_mtapi_action_t * act_m = + embb_mtapi_action_pool_get_storage_for_handle( + node->action_pool, local_job->actions[action_index]); + embb_mtapi_action_t * act_i = + embb_mtapi_action_pool_get_storage_for_handle( + node->action_pool, local_job->actions[ii]); + if (embb_atomic_load_int(&act_m->num_tasks) > + embb_atomic_load_int(&act_i->num_tasks)) { + action_index = ii; + } + } + } if (embb_mtapi_action_pool_is_handle_valid( node->action_pool, local_job->actions[action_index])) { task->action = local_job->actions[action_index]; -- libgit2 0.26.0