Example #1
0
static void thread_hello(void *arg)
{
    int old_rank, cur_rank;
    ABT_thread self;
    ABT_thread_id id;
    char *msg;

    ABT_xstream_self_rank(&cur_rank);
    ABT_thread_self(&self);
    ABT_thread_get_id(self, &id);
    ABT_thread_release(self);

    test_printf("[U%lu:E%d] Hello, world!\n", id, cur_rank);

    ABT_thread_yield();

    old_rank = cur_rank;
    ABT_xstream_self_rank(&cur_rank);
    msg = (cur_rank == old_rank) ? "" : " (stolen)";
    test_printf("[U%lu:E%d] Hello again #1.%s\n", id, cur_rank, msg);

    ABT_thread_yield();

    old_rank = cur_rank;
    ABT_xstream_self_rank(&cur_rank);
    msg = (cur_rank == old_rank) ? "" : " (stolen)";
    test_printf("[U%lu:E%d] Hello again #2.%s\n", id, cur_rank, msg);

    ABT_thread_yield();

    old_rank = cur_rank;
    ABT_xstream_self_rank(&cur_rank);
    msg = (cur_rank == old_rank) ? "" : " (stolen)";
    test_printf("[U%lu:E%d] Goodbye, world!%s\n", id, cur_rank, msg);
}
Example #2
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);
}
Example #3
0
int accalt_get_thread_num() {
#ifdef ARGOBOTS
    int rank;
    ABT_xstream_self_rank(&rank);
    return rank;
#endif
#ifdef MASSIVETHREADS
    return myth_get_worker_num();
#endif
#ifdef QTHREADS
    return qthread_shep();
#endif
}
void vector_scal_launch(void *arguments)
{
    int i, it, j, num_ults, rank, mystart, myend, p;
    ABT_task *tasks;
    ABT_xstream xstream;
    ABT_xstream_self(&xstream);
    vector_scal_task_args_t *arg;
    arg = (vector_scal_task_args_t *) arguments;
    vector_scal_args_t *args;
    it = arg->it;
    num_ults = arg->nxstreams;
    mystart = arg->start;
    myend = arg->end;

    args = (vector_scal_args_t *)malloc(sizeof(vector_scal_args_t)
                                        * num_ults);

    tasks = (ABT_task *)malloc(sizeof(ABT_task) * num_ults);

    int bloc = it / (num_ults);
    int rest = it % (num_ults);
    ABT_xstream_self_rank(&rank);
    for (i = mystart; i < myend; i++) {
        int start = 0;
        int end = 0;
        for (j = 0; j < num_ults; j++) {
            start = end;
            int inc = (j < rest) ? 1 : 0;
            end += bloc + inc;
            args[j].start = start;
            args[j].end = end;
            args[j].x = i;

            if (j > 0) {
                ABT_task_create(g_pools[rank], vector_scal, (void *)&args[j], &tasks[j]);
            }
        }
        vector_scal((void *)&args[0]);
        for (p = 1; p < num_ults; p++) {
            ABT_task_free(&tasks[p]);
        }
    }

    free(tasks);
    free(args);
}
Example #5
0
void thread_func2(void *arg)
{
    int rank, ret;
    ABT_thread self;
    ABT_thread_id id;

    assert((size_t)arg == 2);

    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");

    ABT_test_printf(1, "[U%lu:E%u]: Good-bye, world!\n", id, rank);
}
Example #6
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);
}
Example #7
0
void thread_hello(void *arg)
{
    int rank, tid = (int)(size_t)arg;
    ABT_xstream_self_rank(&rank);
    printf("[U%d:E%d] Hello, world!\n", tid, rank);
}