Exemple #1
0
/**
 * i'm being really sloppy here. ideally, one should probably save the rc and
 * then display or do some other cool thing with it. don't be like this code. if
 * QUO_construct or QUO_init fail, then someone using this could just continue
 * without the awesomeness that is libquo. they cleanup after themselves, so
 * things *should* be in an okay state after an early failure. the failures may
 * be part of a larger problem, however. */
static int
init(context_t **c)
{
    int name_len = 0;
    context_t *newc = NULL;
    /* alloc our context */
    if (NULL == (newc = calloc(1, sizeof(*newc)))) return 1;
    /* libquo requires that MPI be initialized before its init is called */
    if (MPI_SUCCESS != MPI_Init(NULL, NULL)) return 1;
    /* gather some basic job info from our mpi lib */
    if (MPI_SUCCESS != MPI_Comm_size(MPI_COMM_WORLD, &(newc->nranks))) goto err;
    /* ...and more */
    if (MPI_SUCCESS != MPI_Comm_rank(MPI_COMM_WORLD, &(newc->rank))) goto err;
    /* stash my host's name */
    if (MPI_SUCCESS != MPI_Get_processor_name(newc->hostname, &name_len)) {
        goto err;
    }
    /* can be called at any point -- even before init and construct. */
    if (QUO_SUCCESS != QUO_version(&(newc->qv), &(newc->qsv))) goto err;
    /* relatively expensive call. you only really want to do this once at the
     * beginning of time and pass the context all over the place within your
     * code. */
    if (QUO_SUCCESS != QUO_create(&newc->quo)) goto err;
    newc->mpi_inited = true;
    *c = newc;
    return 0;
err:
    (void)fini(newc);
    return 1;
}
static int
quo_init(p1_context_t *ctx)
{
    /* can be called at any point -- even before construct. */
    if (QUO_SUCCESS != QUO_version(&(ctx->qv), &(ctx->qsv))) return 1;
    /* relatively expensive call. you only really want to do this once at the
     * beginning of time and pass the context all over the place within your
     * code.
     */
    if (QUO_SUCCESS != QUO_create(&ctx->quo, ctx->init_comm_dup)) return 1;
    //
    return 0;
}
Exemple #3
0
int
main(void)
{
    int qrc = QUO_SUCCESS, erc = EXIT_SUCCESS;
    int qv = 0, qsv = 0, nnodes = 0, nnoderanks = 0;
    int nsockets = 0, ncores = 0, npus = 0;
    char *bad_func = NULL;
    char *cbindstr = NULL, *cbindstr2 = NULL, *cbindstr3 = NULL;
    int bound = 0, bound2 = 0, bound3 = 0;
    QUO_context quo = NULL;
    inf_t info;

    if (init(&info)) {
        bad_func = "info";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_version(&qv, &qsv))) {
        bad_func = "QUO_version";
        goto out;
    }
    /* cheap call */
    if (QUO_SUCCESS != (qrc = QUO_create(&quo))) {
        bad_func = "QUO_create";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_nsockets(quo, &nsockets))) {
        bad_func = "QUO_nsockets";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_ncores(quo, &ncores))) {
        bad_func = "QUO_ncores";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_npus(quo, &npus))) {
        bad_func = "QUO_npus";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_bound(quo, &bound))) {
        bad_func = "QUO_bound";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_stringify_cbind(quo, &cbindstr))) {
        bad_func = "QUO_stringify_cbind";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_nnodes(quo, &nnodes))) {
        bad_func = "QUO_nnodes";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_nqids(quo, &nnoderanks))) {
        bad_func = "QUO_nnodes";
        goto out;
    }
    /* last argument ignored with QUO_BIND_PUSH_OBJ option */
    if (QUO_SUCCESS != (qrc = QUO_bind_push(quo, QUO_BIND_PUSH_OBJ,
                                            QUO_OBJ_CORE, 0))) {
        bad_func = "QUO_bind_push";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_stringify_cbind(quo, &cbindstr2))) {
        bad_func = "QUO_stringify_cbind";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_bound(quo, &bound2))) {
        bad_func = "QUO_bound";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_bind_pop(quo))) {
        bad_func = "QUO_bind_pop";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_stringify_cbind(quo, &cbindstr3))) {
        bad_func = "QUO_stringify_cbind";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_bound(quo, &bound3))) {
        bad_func = "QUO_bound";
        goto out;
    }
    if (QUO_SUCCESS != (qrc = QUO_free(quo))) {
        bad_func = "QUO_free";
        goto out;
    }
    printf("### quo version: %d.%d ###\n", qv, qsv);
    printf("### nnodes: %d\n", nnodes);
    printf("### nnoderanks: %d\n", nnoderanks);
    printf("### nsockets: %d\n", nsockets);
    printf("### ncores: %d\n", ncores);
    printf("### npus: %d\n", npus);
    printf("### process %d [%s] bound: %s\n",
           (int)getpid(), cbindstr, bound ? "true" : "false");
    printf("### process %d [%s] bound: %s\n",
           (int)getpid(), cbindstr2, bound2 ? "true" : "false");
    printf("### process %d [%s] bound: %s\n",
           (int)getpid(), cbindstr3, bound3 ? "true" : "false");
    /* the string returned by QUO_machine_topo_stringify MUST be free'd by us */
    free(cbindstr);
    free(cbindstr2);
out:
    if (NULL != bad_func) {
        fprintf(stderr, "xxx %s failure in: %s\n", __FILE__, bad_func);
        erc = EXIT_FAILURE;
    }
    (void)fini(&info);
    return erc;
}