예제 #1
0
/* Function to compute Fibonacci numbers */
void fibonacci(void *arguments)
{
    int n;
    thread_args a1, a2;
    ABT_future future, fut;

    thread_args *args = (thread_args *)arguments;
    n = args->n;
    future = args->future;

    /* checking for base cases */
    if (n <= 2)
        args->result = 1;
    else {
        ABT_future_create(3, callback, &fut);
        ABT_future_set(fut, (void *)&args->result);

        a1.n = n - 1;
        a1.future = fut;
        ABT_thread_create(g_pool, fibonacci, &a1, ABT_THREAD_ATTR_NULL, NULL);

        a2.n = n - 2;
        a2.future = fut;
        ABT_thread_create(g_pool, fibonacci, &a2, ABT_THREAD_ATTR_NULL, NULL);

        ABT_future_wait(fut);
        ABT_future_free(&fut);
    }

    /* checking whether to signal the future */
    if (future != ABT_FUTURE_NULL) {
        ABT_future_set(future, (void *)&args->result);
    }
}
예제 #2
0
int main(int argc, char *argv[])
{
    int ret;
    ABT_xstream xstream;

    /* init and thread creation */
    ABT_test_init(argc, argv);

    ret = ABT_xstream_self(&xstream);
    ABT_TEST_ERROR(ret, "ABT_xstream_self");

    /* Get the pools attached to an execution stream */
    ABT_pool pool;
    ret = ABT_xstream_get_main_pools(xstream, 1, &pool);
    ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools");

    ret = ABT_thread_create(pool, fn1, NULL, ABT_THREAD_ATTR_NULL, &th1);
    ABT_TEST_ERROR(ret, "ABT_thread_create");
    ret = ABT_thread_create(pool, fn2, NULL, ABT_THREAD_ATTR_NULL, &th2);
    ABT_TEST_ERROR(ret, "ABT_thread_create");
    ret = ABT_thread_create(pool, fn3, NULL, ABT_THREAD_ATTR_NULL, &th3);
    ABT_TEST_ERROR(ret, "ABT_thread_create");

    ret = ABT_eventual_create(EVENTUAL_SIZE, &myeventual);
    ABT_TEST_ERROR(ret, "ABT_eventual_create");

    ABT_test_printf(1, "START\n");

    void *data;
    ABT_test_printf(1, "Thread main iteration %d waiting for eventual\n", 0);
    ABT_eventual_wait(myeventual,&data);
    ABT_test_printf(1, "Thread main continue iteration %d returning from "
            "eventual\n", 0);

    /* switch to other user-level threads */
    ABT_thread_yield();

    /* join other threads */
    ret = ABT_thread_join(th1);
    ABT_TEST_ERROR(ret, "ABT_thread_join");
    ret = ABT_thread_join(th2);
    ABT_TEST_ERROR(ret, "ABT_thread_join");
    ret = ABT_thread_join(th3);
    ABT_TEST_ERROR(ret, "ABT_thread_join");

    ABT_test_printf(1, "END\n");

    ret = ABT_test_finalize(0);

    return ret;
}
예제 #3
0
static void create_xstream(int idx)
{
    ABT_pool pool;

    ABT_xstream_create(ABT_SCHED_NULL, &g_xstreams[idx]);
    ABT_xstream_get_main_pools(g_xstreams[idx], 1, &pool);

    ABT_thread_create(pool, thread_add_sched, (void *)(intptr_t)idx,
                      ABT_THREAD_ATTR_NULL, NULL);
}
void task_creator(void *args)
{
    int i;
    vector_scal_task_args_t *arg;
    arg = (vector_scal_task_args_t *)args;
    for (i = arg->start; i < arg->end; i++) {
        ABT_thread_create(g_pools[arg->id], task_function, (void *)&arg->ptr[i],
                          ABT_THREAD_ATTR_NULL, NULL);
    }
}
예제 #5
0
int main(int argc, char *argv[])
{
    ABT_xstream xstreams[NUM_XSTREAMS];
    ABT_sched   scheds[NUM_XSTREAMS];
    int         num_pools[NUM_XSTREAMS];
    ABT_pool   *pools[NUM_XSTREAMS];
    int i, k;

    ABT_init(argc, argv);

    /* Create schedulers */
    for (i = 0; i < NUM_XSTREAMS; i++) {
        ABT_sched_predef predef;
        predef = (i % 2) ? ABT_SCHED_BASIC : ABT_SCHED_PRIO;
        ABT_sched_create_basic(predef, 0, NULL, ABT_SCHED_CONFIG_NULL,
                               &scheds[i]);
    }

    /* Create ESs */
    ABT_xstream_self(&xstreams[0]);
    ABT_xstream_set_main_sched(xstreams[0], scheds[0]);
    for (i = 1; i < NUM_XSTREAMS; i++) {
        ABT_xstream_create(scheds[i], &xstreams[i]);
    }

    /* Get the pools associated with each scheduler */
    for (i = 0; i < NUM_XSTREAMS; i++) {
        ABT_sched_get_num_pools(scheds[i], &num_pools[i]);
        pools[i] = (ABT_pool *)malloc(num_pools[i] * sizeof(ABT_pool));
        ABT_sched_get_pools(scheds[i], num_pools[i], 0, pools[i]);
    }

    /* Create ULTs */
    for (i = 0; i < NUM_XSTREAMS; i++) {
        for (k = num_pools[i] - 1; k >= 0; k--) {
            size_t tid = (i + 1) * 10 + k;
            ABT_thread_create(pools[i][k], thread_hello, (void *)tid,
                              ABT_THREAD_ATTR_NULL, NULL);
        }
    }

    /* Join & Free */
    for (i = 1; i < NUM_XSTREAMS; i++) {
        ABT_xstream_join(xstreams[i]);
        ABT_xstream_free(&xstreams[i]);
    }

    for (i = 0; i < NUM_XSTREAMS; i++) {
        free(pools[i]);
    }

    ABT_finalize();

    return 0;
}
예제 #6
0
/* Function to compute Fibonacci numbers */
void fibonacci_thread(void *arguments)
{
    int n, *n1, *n2;
    thread_args a1, a2;
    ABT_eventual eventual, f1, f2;

    thread_args *args = (thread_args *)arguments;
    n = args->n;
    eventual = args->eventual;

    /* checking for base cases */
    if (n <= 2)
        args->result = 1;
    else {
        ABT_eventual_create(sizeof(int), &f1);
        a1.n = n - 1;
        a1.eventual = f1;
        ABT_thread_create(g_pool, fibonacci_thread, &a1, ABT_THREAD_ATTR_NULL,
                          NULL);

        ABT_eventual_create(sizeof(int), &f2);
        a2.n = n - 2;
        a2.eventual = f2;
        ABT_thread_create(g_pool, fibonacci_thread, &a2, ABT_THREAD_ATTR_NULL,
                          NULL);

        ABT_eventual_wait(f1, (void **)&n1);
        ABT_eventual_wait(f2, (void **)&n2);

        args->result = *n1 + *n2;

        ABT_eventual_free(&f1);
        ABT_eventual_free(&f2);
    }

    /* checking whether to signal the eventual */
    if (eventual != ABT_EVENTUAL_NULL) {
        ABT_eventual_set(eventual, &args->result, sizeof(int));
    }
}
예제 #7
0
void thread_create(void *arg)
{
    int rank, i, ret;
    ABT_thread self;
    ABT_thread_id id;
    ABT_pool my_pool;
    ABT_thread *threads;

    assert((size_t)arg == 0);

    ret = ABT_xstream_self_rank(&rank);
    ABT_TEST_ERROR(ret, "ABT_xstream_self_rank");
    ret = ABT_thread_self(&self);
    ABT_TEST_ERROR(ret, "ABT_thread_self");
    ret = ABT_thread_get_id(self, &id);
    ABT_TEST_ERROR(ret, "ABT_thread_get_id");
    ret = ABT_thread_get_last_pool(self, &my_pool);
    ABT_TEST_ERROR(ret, "ABT_thread_get_last_pool");

    threads = (ABT_thread *)malloc(num_threads * sizeof(ABT_thread));

    /* Create ULTs */
    for (i = 0; i < num_threads; i++) {
        ret = ABT_thread_create(my_pool, thread_func, (void *)1,
                                ABT_THREAD_ATTR_NULL, &threads[i]);
        ABT_TEST_ERROR(ret, "ABT_thread_create");
    }
    ABT_test_printf(1, "[U%lu:E%u]: created %d ULTs\n", id, rank, num_threads);

    /* Join ULTs */
    for (i = 0; i < num_threads; i++) {
        ret = ABT_thread_join(threads[i]);
        ABT_TEST_ERROR(ret, "ABT_thread_join");
    }
    ABT_test_printf(1, "[U%lu:E%u]: joined %d ULTs\n", id, rank, num_threads);

    /* Revive ULTs with a different function */
    for (i = 0; i < num_threads; i++) {
        ret = ABT_thread_revive(my_pool, thread_func2, (void *)2, &threads[i]);
        ABT_TEST_ERROR(ret, "ABT_thread_revive");
    }
    ABT_test_printf(1, "[U%lu:E%u]: revived %d ULTs\n", id, rank, num_threads);

    /* Join and free ULTs */
    for (i = 0; i < num_threads; i++) {
        ret = ABT_thread_free(&threads[i]);
        ABT_TEST_ERROR(ret, "ABT_thread_free");
    }
    ABT_test_printf(1, "[U%lu:E%u]: freed %d ULTs\n", id, rank, num_threads);

    free(threads);
}
예제 #8
0
파일: accalt.c 프로젝트: adcastel/ULT_work
void accalt_ult_creation_to(void(*thread_func)(void *), void *arg, ACCALT_ult *new_ult, int dest) {
#ifdef ARGOBOTS
    ABT_pool pool;
    ABT_xstream_get_main_pools(main_team->team[dest], 1, &pool);
    ABT_thread_create(pool, thread_func, arg, ABT_THREAD_ATTR_NULL, new_ult);
#endif
#ifdef MASSIVETHREADS
    accalt_ult_creation(thread_func, arg, new_ult);
#endif
#ifdef QTHREADS
    qthread_fork_to((void *) thread_func, arg, new_ult, dest);
#endif
}
예제 #9
0
void test_create_unnamed(void *arg)
{
    int eid = (int)(size_t)arg;
    ABT_pool my_pool = g_pools[eid];
    int i, t;

    for (i = 0; i < iter; i++) {
        for (t = 0; t < num_threads; t++) {
            ABT_thread_create(my_pool, thread_func, NULL,
                              ABT_THREAD_ATTR_NULL, NULL);
        }
        ABT_thread_yield();
    }
}
예제 #10
0
파일: accalt.c 프로젝트: adcastel/ULT_work
void accalt_ult_creation(void(*thread_func)(void *), void *arg, ACCALT_ult *new_ult) {
#ifdef ARGOBOTS
    ABT_xstream xstream;
    ABT_xstream_self(&xstream);
    ABT_pool pool;
    ABT_xstream_get_main_pools(xstream, 1, &pool);
    ABT_thread_create(pool, thread_func, arg, ABT_THREAD_ATTR_NULL, new_ult);
#endif
#ifdef MASSIVETHREADS
    *new_ult = myth_create((void *) thread_func, arg);
#endif
#ifdef QTHREADS
    qthread_fork((void *) thread_func, arg, new_ult);
#endif
}
예제 #11
0
static void gen_work(void *arg)
{
    int idx = (size_t)arg;
    int num_pools = g_data.num_pools[idx];
    ABT_pool *my_pools = g_data.pools[idx];
    ABT_bool flag;
    int i, ret;
    unsigned seed = time(NULL);

    ABT_test_printf(1, "[E%d] creating work units\n", idx);

    /* Create work units on the current ES */
    /* TODO: add work units to pools of other ESs */
    for (i = 0; i < num_units; i++) {
        unit_arg_t *my_arg = (unit_arg_t *)malloc(sizeof(unit_arg_t));
        my_arg->es_id = idx;
        my_arg->my_id = i;
        my_arg->prio = rand_r(&seed) % num_pools;

        if (i & 1) {
            ret = ABT_thread_create(my_pools[my_arg->prio],
                                    thread_func, (void *)my_arg,
                                    ABT_THREAD_ATTR_NULL, NULL);
            ABT_TEST_ERROR(ret, "ABT_thread_create");
        } else {
            ret = ABT_task_create(my_pools[my_arg->prio],
                                  task_func, (void *)my_arg,
                                  NULL);
            ABT_TEST_ERROR(ret, "ABT_task_create");
        }
    }

    /* Stack the priority scheduler if it is associated with PW pools */
    ret = ABT_self_on_primary_xstream(&flag);
    ABT_TEST_ERROR(ret, "ABT_self_on_primary_stream");
    if (flag == ABT_FALSE) {
        if (accesses[idx] == ABT_POOL_ACCESS_PRIV ||
            accesses[idx] == ABT_POOL_ACCESS_SPSC ||
            accesses[idx] == ABT_POOL_ACCESS_SPMC) {
                ABT_pool main_pool;
                ret = ABT_xstream_get_main_pools(g_data.xstreams[idx],
                                                 1, &main_pool);
                ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools");
                ret = ABT_pool_add_sched(main_pool, g_data.scheds[idx]);
                ABT_TEST_ERROR(ret, "ABT_pool_add_sched");
        }
    }
}
예제 #12
0
static void decrease_xstream(void)
{
    char send_buf[SEND_BUF_LEN];
    int n;

    if (num_xstreams <= 1) {
        printf("cannot decrease # of ESs\n");
        sprintf(send_buf, "min");
        n = write(abt_pfd.fd, send_buf, strlen(send_buf));
        assert(n == strlen(send_buf));
        return;
    } else {
        ABT_thread_create(g_pools[0], thread_join_xstream, NULL,
                          ABT_THREAD_ATTR_NULL, NULL);
    }
}
예제 #13
0
static void create_work_units(void)
{
    int i;
    int ret;

    for (i = 0; i < g_data.num_scheds; i++) {
        /* Create a ULT in the first main pool */
        ABT_pool main_pool;
        ret = ABT_xstream_get_main_pools(g_data.xstreams[i], 1, &main_pool);
        ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools");

        ret = ABT_thread_create(main_pool, gen_work, (void *)(size_t)i,
                                ABT_THREAD_ATTR_NULL, NULL);
        ABT_TEST_ERROR(ret, "ABT_thread_create");
    }
}
예제 #14
0
void test_yield(void *arg)
{
    int eid = (int)(size_t)arg;
    ABT_pool    my_pool    = g_pools[eid];
    ABT_thread *my_threads = g_threads[eid];
    int i;

    for (i = 0; i < num_threads; i++) {
        ABT_thread_create(my_pool, thread_func_yield, NULL,
                          ABT_THREAD_ATTR_NULL, &my_threads[i]);
    }
    ABT_THREAD_JOIN_MANY(num_threads, my_threads);
    for (i = 0; i < num_threads; i++) {
        ABT_thread_free(&my_threads[i]);
    }
}
예제 #15
0
void test_create_join(void *arg)
{
    int eid = (int)(size_t)arg;
    ABT_pool    my_pool    = g_pools[eid];
    ABT_thread *my_threads = g_threads[eid];
    int i, t;

    for (i = 0; i < iter; i++) {
        for (t = 0; t < num_threads; t++) {
            ABT_thread_create(my_pool, thread_func, NULL,
                              ABT_THREAD_ATTR_NULL, &my_threads[t]);
        }

        ABT_THREAD_JOIN_MANY(num_threads, my_threads);
        for (t = 0; t < num_threads; t++) {
            ABT_thread_free(&my_threads[t]);
        }
    }
}
예제 #16
0
/* This function is the second callback function for the event,
 * ABT_EVENT_ADD_XSTREAM.  After all the first callback functions registered
 * for ABT_EVENT_ADD_XSTREAM return ABT_TRUE for the target ES, the Argobots
 * runtime will call this second callback function to notify that we have
 * reached an agreement. For now, the creation of the target ES needs to be
 * happened in this callback function.
 *
 * Parameters:
 *  [in] user_arg: user-provided argument
 *  [in] abt_arg : runtime-provided argument, the rank of ES to create
 */
