Exemple #1
0
void accalt_tasklet_join(ACCALT_tasklet *tasklet) {
#ifdef ARGOBOTS
    ABT_task_free(tasklet);
#endif
#ifdef MASSIVETHREADS
    myth_join(*tasklet, NULL);
#endif
#ifdef QTHREADS
    qthread_readFF(NULL, tasklet);
#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);
}
Exemple #3
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);
}
Exemple #4
0
int main(int argc, char *argv[])
{
    int i, j, ret;
    int num_xstreams = DEFAULT_NUM_XSTREAMS;
    int num_threads = DEFAULT_NUM_THREADS;
    int num_tasks = DEFAULT_NUM_TASKS;
    if (argc > 1) num_xstreams = atoi(argv[1]);
    assert(num_xstreams >= 0);
    if (argc > 2) num_threads = atoi(argv[2]);
    assert(num_threads >= 0);
    if (argc > 3) num_tasks = atoi(argv[3]);
    assert(num_tasks >= 0);

    ABT_xstream *xstreams;
    ABT_thread **threads;
    thread_arg_t **thread_args;
    ABT_task *tasks;
    task_arg_t *task_args;

    xstreams = (ABT_xstream *)malloc(sizeof(ABT_xstream) * num_xstreams);
    threads = (ABT_thread **)malloc(sizeof(ABT_thread *) * num_xstreams);
    thread_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;
        }
        thread_args[i] = (thread_arg_t *)malloc(sizeof(thread_arg_t) *
                                                num_threads);
    }
    tasks = (ABT_task *)malloc(sizeof(ABT_task) * num_tasks);
    task_args = (task_arg_t *)malloc(sizeof(task_arg_t) * num_tasks);

    /* 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;
            thread_args[i][j].id = tid;
            thread_args[i][j].num_threads = num_threads;
            thread_args[i][j].threads = &threads[i][0];
            ret = ABT_thread_create(pools[i],
                    thread_func, (void *)&thread_args[i][j],
                    ABT_THREAD_ATTR_NULL,
                    &threads[i][j]);
            ABT_TEST_ERROR(ret, "ABT_thread_create");
        }
    }

    /* Create tasks with task_func1 */
    for (i = 0; i < num_tasks; i++) {
        size_t num = 100 + i;
        ret = ABT_task_create(pools[i % num_xstreams],
                              task_func1, (void *)num,
                              NULL);
        ABT_TEST_ERROR(ret, "ABT_task_create");
    }

    /* Create tasks with task_func2 */
    for (i = 0; i < num_tasks; i++) {
        task_args[i].num = 100 + i;
        ret = ABT_task_create(pools[i % num_xstreams],
                              task_func2, (void *)&task_args[i],
                              &tasks[i]);
        ABT_TEST_ERROR(ret, "ABT_task_create");
    }

    /* Switch to other work units */
    ABT_thread_yield();

    /* Results of task_funcs2 */
    for (i = 0; i < num_tasks; i++) {
        ABT_task_state state;
        do {
            ABT_task_get_state(tasks[i], &state);
            ABT_thread_yield();
        } while (state != ABT_TASK_STATE_TERMINATED);

        ABT_test_printf(1, "task_func2: num=%lu result=%llu\n",
               task_args[i].num, task_args[i].result);

        /* Free named tasks */
        ret = ABT_task_free(&tasks[i]);
        ABT_TEST_ERROR(ret, "ABT_task_free");
    }

    /* 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 = 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(thread_args[i]);
        free(threads[i]);
    }
    free(thread_args);
    free(threads);
    free(task_args);
    free(tasks);
    free(pools);
    free(xstreams);

    return ret;
}