Exemplo n.º 1
0
/* Function to compute Fibonacci numbers */
void fibonacci_task(void *arguments)
{
    int n, result;
    task_args *a1, *a2, *parent, *temp;
    ABT_task t1, t2;

    task_args *args = (task_args *)arguments;
    n = args->n;
    parent = args->parent;

    /* checking for base cases */
    if (n <= 2) {
        args->result = 1;
        result = 1;
        int flag = 1;
        while (flag && parent != NULL) {
            ABT_mutex_lock(parent->mutex);
            parent->result += result;
            if (result == parent->result) flag = 0;
            ABT_mutex_unlock(parent->mutex);
            result = parent->result;
            temp = parent->parent;

            if (flag && temp) {
                ABT_mutex_free(&parent->mutex);
                free(parent);
            }

            parent = temp;
        }

        ABT_mutex_free(&args->mutex);
        if (args->parent) {
            free(args);
        }
    } else {
        a1 = (task_args *)malloc(sizeof(task_args));
        a1->n = n - 1;
        a1->result = 0;
        ABT_mutex_create(&a1->mutex);
        a1->parent = args;
        ABT_task_create(g_pool, fibonacci_task, a1, &t1);

        a2 = (task_args *)malloc(sizeof(task_args));
        a2->n = n - 2;
        a2->result = 0;
        ABT_mutex_create(&a2->mutex);
        a2->parent = args;
        ABT_task_create(g_pool, fibonacci_task, a2, &t2);
    }
}
Exemplo n.º 2
0
void
__kmp_global_destroy(void)
{
    int i;

    ABT_mutex_free(&__kmp_global.stdio_lock);
    ABT_mutex_free(&__kmp_global.cat_lock);
    ABT_mutex_free(&__kmp_global.initz_lock);
    ABT_mutex_free(&__kmp_global.task_team_lock);
    for (i = 0; i < KMP_NUM_CRIT_LOCKS; i++) {
        ABT_mutex_free(&__kmp_global.crit_lock[i]);
    }

    ABT_finalize();
    __kmp_init_global = FALSE;
}
Exemplo n.º 3
0
static void finalize(void)
{
    int i;

    for (i = 1; i < max_xstreams; i++) {
        if (g_xstreams[i] != ABT_XSTREAM_NULL) {
            ABT_xstream_free(&g_xstreams[i]);
        }
    }

    ABT_mutex_free(&g_mutex);
    free(g_pools);
    free(g_xstreams);
}
Exemplo n.º 4
0
void rt1_finalize(void)
{
    int i;

    while (rt1_data->num_xstreams > 0) {
        ABT_thread_yield();
    }

    for (i = 0; i < rt1_data->max_xstreams; i++) {
        assert(rt1_data->xstreams[i] == ABT_XSTREAM_NULL);
    }

    /* Delete registered callbacks */
    ABT_event_del_callback(ABT_EVENT_STOP_XSTREAM, rt1_data->stop_cb_id);
    ABT_event_del_callback(ABT_EVENT_ADD_XSTREAM, rt1_data->add_cb_id);

    ABT_mutex_lock(rt1_data->mutex);
    ABT_mutex_free(&rt1_data->mutex);
    ABT_barrier_free(&rt1_data->bar);
    free(rt1_data->xstreams);
    free(rt1_data->app_data);
    free(rt1_data);
    rt1_data = NULL;
}
Exemplo n.º 5
0
GLT_func_prefix void glt_mutex_free(GLT_mutex * mutex) {
    CHECK(ABT_mutex_free(mutex),ABT_SUCCESS);
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    int i, j;
    int ret, expected;
    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_mutex mutex;
    ABT_xstream *xstreams;
    thread_arg_t **args;
    xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams);
    assert(xstreams != NULL);
    args = (thread_arg_t **)malloc(sizeof(thread_arg_t *) * num_xstreams);
    assert(args != NULL);
    for (i = 0; i < num_xstreams; i++) {
        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 a mutex */
    ret = ABT_mutex_create(&mutex);
    ABT_TEST_ERROR(ret, "ABT_mutex_create");

    /* 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].mutex = mutex;
            ret = ABT_thread_create(pools[i],
                    thread_func, (void *)&args[i][j], ABT_THREAD_ATTR_NULL,
                    NULL);
            ABT_TEST_ERROR(ret, "ABT_thread_create");
        }
    }

    /* Switch to other user level threads */
    ABT_thread_yield();

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

    /* Free the mutex */
    ret = ABT_mutex_free(&mutex);
    ABT_TEST_ERROR(ret, "ABT_mutex_free");

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

    /* Validation */
    expected = num_xstreams * num_threads;
    if (g_counter != expected) {
        printf("g_counter = %d\n", g_counter);
    }

    /* Finalize */
    ret = ABT_test_finalize(g_counter != expected);

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

    return ret;
}