static ABT_bool rt1_act_add_xstream(void *user_arg, void *abt_arg)
{
    rt1_data_t *my_data = (rt1_data_t *)user_arg;
    int tar_rank = (int)(intptr_t)abt_arg;
    ABT_bool result = ABT_TRUE;
    ABT_pool pool;
    ABT_xstream tar_xstream;
    int rank, ret;

    /* Create a new ES */
    if (tar_rank == ABT_XSTREAM_ANY_RANK) {
        ret = ABT_xstream_create(ABT_SCHED_NULL, &tar_xstream);
        if (ret != ABT_SUCCESS) {
            result = ABT_FALSE;
            goto fn_exit;
        }
        ABT_xstream_get_rank(tar_xstream, &rank);
    } else {
        rank = tar_rank;
        ret = ABT_xstream_create_with_rank(ABT_SCHED_NULL, rank, &tar_xstream);
        if (ret != ABT_SUCCESS) {
            printf("ES%d: failed to create\n", rank);
            result = ABT_FALSE;
            goto fn_exit;
        }
    }
    ABT_mutex_spinlock(my_data->mutex);
    assert(rank < my_data->max_xstreams &&
           my_data->xstreams[rank] == ABT_XSTREAM_NULL);
    my_data->xstreams[rank] = tar_xstream;
    my_data->num_xstreams++;
    g_xstreams[rank] = tar_xstream;
    ABT_mutex_unlock(my_data->mutex);

    ABT_xstream_get_main_pools(tar_xstream, 1, &pool);
    ABT_thread_create(pool, rt1_launcher, (void *)(intptr_t)rank,
                      ABT_THREAD_ATTR_NULL, NULL);
    printf("ES%d: created\n", rank);

  fn_exit:
    return result;
}
예제 #17
0
void test_yield_to(void *arg)
{
    int eid = (int)(size_t)arg;
    ABT_pool    my_pool    = g_pools[eid];
    ABT_thread *my_threads = g_threads[eid];
    int i;

    arg_t *args = (arg_t *)malloc(num_threads * sizeof(arg_t));
    for (i = 0; i < num_threads; i++) {
        args[i].eid = eid;
        args[i].tid = i;
        ABT_thread_create(my_pool, thread_func_yield_to, (void *)&args[i],
                          ABT_THREAD_ATTR_NULL, &my_threads[i]);
    }
    ABT_THREAD_JOIN_MANY(num_threads, my_threads);
    for (i = 0; i < num_threads; i++) {
        ABT_thread_free(&my_threads[i]);
    }
    free(args);
}
예제 #18
0
/* Create a work-stealing scheduler and push it to the pool */
static void thread_add_sched(void *arg)
{
    int idx = (int)(intptr_t)arg;
    int i;
    ABT_thread cur_thread;
    ABT_pool cur_pool;
    ABT_pool *my_pools;
    ABT_sched_config config;
    ABT_sched sched;
    size_t size;
    double t_start, t_end;

    ABT_sched_config_var cv_event_freq = {
        .idx = 0,
        .type = ABT_SCHED_CONFIG_INT
    };

    ABT_sched_config_var cv_idx = {
        .idx = 1,
        .type = ABT_SCHED_CONFIG_INT
    };

    ABT_sched_def sched_def = {
        .type = ABT_SCHED_TYPE_ULT,
        .init = sched_init,
        .run = sched_run,
        .free = sched_free,
        .get_migr_pool = NULL
    };

    /* Create a scheduler */
    ABT_sched_config_create(&config,
                            cv_event_freq, 10,
                            cv_idx, idx,
                            ABT_sched_config_var_end);
    my_pools = (ABT_pool *)malloc(sizeof(ABT_pool) * max_xstreams);
    for (i = 0; i < max_xstreams; i++) {
        my_pools[i] = g_pools[(idx + i) % max_xstreams];
    }
    ABT_sched_create(&sched_def, max_xstreams, my_pools, config, &sched);

    /* Create a ULT for the new scheduler */
    ABT_thread_create(my_pools[0], thread_work, arg, ABT_THREAD_ATTR_NULL,
                      NULL);

    /* Push the scheduler to the current pool */
    ABT_thread_self(&cur_thread);
    ABT_thread_get_last_pool(cur_thread, &cur_pool);
    ABT_pool_add_sched(cur_pool, sched);

    /* Free */
    ABT_thread_release(cur_thread);
    ABT_sched_config_free(&config);
    free(my_pools);

    t_start = ABT_get_wtime();
    while (1) {
        ABT_thread_yield();

        ABT_pool_get_total_size(cur_pool, &size);
        if (size == 0) {
            ABT_sched_free(&sched);
            break;
        }

        t_end = ABT_get_wtime();
        if ((t_end - t_start) > g_timeout) {
            ABT_sched_finish(sched);
        }
    }
}

