codes-jobmap.c 1.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * 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;
14
extern struct codes_jobmap_impl jobmap_list_impl;
15
extern struct codes_jobmap_impl jobmap_identity_impl;
16 17 18 19 20 21 22 23 24 25

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) {
26 27
        case CODES_JOBMAP_IDENTITY:
            c->impl = &jobmap_identity_impl;
28
            break;
29
        case CODES_JOBMAP_LIST:
30
            c->impl = &jobmap_list_impl;
31
            break;
32 33 34
        case CODES_JOBMAP_DUMMY:
            c->impl = &jobmap_dummy_impl;
            break;
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
        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);
}

56
struct codes_jobmap_id codes_jobmap_to_local_id(
57 58 59
        int id,
        struct codes_jobmap_ctx const * c)
{
60 61 62 63 64 65 66 67
    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);
68 69 70 71 72 73 74
}

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

75 76 77 78 79
int codes_jobmap_get_num_ranks(int job_id, struct codes_jobmap_ctx const * c)
{
    return c->impl->get_num_ranks(job_id, c->ctx);
}

80 81 82 83 84 85 86 87 88
/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  indent-tabs-mode: nil
 * End:
 *
 * vim: ts=8 sts=4 sw=4 expandtab
 */