static void sched_run(ABT_sched sched) { uint32_t work_count = 0; void *data; sched_data_t *p_data; ABT_pool my_pool; size_t size; ABT_unit unit; uint32_t event_freq; int num_pools; ABT_pool *pools; ABT_sched_get_data(sched, &data); p_data = sched_data_get_ptr(data); event_freq = p_data->event_freq; ABT_sched_get_num_pools(sched, &num_pools); pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_pools); ABT_sched_get_pools(sched, num_pools, 0, pools); my_pool = pools[0]; while (1) { /* Execute one work unit from the scheduler's pool */ ABT_pool_pop(my_pool, &unit); if (unit != ABT_UNIT_NULL) { ABT_xstream_run_unit(unit, my_pool); } else if (num_pools > 1) { /* Steal a work unit from other pools */ int target = (num_pools == 2) ? 1 : (rand() % (num_pools - 1) + 1); ABT_pool tar_pool = pools[target]; ABT_pool_get_size(tar_pool, &size); if (size > 0) { /* Pop one work unit */ ABT_pool_pop(tar_pool, &unit); if (unit != ABT_UNIT_NULL) { ABT_xstream_run_unit(unit, tar_pool); } } } if (++work_count >= event_freq) { abt_check_events(p_data->idx); ABT_bool stop; ABT_sched_has_to_stop(sched, &stop); if (stop == ABT_TRUE) break; work_count = 0; ABT_xstream_check_events(sched); } } free(pools); }
static void sched_run(ABT_sched sched) { uint32_t work_count = 0; sched_data_t *p_data; ABT_pool my_pool; int num_pools; ABT_pool *pools; ABT_unit unit; int target; ABT_bool stop; unsigned seed = time(NULL); ABT_sched_get_data(sched, (void **)&p_data); ABT_sched_get_num_pools(sched, &num_pools); pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_pools); ABT_sched_get_pools(sched, num_pools, 0, pools); my_pool = pools[0]; while (1) { /* Execute one work unit from the scheduler's pool */ ABT_pool_pop(my_pool, &unit); if (unit != ABT_UNIT_NULL) { ABT_xstream_run_unit(unit, my_pool); } else if (num_pools > 1) { /* Steal a work unit from other pools */ target = (num_pools == 2) ? 1 : (rand_r(&seed) % (num_pools-1) + 1); ABT_pool_pop(pools[target], &unit); if (unit != ABT_UNIT_NULL) { ABT_xstream_run_unit(unit, pools[target]); } } if (++work_count >= p_data->event_freq) { work_count = 0; ABT_xstream_check_events(sched); ABT_sched_has_to_stop(sched, &stop); if (stop == ABT_TRUE) { /* TODO: Migrate work units if we have private pools */ break; } } } free(pools); }