codes-jobmap.c 1.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
/*
 * Copyright (C) 2015 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

#include <assert.h>
#include <stdlib.h>

#include "codes-jobmap-method-impl.h"
#include "codes/codes-jobmap.h"

extern struct codes_jobmap_impl jobmap_dummy_impl;

struct codes_jobmap_ctx *
codes_jobmap_configure(enum codes_jobmap_type t, void const * params)
{
    struct codes_jobmap_ctx *c = malloc(sizeof(*c));
    assert(c);
    int rc;

    c->type = t;
    switch(t) {
        case CODES_JOBMAP_DUMMY:
            c->impl = &jobmap_dummy_impl;
            break;
        default:
            free(c);
            fprintf(stderr, "ERROR: unknown jobmap type %d\n", t);
            return NULL;
    }
    rc = c->impl->configure(params, &c->ctx);
    if (rc) {
        fprintf(stderr, "ERROR: failed to configure jobmap type %d\n", t);
        free(c);
        return NULL;
    }
    else
        return c;
}

void codes_jobmap_destroy(struct codes_jobmap_ctx *c)
{
    c->impl->destroy(c->ctx);
    free(c);
}

48
struct codes_jobmap_id codes_jobmap_to_local_id(
49 50 51
        int id,
        struct codes_jobmap_ctx const * c)
{
52 53 54 55 56 57 58 59
    return c->impl->to_local(id, c->ctx);
}

int codes_jobmap_to_global_id(
        struct codes_jobmap_id id,
        struct codes_jobmap_ctx const * c)
{
    return c->impl->to_global(id, c->ctx);
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
}

int codes_jobmap_get_num_jobs(struct codes_jobmap_ctx const * c)
{
    return c->impl->get_num_jobs(c->ctx);
}

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  indent-tabs-mode: nil
 * End:
 *
 * vim: ts=8 sts=4 sw=4 expandtab
 */