map-ctx-test.c 5.47 KB
Newer Older
Jonathan Jenkins's avatar
Jonathan Jenkins committed
1 2 3 4 5 6 7 8 9 10
/*
 * Copyright (C) 2015 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

#include <stdbool.h>
#include <mpi.h>
#include <codes/codes-mapping-context.h>
#include <codes/configuration.h>
Jonathan Jenkins's avatar
Jonathan Jenkins committed
11
#include <codes/codes.h>
Jonathan Jenkins's avatar
Jonathan Jenkins committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

#define ERR(_fmt, ...) \
    do { \
        fprintf(stderr, "Error at %s:%d: " _fmt "\n", __FILE__, __LINE__, \
                ##__VA_ARGS__); \
        return 1; \
    } while (0)

/* NOTE: hard-coded against configuration file */
int main(int argc, char *argv[])
{
    MPI_Init(&argc, &argv);
    int rc = configuration_load(argv[1], MPI_COMM_WORLD, &config);
    if (rc != 0)
        ERR("unable to load configuration file %s", argv[1]);

28 29 30
    struct codes_mctx direct, group_ratio, group_rratio, group_modulo,
                      group_rmodulo, group_direct, group_modulo_anno,
                      group_rmodulo_anno, group_direct_anno;
Jonathan Jenkins's avatar
Jonathan Jenkins committed
31

32
    direct              = codes_mctx_set_global_direct(12ul);
33 34
    group_ratio         = codes_mctx_set_group_ratio(NULL, true);
    group_rratio        = codes_mctx_set_group_ratio_reverse(NULL, true);
35 36 37 38 39 40
    group_modulo        = codes_mctx_set_group_modulo(NULL, true);
    group_rmodulo       = codes_mctx_set_group_modulo_reverse(NULL, true);
    group_direct        = codes_mctx_set_group_direct(1, NULL, true);
    group_modulo_anno   = codes_mctx_set_group_modulo("baz", false);
    group_rmodulo_anno  = codes_mctx_set_group_modulo_reverse("baz", false);
    group_direct_anno   = codes_mctx_set_group_direct(1, "baz", false);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
41

42
    tw_lpid in, out;
43
    tw_lpid rtn_id;
44
    char const * out_anno;
45
    char const * rtn_anno;
Jonathan Jenkins's avatar
Jonathan Jenkins committed
46

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#define CHECK(_type_str) \
    do { \
        if (rtn_id != out) { \
            ERR("%s mapping failed: in:%llu, expected:%llu, out:%llu", \
                    _type_str, LLU(in), LLU(rtn_id), LLU(out)); \
        } \
    } while(0)

#define CHECK_ANNO(_type_str) \
    do { \
        if (!((out_anno && rtn_anno && strcmp(out_anno, rtn_anno) == 0) || \
                (!out_anno && !rtn_anno))) { \
            ERR("%s anno mapping failed: in:%llu, expected:%s, out:%s", \
                    _type_str, LLU(in), rtn_anno, out_anno); \
        } \
    } while (0)


    in  = 0ul;
    out = 12ul;
    out_anno = NULL;
68 69
    rtn_id = codes_mctx_to_lpid(&direct, NULL, 0);
    rtn_anno = codes_mctx_get_annotation(&direct, NULL, 0);
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    CHECK("global_direct");
    CHECK_ANNO("global_direct");

    /* test BAZ group (evenly divide foo, bar) */
    in = 47ul;
    out = 50ul;
    out_anno = NULL;
    rtn_id = codes_mctx_to_lpid(&group_ratio, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_ratio, "bar", in);
    CHECK("global_ratio");
    CHECK_ANNO("global_ratio");

    out = 49ul;
    rtn_id = codes_mctx_to_lpid(&group_rratio, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_rratio, "bar", in);
    CHECK("global_rratio");
    CHECK_ANNO("global_rratio");

    /* test BAT group (non-even foo/bar division) */
    in = 79ul;
    out = 82ul;
    out_anno = NULL;
    rtn_id = codes_mctx_to_lpid(&group_ratio, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_ratio, "bar", in);
    CHECK("global_ratio");
    CHECK_ANNO("global_ratio");

    out = 80ul;
    rtn_id = codes_mctx_to_lpid(&group_rratio, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_rratio, "bar", in);
    CHECK("global_ratio");
    CHECK_ANNO("global_ratio");
Jonathan Jenkins's avatar
Jonathan Jenkins committed
102

103
    in = 8ul;
104 105
    out = 9ul;
    out_anno = NULL;
106 107
    rtn_id = codes_mctx_to_lpid(&group_modulo, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_modulo, "bar", in);
108 109
    CHECK("group_modulo");
    CHECK_ANNO("group_modulo");
Jonathan Jenkins's avatar
Jonathan Jenkins committed
110

111 112
    rtn_id = codes_mctx_to_lpid(&group_rmodulo, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_rmodulo, "bar", in);
113 114
    CHECK("group_rmodulo");
    CHECK_ANNO("group_rmodulo");
115

116
    in = 12ul;
117 118
    out = 13ul;
    out_anno = NULL;
119 120
    rtn_id = codes_mctx_to_lpid(&group_modulo, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_modulo, "bar", in);
121 122
    CHECK("group_modulo");
    CHECK_ANNO("group_modulo");
Jonathan Jenkins's avatar
Jonathan Jenkins committed
123

124
    out = 14ul;
125 126
    rtn_id = codes_mctx_to_lpid(&group_rmodulo, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_rmodulo, "bar", in);
127 128
    CHECK("group_rmodulo");
    CHECK_ANNO("group_rmodulo");
129

130
    out = 13ul;
131 132
    rtn_id = codes_mctx_to_lpid(CODES_MCTX_DEFAULT, "bar", in);
    rtn_anno = codes_mctx_get_annotation(CODES_MCTX_DEFAULT, "bar", in);
133 134
    CHECK("CODES_MCTX_DEFAULT");
    CHECK_ANNO("CODES_MCTX_DEFAULT");
Jonathan Jenkins's avatar
Jonathan Jenkins committed
135

136 137
    out = 15ul;
    out_anno = "baz";
138 139
    rtn_id = codes_mctx_to_lpid(&group_modulo_anno, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_modulo_anno, "bar", in);
140 141
    CHECK("group_modulo_anno");
    CHECK_ANNO("group_modulo_anno");
Jonathan Jenkins's avatar
Jonathan Jenkins committed
142

143
    out = 16ul;
144 145
    rtn_id = codes_mctx_to_lpid(&group_rmodulo_anno, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_rmodulo_anno, "bar", in);
146 147
    CHECK("group_rmodulo_anno");
    CHECK_ANNO("group_rmodulo_anno");
148

149
    in = 10ul;
150 151
    out = 14ul;
    out_anno = NULL;
152 153
    rtn_id = codes_mctx_to_lpid(&group_direct, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_direct, "bar", in);
154 155
    CHECK("group_direct");
    CHECK_ANNO("group_direct");
Jonathan Jenkins's avatar
Jonathan Jenkins committed
156

157 158
    out = 16ul;
    out_anno = "baz";
159 160
    rtn_id = codes_mctx_to_lpid(&group_direct_anno, "bar", in);
    rtn_anno = codes_mctx_get_annotation(&group_direct_anno, "bar", in);
161 162
    CHECK("group_direct_anno");
    CHECK("group_direct_anno");
Jonathan Jenkins's avatar
Jonathan Jenkins committed
163 164 165 166 167 168 169 170 171 172 173 174 175

    return 0;
}

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