static void thread_work(void *arg)
{
    int idx = (int)(intptr_t)arg;
    int i;
    ABT_thread cur_thread;
    ABT_pool cur_pool;
    ABT_thread *threads;
    int num_threads;
    double t_start, t_end;

    ABT_thread_self(&cur_thread);
    ABT_thread_get_last_pool(cur_thread, &cur_pool);
    ABT_thread_release(cur_thread);

    t_start = ABT_get_wtime();
    while (1) {
        num_threads = 2;
        threads = (ABT_thread *)malloc(sizeof(ABT_thread) * num_threads);
        for (i = 0; i < num_threads; i++) {
            ABT_thread_create(cur_pool, thread_hello, NULL,
                              ABT_THREAD_ATTR_NULL, &threads[i]);
        }
        for (i = 0; i < num_threads; i++) {
            ABT_thread_free(&threads[i]);
        }
        free(threads);

        if (g_signal[idx]) {
            ABT_xstream xstream;
            ABT_xstream_self(&xstream);
            ABT_xstream_cancel(xstream);
            g_signal[idx] = 0;
            break;
        }

        t_end = ABT_get_wtime();
        if ((t_end - t_start) > g_timeout) {
            break;
        }
    }
}

static void test_printf(const char *format, ...)
{
#if 0
    va_start(list, format);
    vprintf(format, list);
    va_end(list);
    fflush(stdout);
#endif
}
예제 #19
0
void rt1_launcher(void *arg)
{
    int idx = (int)(intptr_t)arg;
    ABT_thread cur_thread;
    ABT_pool cur_pool;
    ABT_sched_config config;
    ABT_sched sched;
    size_t size;
    double t_start, t_end;

    ABT_sched_config_var cv_event_freq = {
        .idx = 0,
        .type = ABT_SCHED_CONFIG_INT
    };

    ABT_sched_config_var cv_idx = {
        .idx = 1,
        .type = ABT_SCHED_CONFIG_INT
    };

    ABT_sched_def sched_def = {
        .type = ABT_SCHED_TYPE_ULT,
        .init = sched_init,
        .run = sched_run,
        .free = sched_free,
        .get_migr_pool = NULL
    };

    /* Create a scheduler */
    ABT_sched_config_create(&config,
                            cv_event_freq, 10,
                            cv_idx, idx,
                            ABT_sched_config_var_end);
    ABT_sched_create(&sched_def, 1, &rt1_data->pool, config, &sched);

    /* Push the scheduler to the current pool */
    ABT_thread_self(&cur_thread);
    ABT_thread_get_last_pool(cur_thread, &cur_pool);
    ABT_pool_add_sched(cur_pool, sched);

    /* Free */
    ABT_sched_config_free(&config);

    t_start = ABT_get_wtime();
    while (1) {
        rt1_app(idx);

        ABT_pool_get_total_size(cur_pool, &size);
        if (size == 0) {
            ABT_sched_free(&sched);
            int rank;
            ABT_xstream_self_rank(&rank);
            printf("ES%d: finished\n", rank);
            ABT_mutex_lock(rt1_data->mutex);
            rt1_data->xstreams[rank] = ABT_XSTREAM_NULL;
            rt1_data->num_xstreams--;
            ABT_mutex_unlock(rt1_data->mutex);
            break;
        }

        t_end = ABT_get_wtime();
        if ((t_end - t_start) > g_timeout) {
            ABT_sched_finish(sched);
        }
    }
}

