示例#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);
}
示例#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);
}
示例#3
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);
}