jobmap-identity.c 1.65 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 48 49 50 51 52 53 54 55 56 57 58
/*
 * Copyright (C) 2015 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

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

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

static int jobmap_identity_configure(void const * params, void ** ctx)
{
    int *num_ranks = malloc(sizeof(*num_ranks));
    assert(num_ranks);
    *ctx = num_ranks;

    struct codes_jobmap_params_identity const * p = params;

    *num_ranks = p->num_ranks;

    return 0;
}

static void jobmap_identity_destroy(void * ctx)
{
    free(ctx);
}

static struct codes_jobmap_id jobmap_identity_to_local(int id, void const * ctx)
{
    int const * num_ranks = ctx;
    struct codes_jobmap_id rtn;

    if (id < 0 || id >= *num_ranks) {
        rtn.job = -1;
        rtn.rank = -1;
    }
    else {
        rtn.job  = 0;
        rtn.rank = id;
    }

    return rtn;
}

static int jobmap_identity_to_global(struct codes_jobmap_id id, void const * ctx)
{
    int const * num_ranks = ctx;

    if (id.job >= 1 || id.rank >= *num_ranks || id.job < 0 || id.rank < 0)
        return -1;
    else
        return id.rank;
}

int jobmap_identity_get_num_jobs(void const * ctx)
{
Jonathan Jenkins's avatar
Jonathan Jenkins committed
59
    (void)ctx;
60 61 62
    return 1;
}

63 64 65 66 67
int jobmap_identity_get_num_ranks(int job_id, void const * ctx)
{
    return (job_id == 0) ? *(int const *) ctx : -1;
}

68 69 70 71 72
struct codes_jobmap_impl jobmap_identity_impl = {
    jobmap_identity_configure,
    jobmap_identity_destroy,
    jobmap_identity_to_local,
    jobmap_identity_to_global,
73 74
    jobmap_identity_get_num_jobs,
    jobmap_identity_get_num_ranks
75 76 77 78 79 80 81 82 83 84 85
};

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