static void rt1_app(int eid)
{
    int i, num_comps;
    size_t size;
    ABT_thread cur_thread;
    ABT_pool cur_pool;

    ABT_thread_self(&cur_thread);
    ABT_thread_get_last_pool(cur_thread, &cur_pool);

    if (eid == 0) ABT_event_prof_start();

    num_comps = rt1_data->num_comps;
    for (i = 0; i < num_comps * 2; i += 2) {
        ABT_thread_create(rt1_data->pool, rt1_app_compute,
                          (void *)(intptr_t)(eid * num_comps * 2 + i),
                          ABT_THREAD_ATTR_NULL, NULL);
        ABT_task_create(rt1_data->pool, rt1_app_compute,
                        (void *)(intptr_t)(eid * num_comps * 2 + i + 1),
                        NULL);
    }

    do {
        ABT_thread_yield();

        /* If the size of cur_pool is zero, it means the stacked scheduler has
         * been terminated because of the shrinking event. */
        ABT_pool_get_total_size(cur_pool, &size);
        if (size == 0) break;

        ABT_pool_get_total_size(rt1_data->pool, &size);
    } while (size > 0);

    if (eid == 0) {
        ABT_event_prof_stop();

        int cnt = __atomic_exchange_n(&rt1_data->cnt, 0, __ATOMIC_SEQ_CST);
        double local_work = (double)(cnt * rt1_data->num_iters);
        ABT_event_prof_publish("ops", local_work, local_work);
    }
}

