jobmap-test.c 1.21 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
/*
 * Copyright (C) 2015 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

#include <stdio.h>

#include "codes/codes-jobmap.h"

const int N = 10;

int main(int argc, char *argv[])
{
    struct codes_jobmap_ctx *c;
    struct codes_jobmap_params_dummy p;
    p.num_jobs = N;

#define ERR(str, ...) \
    do { \
        fprintf(stderr, "ERROR: " str "\n", ##__VA_ARGS__); \
        return 1; \
    } while(0)

    /* initialize */
    c = codes_jobmap_configure(CODES_JOBMAP_DUMMY, &p);
27
    if (!c) ERR("jobmap configure failure");
28 29 30 31

    /* successful lookups */
    struct codes_jobmap_id id;
    for (int i = 0; i < N; i++) {
32
        id = codes_jobmap_to_local_id(i, c);
33 34 35
        if (id.job != i || id.rank != 0)
            ERR("lookup failure for %d: expected (%d,%d), got (%d,%d)",
                    i, i, 0, id.job, id.rank);
36 37 38 39
        else {
            id.job = -1;
            id.rank = -1;
        }
40 41
    }
    /* bad lookup */
42
    id = codes_jobmap_to_local_id(10, c);
43 44 45 46 47 48 49 50 51 52
    if (id.job != -1 || id.rank != -1)
        ERR("lookup expected failure for 10: expected (%d,%d), got (%d,%d)",
                -1,-1, id.job,id.rank);

    /* cleanup */
    codes_jobmap_destroy(c);

#undef ERR
    return 0;
}