static void rt1_app_compute(void *arg)
{
    int pos = (int)(intptr_t)arg;
    int i;

    rt1_data->app_data[pos] = 0;
    for (i = 0; i < rt1_data->num_iters; i++) {
        rt1_data->app_data[pos] += sin((double)pos);
    }

    __atomic_fetch_add(&rt1_data->cnt, 1, __ATOMIC_SEQ_CST);
}
예제 #20
0
int main(int argc, char *argv[])
{
    ABT_xstream *xstreams;
    ABT_pool *pools;
    ABT_thread *threads;
    int num_xstreams;
    int es = 0;
    int *args;
    int i, j, iter, t;
    int ret;

    /* Initialize */
    ABT_test_init(argc, argv);
    if (argc < 2) {
        num_xstreams = 4;
        N = 10;
        iter = 100;
    } else {
        num_xstreams = ABT_test_get_arg_val(ABT_TEST_ARG_N_ES);
        N = ABT_test_get_arg_val(ABT_TEST_ARG_N_ULT);
        iter = ABT_test_get_arg_val(ABT_TEST_ARG_N_ITER);
    }

    ABT_test_printf(1, "# of ESs : %d\n", num_xstreams);
    ABT_test_printf(1, "# of ULTs: %d\n", N * N);
    ABT_test_printf(1, "# of iter: %d\n", iter);

    xstreams = (ABT_xstream *)malloc(num_xstreams * sizeof(ABT_xstream));
    pools = (ABT_pool *)malloc(num_xstreams * sizeof(ABT_pool));
    threads = (ABT_thread *)malloc(N * N * sizeof(ABT_thread));

    values = (int *)malloc(N * sizeof(int));
    row_barrier = (ABT_barrier *)malloc(N * sizeof(ABT_barrier));
    col_barrier = (ABT_barrier *)malloc(N * sizeof(ABT_barrier));

    /* Create the values and barriers */
    for (i = 0; i < N; i++) {
        ret = ABT_barrier_create((size_t)N, &row_barrier[i]);
        ABT_TEST_ERROR(ret, "ABT_barrier_create");
        ret = ABT_barrier_create((size_t)N, &col_barrier[i]);
        ABT_TEST_ERROR(ret, "ABT_barrier_create");
    }
    ret = ABT_barrier_create((size_t)N * N, &global_barrier);
    ABT_TEST_ERROR(ret, "ABT_barrier_create");

    args = (int *)malloc(2 * N * N * sizeof(int));

    /* Create ESs */
    for (t = 0; t < iter; t++) {
        ABT_test_printf(1, "iter=%d\n", t);
        ret = ABT_xstream_self(&xstreams[0]);
        ABT_TEST_ERROR(ret, "ABT_xstream_self");
        for (i = 1; i < num_xstreams; i++) {
            ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]);
            ABT_TEST_ERROR(ret, "ABT_xstream_create");
        }

        /* Get the first pool of each ES */
        for (i = 0; i < num_xstreams; i++) {
            ret = ABT_xstream_get_main_pools(xstreams[i], 1, &pools[i]);
            ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools");
        }

        /* Create ULTs */
        for (i = 0; i < N; i++) {
            values[i] = i;
        }
        for (i = 0; i < N; i++) {
            for (j = 0; j < N; j++) {
                args[2*(i*N+j)] = i;
                args[2*(i*N+j)+1] = j;
                ret = ABT_thread_create(pools[es], run, (void *)&args[2*(i*N+j)],
                                        ABT_THREAD_ATTR_NULL, &threads[i*N+j]);
                ABT_TEST_ERROR(ret, "ABT_thread_create");
                es = (es + 1) % num_xstreams;
            }
        }

        /* Join and free ULTs */
        for (i = 0; i < N; i++) {
            for (j = 0; j < N; j++) {
                ret = ABT_thread_free(&threads[i*N+j]);
                ABT_TEST_ERROR(ret, "ABT_thread_free");
            }
        }

        /* Join ESs */
        for (i = 1; i < num_xstreams; i++) {
            ret = ABT_xstream_join(xstreams[i]);
            ABT_TEST_ERROR(ret, "ABT_xstream_join");
        }

        /* Free ESs */
        for (i = 1; i < num_xstreams; i++) {
            ret = ABT_xstream_free(&xstreams[i]);
            ABT_TEST_ERROR(ret, "ABT_xstream_free");
        }
    }

    /* Free the barriers */
    for (i = 0; i < N; i++) {
        ret = ABT_barrier_free(&row_barrier[i]);
        ABT_TEST_ERROR(ret, "ABT_barrier_create");
        ret = ABT_barrier_free(&col_barrier[i]);
        ABT_TEST_ERROR(ret, "ABT_barrier_create");
    }
    ret = ABT_barrier_free(&global_barrier);
    ABT_TEST_ERROR(ret, "ABT_barrier_free");

    /* Finalize */
    ret = ABT_test_finalize(0);

    free(xstreams);
    free(pools);
    free(threads);
    free(values);
    free(row_barrier);
    free(col_barrier);
    free(args);

    return ret;
}
예제 #21
0
int main(int argc, char *argv[])
{
    int i, j;
    int ret;
    int num_xstreams = DEFAULT_NUM_XSTREAMS;
    int num_threads = DEFAULT_NUM_THREADS;
    if (argc > 1) num_xstreams = atoi(argv[1]);
    assert(num_xstreams >= 0);
    if (argc > 2) num_threads = atoi(argv[2]);
    assert(num_threads >= 0);

    ABT_xstream *xstreams;
    xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams);

    ABT_pool *pools;
    pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_xstreams);

    /* Initialize */
    ABT_test_init(argc, argv);

    /* Create Execution Streams */
    ret = ABT_xstream_self(&xstreams[0]);
    ABT_TEST_ERROR(ret, "ABT_xstream_self");
    for (i = 1; i < num_xstreams; i++) {
        ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]);
        ABT_TEST_ERROR(ret, "ABT_xstream_create");
    }

    /* Get the pools attached to an execution stream */
    for (i = 0; i < num_xstreams; i++) {
        ret = ABT_xstream_get_main_pools(xstreams[i], 1, pools+i);
        ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools");
    }

    /* Create threads */
    for (i = 0; i < num_xstreams; i++) {
        for (j = 0; j < num_threads; j++) {
            size_t tid = i * num_threads + j + 1;
            ret = ABT_thread_create(pools[i],
                    thread_func, (void *)tid, ABT_THREAD_ATTR_NULL,
                    NULL);
            ABT_TEST_ERROR(ret, "ABT_thread_create");
        }
    }

    /* Join Execution Streams */
    for (i = 1; i < num_xstreams; i++) {
        ret = ABT_xstream_join(xstreams[i]);
        ABT_TEST_ERROR(ret, "ABT_xstream_join");
    }

    /* Free Execution Streams */
    for (i = 1; i < num_xstreams; i++) {
        ret = ABT_xstream_free(&xstreams[i]);
        ABT_TEST_ERROR(ret, "ABT_xstream_free");
    }

    /* Finalize */
    ret = ABT_test_finalize(0);

    free(pools);
    free(xstreams);

    return ret;
}
예제 #22
0
/* Main function */
int main(int argc, char *argv[])
{
    int n, i, expected;
    int num_xstreams;
    ABT_xstream *xstreams;
    ABT_thread thread;
    thread_args args;

    if (argc > 1 && strcmp(argv[1], "-h") == 0) {
        printf("Usage: %s [N=10] [num_ES=4]\n", argv[0]);
        return EXIT_SUCCESS;
    }
    n = argc > 1 ? atoi(argv[1]) : N;
    num_xstreams = argc > 2 ? atoi(argv[2]) : NUM_XSTREAMS;
    printf("# of ESs: %d\n", num_xstreams);

    /* initialization */
    ABT_init(argc, argv);

    /* shared pool creation */
    ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE,
                          &g_pool);

    /* ES creation */
    xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams);
    ABT_xstream_self(&xstreams[0]);
    ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT,
                                     1, &g_pool);
    for (i = 1; i < num_xstreams; i++) {
        ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pool,
                                 ABT_SCHED_CONFIG_NULL, &xstreams[i]);
        ABT_xstream_start(xstreams[i]);
    }

    args.n = n;
    args.future = ABT_FUTURE_NULL;
    ABT_thread_create(g_pool, fibonacci, &args, ABT_THREAD_ATTR_NULL, &thread);

    /* join the thread */
    ABT_thread_join(thread);
    ABT_thread_free(&thread);

    /* join ESs */
    for (i = 1; i < num_xstreams; i++) {
        ABT_xstream_join(xstreams[i]);
        ABT_xstream_free(&xstreams[i]);
    }

    ABT_finalize();

    free(xstreams);

    printf("Fib(%d): %d\n", n, args.result);
    expected = verify(n);
    if (args.result != expected) {
        fprintf(stderr, "ERROR: expected=%d\n", expected);
        exit(EXIT_FAILURE);
    }

    return EXIT_SUCCESS;
}
예제 #23
0
int main(int argc, char *argv[])
{
    int i, j;
    int ret;
    int num_xstreams = DEFAULT_NUM_XSTREAMS;
    int num_threads = DEFAULT_NUM_THREADS;
    if (argc > 1) num_xstreams = atoi(argv[1]);
    assert(num_xstreams >= 0);
    if (argc > 2) num_threads = atoi(argv[2]);
    assert(num_threads >= 0);

    ABT_xstream *xstreams;
    ABT_thread **threads;
    thread_arg_t **args;
    xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams);
    threads = (ABT_thread **)malloc(sizeof(ABT_thread *) * num_xstreams);
    args = (thread_arg_t **)malloc(sizeof(thread_arg_t *) * num_xstreams);
    for (i = 0; i < num_xstreams; i++) {
        threads[i] = (ABT_thread *)malloc(sizeof(ABT_thread) * num_threads);
        for (j = 0; j < num_threads; j++) {
            threads[i][j] = ABT_THREAD_NULL;
        }
        args[i] = (thread_arg_t *)malloc(sizeof(thread_arg_t) * num_threads);
    }

    /* Initialize */
    ABT_test_init(argc, argv);

    /* Create Execution Streams */
    ret = ABT_xstream_self(&xstreams[0]);
    ABT_TEST_ERROR(ret, "ABT_xstream_self");
    for (i = 1; i < num_xstreams; i++) {
        ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]);
        ABT_TEST_ERROR(ret, "ABT_xstream_create");
    }

    /* Get the pools attached to an execution stream */
    ABT_pool *pools;
    pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_xstreams);
    for (i = 0; i < num_xstreams; i++) {
        ret = ABT_xstream_get_main_pools(xstreams[i], 1, pools+i);
        ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools");
    }

    /* Create threads */
    for (i = 0; i < num_xstreams; i++) {
        for (j = 0; j < num_threads; j++) {
            int tid = i * num_threads + j + 1;
            args[i][j].id = tid;
            args[i][j].num_threads = num_threads;
            args[i][j].threads = &threads[i][0];
            ret = ABT_thread_create(pools[i],
                    thread_func, (void *)&args[i][j], ABT_THREAD_ATTR_NULL,
                    &threads[i][j]);
            ABT_TEST_ERROR(ret, "ABT_thread_create");
        }
    }

    /* Join Execution Streams */
    for (i = 1; i < num_xstreams; i++) {
        ret = ABT_xstream_join(xstreams[i]);
        ABT_TEST_ERROR(ret, "ABT_xstream_join");
    }

    /* Free threads and Execution Streams */
    for (i = 0; i < num_xstreams; i++) {
        for (j = 0; j < num_threads; j++) {
            ret = ABT_thread_free(&threads[i][j]);
            ABT_TEST_ERROR(ret, "ABT_thread_free");
        }

        if (i == 0) continue;

        ret = ABT_xstream_free(&xstreams[i]);
        ABT_TEST_ERROR(ret, "ABT_xstream_free");
    }

    /* Finalize */
    ret = ABT_test_finalize(0);

    for (i = 0; i < num_xstreams; i++) {
        free(args[i]);
        free(threads[i]);
    }
    free(args);
    free(threads);
    free(pools);
    free(xstreams);

    return ret;
}
예제 #24
0
int main(int argc, char *argv[])
{
    int i, provided;
    int ret;
    int num_threads = DEFAULT_NUM_THREADS;
    if (argc > 1)
        num_threads = atoi(argv[1]);
    if (num_threads % 2 != 0) {
        if (rank == 0)
            printf("number of user level threads should be even\n");
        exit(0);
    }
    assert(num_threads >= 0);
    num_loop = NUM_LOOP;
    if (argc > 2)
        num_loop = atoi(argv[2]);
    assert(num_loop >= 0);
    buf_size = BUF_SIZE;
    if (argc > 3)
        buf_size = atoi(argv[3]);
    assert(buf_size >= 0);

    /* Initialize */
    ret = ABT_init(argc, argv);
    if (ret != ABT_SUCCESS) {
        printf("Failed to initialize Argobots\n");
        return EXIT_FAILURE;
    }

    ret = MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
    if (provided != MPI_THREAD_MULTIPLE) {
        printf("Cannot initialize with MPI_THREAD_MULTIPLE\n");
        return EXIT_FAILURE;
    }

    send_buf = (int *) malloc(buf_size * sizeof(int));
    recv_buf = (int *) malloc(buf_size * sizeof(int));

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    if (profiling)
        t1 = MPI_Wtime();
    ABT_xstream xstream;
    ABT_pool pools;
    ABT_thread *threads = (ABT_thread *) malloc(num_threads * sizeof(ABT_thread));

    ABT_xstream_self(&xstream);
    ABT_xstream_get_main_pools(xstream, 1, &pools);
    for (i = 0; i < num_threads; i++) {
        size_t tid = i + 1;
        if (i % 2 == 0) {
            ret = ABT_thread_create(pools,
                                    thread_send_func, (void *) tid,
                                    ABT_THREAD_ATTR_NULL, &threads[i]);
        } else {
            ret = ABT_thread_create(pools,
                                    thread_recv_func, (void *) tid,
                                    ABT_THREAD_ATTR_NULL, &threads[i]);
        }
        HANDLE_ERROR(ret, "ABT_thread_create");
    }

    /* Join and free the ULT children */
    for (i = 0; i < num_threads; i++)
        ABT_thread_free(&threads[i]);

    if (profiling) {
        t2 = MPI_Wtime();
        if (rank == 0) {
            fprintf(stdout, "%*s%*f\n", FIELD_WIDTH, "Time", FIELD_WIDTH, t2 - t1);
        }
    }

    /* Finalize */
    free(threads);
    free(send_buf);
    free(recv_buf);
    MPI_Finalize();
    ABT_finalize();
    return EXIT_SUCCESS;
}
예제 #25
0
int main(int argc, char *argv[])
{
  // Argobots definitions
  int ret, i;
  num_threads = 0;

  // Sockets Definitions
  int fd, cfd;
  struct sockaddr_in svaddr;
  struct sockaddr_storage claddr;
  socklen_t addrlen;
  signal(SIGINT, sighandler);

  ABT_init(argc, argv);

  int abts = 0;//ABT_snoozer_xstream_self_set();
  if (abts != 0){
    fprintf(stderr, "%s\n", "ABT snoozer xstream self error");
    exit(-1);
  }
  xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * CORES);
  ret = ABT_xstream_self(&xstreams[0]);
  if(ret != 0){
    fprintf(stderr, "%s\n", "ABT xstream self error");
    exit(-1);
  }
  ret = ABT_xstream_get_main_pools(xstreams[0], 1, &pool);
  if(ret != 0){
    fprintf(stderr, "%s\n", "ABT xstream pool error");
    exit(-1);
  }
  ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE, &g_pool);

  /* ES creation */
  ABT_xstream_self(&xstreams[0]);
  ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT,
                                   1, &g_pool);
  for (i = 1; i < CORES; i++) {
      ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pool,
                               ABT_SCHED_CONFIG_NULL, &xstreams[i]);
      ABT_xstream_start(xstreams[i]);
  }
  //abtio = abt_io_init(CORES);
  //assert(abtio != NULL);

  fd = socket(AF_INET, SOCK_STREAM, 0);
  if(fd < 0){
    fprintf(stderr, "%s\n", "Socket creating error");
    exit(-1);
  }
  memset(&svaddr, 0, sizeof(struct sockaddr_in));
  svaddr.sin_family = AF_INET;
  svaddr.sin_addr.s_addr = INADDR_ANY;
  svaddr.sin_port = htons(PORTNUM);

  ret = bind(fd, (struct sockaddr *) &svaddr, sizeof(struct sockaddr_in));
  if(ret < 0){
    fprintf(stderr, "%s\n", "Socket binding error");
    exit(-1);
  }
  if( listen(fd, BACKLOG) == -1)
  {
    fprintf(stderr, "%s\n", "Socket listening error");
    exit(-1);
  }
  int aio_sock =  abt_io_socket_initialize(1000);
  if(aio_sock <= 0)
    printf("Initialize io_sock error\n");
  //printf("USer: main: epoll fd = %d\n", aio_sock);
  addrlen = sizeof(struct sockaddr_storage);
  while(1){
    cfd = accept(fd, (struct sockaddr *)&claddr, &addrlen);
    if(cfd == -1){
      fprintf(stderr, "%s\n", "Socket accepting error");
      exit(-1);
    }
    //printf("accepted client on file descriptor %d\n", cfd);
    struct thread_args* ta = (struct thread_args*) malloc (sizeof(ta));
    ta->epfd = aio_sock;
    ta->fd = cfd;
    ABT_thread_create(g_pool, handle_client, (void *) ta, ABT_THREAD_ATTR_NULL, threads[num_threads++]);
  }

  return 0;
}
예제 #26
0
int main(int argc, char *argv[])
{
    ABT_xstream *xstreams;
    ABT_thread *masters;
    int i, ret;

    /* Initialize */
    ABT_test_init(argc, argv);
    if (argc < 2) {
        num_xstreams = DEFAULT_NUM_XSTREAMS;
        num_threads  = DEFAULT_NUM_THREADS;
        num_tasks    = DEFAULT_NUM_TASKS;
        num_iter     = DEFAULT_NUM_ITER;
    } else {
        num_xstreams = ABT_test_get_arg_val(ABT_TEST_ARG_N_ES);
        num_tasks    = ABT_test_get_arg_val(ABT_TEST_ARG_N_TASK);
        num_threads  = num_tasks * 2;
        num_iter     = ABT_test_get_arg_val(ABT_TEST_ARG_N_ITER);
    }

    ABT_test_printf(1, "# of ESs        : %d\n", num_xstreams);
    ABT_test_printf(1, "# of ULTs/ES    : %d\n", num_threads + num_tasks);
    ABT_test_printf(1, "# of tasklets/ES: %d\n", num_tasks);
    ABT_test_printf(1, "# of iter       : %d\n", num_iter);

    xstreams = (ABT_xstream *)malloc(num_xstreams * sizeof(ABT_xstream));
    pools    = (ABT_pool *)malloc(num_xstreams * sizeof(ABT_pool));
    masters  = (ABT_thread *)malloc(num_xstreams * sizeof(ABT_thread));

    /* Create Execution Streams */
    ret = ABT_xstream_self(&xstreams[0]);
    ABT_TEST_ERROR(ret, "ABT_xstream_self");
    for (i = 1; i < num_xstreams; i++) {
        ret = ABT_xstream_create(ABT_SCHED_NULL, &xstreams[i]);
        ABT_TEST_ERROR(ret, "ABT_xstream_create");
    }

    /* Get the main pool of each ES */
    for (i = 0; i < num_xstreams; i++) {
        ret = ABT_xstream_get_main_pools(xstreams[i], 1, &pools[i]);
        ABT_TEST_ERROR(ret, "ABT_xstream_get_main_pools");
    }

    /* Create a master ULT for each ES */
    for (i = 1; i < num_xstreams; i++) {
        ret = ABT_thread_create(pools[i], eventual_test, (void *)(size_t)i,
                                ABT_THREAD_ATTR_NULL, &masters[i]);
        ABT_TEST_ERROR(ret, "ABT_thread_create");
    }

    eventual_test((void *)0);

    /* Join master ULTs */
    for (i = 1; i < num_xstreams; i++) {
        ret = ABT_thread_free(&masters[i]);
        ABT_TEST_ERROR(ret, "ABT_thread_free");
    }

    /* Join and free Execution Streams */
    for (i = 1; i < num_xstreams; i++) {
        ret = ABT_xstream_join(xstreams[i]);
        ABT_TEST_ERROR(ret, "ABT_xstream_join");
        ret = ABT_xstream_free(&xstreams[i]);
        ABT_TEST_ERROR(ret, "ABT_xstream_free");
    }

    /* Finalize */
    ret = ABT_test_finalize(0);

    free(xstreams);
    free(pools);
    free(masters);

    return ret;
}
예제 #27
0
void eventual_test(void *arg)
{
    int i, t, ret;
    size_t pid = (size_t)arg;
    int eid = (int)pid;

    ABT_thread *threads;
    arg_t *thread_args;
    int *nbytes;
    ABT_eventual *evs1;

    ABT_thread *waiters;
    arg_t *waiter_args;
    ABT_task *tasks;
    arg_t *task_args;
    ABT_eventual *evs2;

    ABT_test_printf(1, "[M%u] start\n", (unsigned)(size_t)arg);

    assert(num_tasks * 2 == num_threads);

    threads = (ABT_thread *)malloc(num_threads * sizeof(ABT_thread));
    thread_args = (arg_t *)malloc(num_threads * sizeof(arg_t));
    nbytes = (int *)malloc(num_tasks * sizeof(int));
    evs1 = (ABT_eventual *)malloc(num_tasks * sizeof(ABT_eventual));
    assert(threads && thread_args && nbytes && evs1);

    waiters = (ABT_thread *)malloc(num_tasks * sizeof(ABT_thread));
    waiter_args = (arg_t *)malloc(num_tasks * sizeof(arg_t));
    tasks = (ABT_task *)malloc(num_tasks * sizeof(ABT_task));
    task_args = (arg_t *)malloc(num_tasks * sizeof(arg_t));
    evs2 = (ABT_eventual *)malloc(num_tasks * sizeof(ABT_eventual));
    assert(waiters && waiter_args && tasks && task_args && evs2);

    for (t = 0; t < num_tasks; t++) {
        nbytes[t] = (t & 1) ? sizeof(int) : 0;

        ret = ABT_eventual_create(nbytes[t], &evs1[t]);
        ABT_TEST_ERROR(ret, "ABT_eventual_create");

        ret = ABT_eventual_create(nbytes[t], &evs2[t]);
        ABT_TEST_ERROR(ret, "ABT_eventual_create");
    }

    for (i = 0; i < num_iter; i++) {
        ABT_test_printf(2, "[M%u] iter=%d\n", (unsigned)(size_t)arg, i);

        /* Use eventual between ULTs */
        for (t = 0; t < num_threads; t += 2) {
            thread_args[t].eid = eid;
            thread_args[t].tid = t;
            thread_args[t].ev = evs1[t/2];
            thread_args[t].nbytes = nbytes[t/2];
            thread_args[t].op_type = OP_WAIT;
            ret = ABT_thread_create(pools[pid], thread_func, &thread_args[t],
                                    ABT_THREAD_ATTR_NULL, &threads[t]);
            ABT_TEST_ERROR(ret, "ABT_thread_create");
            pid = (pid + 1) % num_xstreams;

            thread_args[t+1].eid = eid;
            thread_args[t+1].tid = t + 1;
            thread_args[t+1].ev = evs1[t/2];
            thread_args[t+1].nbytes = nbytes[t/2];
            thread_args[t+1].op_type = OP_SET;
            ret = ABT_thread_create(pools[pid], thread_func, &thread_args[t+1],
                                    ABT_THREAD_ATTR_NULL, &threads[t+1]);
            ABT_TEST_ERROR(ret, "ABT_thread_create");
            pid = (pid + 1) % num_xstreams;
        }

        /* Use eventual between ULT and tasklet */
        for (t = 0; t < num_tasks; t++) {
            waiter_args[t].ev = evs2[t];
            waiter_args[t].nbytes = nbytes[t];
            waiter_args[t].op_type = OP_WAIT;
            ret = ABT_thread_create(pools[pid], thread_func, &waiter_args[t],
                                    ABT_THREAD_ATTR_NULL, &waiters[t]);
            ABT_TEST_ERROR(ret, "ABT_thread_create");
            pid = (pid + 1) % num_xstreams;

            task_args[t].ev = evs2[t];
            task_args[t].nbytes = nbytes[t];
            task_args[t].op_type = OP_SET;
            ret = ABT_task_create(pools[pid], task_func, &task_args[t], &tasks[t]);
            ABT_TEST_ERROR(ret, "ABT_task_create");
            pid = (pid + 1) % num_xstreams;
        }

        for (t = 0; t < num_threads; t++) {
            ret = ABT_thread_free(&threads[t]);
            ABT_TEST_ERROR(ret, "ABT_thread_free");
        }

        for (t = 0; t < num_tasks; t++) {
            ret = ABT_thread_free(&waiters[t]);
            ABT_TEST_ERROR(ret, "ABT_thread_free");
            ret = ABT_task_free(&tasks[t]);
            ABT_TEST_ERROR(ret, "ABT_task_free");
        }

        for (t = 0; t < num_tasks; t++) {
            ret = ABT_eventual_reset(evs1[t]);
            ABT_TEST_ERROR(ret, "ABT_eventual_reset");
            ret = ABT_eventual_reset(evs2[t]);
            ABT_TEST_ERROR(ret, "ABT_eventual_reset");
        }

    }

    for (t = 0; t < num_tasks; t++) {
        ret = ABT_eventual_free(&evs1[t]);
        ABT_TEST_ERROR(ret, "ABT_eventual_free");
        ret = ABT_eventual_free(&evs2[t]);
        ABT_TEST_ERROR(ret, "ABT_eventual_free");
    }

    free(threads);
    free(thread_args);
    free(nbytes);
    free(evs1);

    free(waiters);
    free(waiter_args);
    free(tasks);
    free(task_args);
    free(evs2);

    ABT_test_printf(1, "[M%u] end\n", (unsigned)(size_t)arg);
}
예제 #28
0
int main(int argc, char *argv[])
{
    ABT_xstream xstream;
    ABT_pool pool;
    ABT_timer timer;
    int i, iter;
    double t_overhead;

    ABT_test_read_args(argc, argv);
    iter = ABT_test_get_arg_val(ABT_TEST_ARG_N_ITER);

    ABT_timer_create(&timer);
    ABT_timer_start(timer);
    ABT_timer_stop(timer);
    ABT_timer_get_overhead(&t_overhead);
    for (i = 0; i < T_LAST; i++) t_timers[i] = 0.0;

    /* measure init/finalize time (cold) */
    ABT_timer_start(timer);
    ABT_init(argc, argv);
    ABT_finalize();
    ABT_timer_stop_and_read(timer, &t_timers[T_INIT_FINALIZE_COLD]);
    t_timers[T_INIT_FINALIZE_COLD] -= t_overhead;

    /* measure init/finalize time */
    for (i = 0; i < iter; i++) {
        ABT_timer_start(timer);
        ABT_init(argc, argv);
        ABT_timer_stop_and_add(timer, &t_timers[T_INIT]);

        ABT_timer_start(timer);
        ABT_finalize();
        ABT_timer_stop_and_add(timer, &t_timers[T_FINALIZE]);
    }
    t_timers[T_INIT] /= iter;
    t_timers[T_INIT] -= t_overhead;
    t_timers[T_FINALIZE] /= iter;
    t_timers[T_FINALIZE] -= t_overhead;
    t_timers[T_INIT_FINALIZE] = t_timers[T_INIT] + t_timers[T_FINALIZE];

    /* measure time of init/finalize with work */
    for (i = 0; i < iter; i++) {
        ABT_timer_start(timer);
        ABT_init(argc, argv);
        ABT_timer_stop_and_add(timer, &t_timers[T_INIT_FINALIZE_WITH_WORK]);

        ABT_xstream_create(ABT_SCHED_NULL, &xstream);
        ABT_xstream_get_main_pools(xstream, 1, &pool);
        ABT_thread_create(pool, thread_func, NULL, ABT_THREAD_ATTR_NULL,
                          NULL);
        ABT_xstream_join(xstream);
        ABT_xstream_free(&xstream);

        ABT_timer_start(timer);
        ABT_finalize();
        ABT_timer_stop_and_add(timer, &t_timers[T_INIT_FINALIZE_WITH_WORK]);
    }
    t_timers[T_INIT_FINALIZE_WITH_WORK] /= iter;
    t_timers[T_INIT_FINALIZE_WITH_WORK] -= t_overhead;

    /* output */
    int line_size = 45;
    ABT_test_print_line(stdout, '-', line_size);
    printf("Avg. execution time (in seconds, %d times)\n", iter);
    ABT_test_print_line(stdout, '-', line_size);
    for (i = 0; i < T_LAST; i++) {
        printf("%-23s  %.9f\n", t_names[i], t_timers[i]);
    }
    ABT_test_print_line(stdout, '-', line_size);

    ABT_timer_free(&timer);

    return EXIT_SUCCESS;
}
int main(int argc, char *argv[])
{
    int i, j, r;
    int num_xstreams;
    char *str, *endptr;
    ABT_xstream *xstreams;
    ABT_thread *threads;
    vector_scal_task_args_t *args;
    int inner_xstreams;
    double *time, avg_time = 0.0;

    num_xstreams = (argc > 1) ? atoi(argv[1]) : NUM_XSTREAMS;
    inner_xstreams = (argc > 2) ? atoi(argv[2]) : NUM_XSTREAMS;
    int rep = (argc > 3) ? atoi(argv[3]) : NUM_REPS;
    time = (double *)malloc(sizeof(double) * rep);

    init();

    g_pools = (ABT_pool *)malloc(sizeof(ABT_pool) * num_xstreams);
    xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams);
    threads = (ABT_thread *)malloc(sizeof(ABT_thread) * num_xstreams);
    args = (vector_scal_task_args_t *)malloc(sizeof(vector_scal_task_args_t)
            * num_xstreams);

    /* initialization */
    ABT_init(argc, argv);

    for (i = 0; i < num_xstreams; i++) {
        ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE,
                              &g_pools[i]);
    }

    /* ES creation */
    ABT_xstream_self(&xstreams[0]);
    ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT,
                                     1, &g_pools[0]);

    for (i = 1; i < num_xstreams; i++) {
        ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pools[i],
                                 ABT_SCHED_CONFIG_NULL, &xstreams[i]);
        ABT_xstream_start(xstreams[i]);
    }

    /* Each task is created on the xstream which is going to execute it */

    for (r = 0; r < rep; r++) {
        time[r] = ABT_get_wtime();

        int bloc = NUM / (num_xstreams);
        int rest = NUM % (num_xstreams);
        int start = 0;
        int end = 0;

        for (j = 0; j < num_xstreams; j++) {
            start = end;
            int inc = (j < rest) ? 1 : 0;
            end += bloc + inc;
            args[j].start = start;
            args[j].end = end;
            args[j].it = NUM;
            args[j].nxstreams = inner_xstreams;
            if (j > 0) {
                ABT_thread_create(g_pools[j], vector_scal_launch,
                                  (void *)&args[j], ABT_THREAD_ATTR_NULL,
                                  &threads[j]);
            }
        }
        vector_scal_launch((void *)&args[0]);

        for (j = 1; j < num_xstreams; j++) {
            ABT_thread_free(&threads[j]);
        }

        time[r] = ABT_get_wtime() - time[r];
        avg_time += time[r];
    }
    avg_time /= rep;
    printf("%d %d %f\n", num_xstreams, inner_xstreams, avg_time);
    check();

    for (i = 1; i < num_xstreams; i++) {
        ABT_xstream_join(xstreams[i]);
        ABT_xstream_free(&xstreams[i]);
    }

    ABT_finalize();

    free(g_pools);
    free(xstreams);
    free(threads);
    free(args);
    free(time);

    return EXIT_SUCCESS;
}
예제 #30
0
/* Main function */
int main(int argc, char *argv[])
{
    int n, i, result, expected;
    int num_xstreams;
    ABT_xstream *xstreams;

    ABT_thread thread;
    thread_args args_thread;
    ABT_task task;
    task_args *args_task;

    if (argc > 1 && strcmp(argv[1], "-h") == 0) {
        printf("Usage: %s [N=10] [num_ES=4]\n", argv[0]);
        return EXIT_SUCCESS;
    }
    n = argc > 1 ? atoi(argv[1]) : N;
    num_xstreams = argc > 2 ? atoi(argv[2]) : NUM_XSTREAMS;
    printf("# of ESs: %d\n", num_xstreams);

    if (n <= 2) {
        result = 1;
        goto fn_result;
    }

    /* initialization */
    ABT_init(argc, argv);

    /* shared pool creation */
    ABT_pool_create_basic(ABT_POOL_FIFO, ABT_POOL_ACCESS_MPMC, ABT_TRUE,
                          &g_pool);

    /* ES creation */
    xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams);
    ABT_xstream_self(&xstreams[0]);
    ABT_xstream_set_main_sched_basic(xstreams[0], ABT_SCHED_DEFAULT,
                                     1, &g_pool);
    for (i = 1; i < num_xstreams; i++) {
        ABT_xstream_create_basic(ABT_SCHED_DEFAULT, 1, &g_pool,
                                 ABT_SCHED_CONFIG_NULL, &xstreams[i]);
        ABT_xstream_start(xstreams[i]);
    }

    /* creating thread */
    args_thread.n = n - 1;
    args_thread.eventual = ABT_EVENTUAL_NULL;
    ABT_thread_create(g_pool, fibonacci_thread, &args_thread, ABT_THREAD_ATTR_NULL, &thread);

    /* creating task */
    args_task = (task_args *)malloc(sizeof(task_args));
    args_task->n = n - 2;
    args_task->result = 0;
    ABT_mutex_create(&args_task->mutex);
    args_task->parent = NULL;
    ABT_task_create(g_pool, fibonacci_task, args_task, &task);

    /* switch to other user-level threads */
    ABT_thread_yield();

    /* join other threads */
    ABT_thread_join(thread);
    ABT_thread_free(&thread);

    /* join ESs */
    for (i = 1; i < num_xstreams; i++) {
        ABT_xstream_join(xstreams[i]);
        ABT_xstream_free(&xstreams[i]);
    }

    result = args_thread.result + args_task->result;
    free(args_task);

    ABT_finalize();

    free(xstreams);

  fn_result:
    printf("Fib(%d): %d\n", n, result);
    expected = verify(n);
    if (result != expected) {
        fprintf(stderr, "ERROR: expected=%d\n", expected);
        exit(EXIT_FAILURE);
    }

    return EXIT_SUCCESS;
}