map-ctx-test.c 5.06 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
    struct codes_mctx direct, group_modulo, group_rmodulo, group_direct,
                      group_modulo_anno, group_rmodulo_anno, group_direct_anno;
Jonathan Jenkins's avatar
Jonathan Jenkins committed
30

31 32 33 34 35 36 37
    direct              = codes_mctx_set_global_direct(12ul);
    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
38

39 40 41
    tw_lpid in;
    tw_lpid rtn_id;
    char const * rtn_anno;
Jonathan Jenkins's avatar
Jonathan Jenkins committed
42

43 44
    rtn_id = codes_mctx_to_lpid(&direct, NULL, 0);
    if (12ul != rtn_id)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
45 46
        ERR("global_direct mapping: expected %llu, got %llu",
                12ull, LLU(rtn_id));
47 48 49
    rtn_anno = codes_mctx_get_annotation(&direct, NULL, 0);
    if (rtn_anno)
        ERR("global_direct mapping: expected NULL anno, got %s", rtn_anno);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
50

51 52 53
    in = 8ul;
    rtn_id = codes_mctx_to_lpid(&group_modulo, "bar", in);
    if (rtn_id != 9ul)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
54 55
        ERR("group_modulo mapping: expected %llu, got %llu",
                9ull, LLU(rtn_id));
56 57 58
    rtn_anno = codes_mctx_get_annotation(&group_modulo, "bar", in);
    if (rtn_anno)
        ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
59

60 61
    rtn_id = codes_mctx_to_lpid(&group_rmodulo, "bar", in);
    if (rtn_id != 9ul)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
62 63
        ERR("group_rmodulo mapping: expected %llu, got %llu",
                9ull, LLU(rtn_id));
64 65 66 67
    rtn_anno = codes_mctx_get_annotation(&group_rmodulo, "bar", in);
    if (rtn_anno)
        ERR("group_rmodulo mapping: expected NULL anno, got %s", rtn_anno);

68 69 70
    in = 12ul;
    rtn_id = codes_mctx_to_lpid(&group_modulo, "bar", in);
    if (rtn_id != 13ul)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
71 72
        ERR("group_modulo mapping: expected %llu, got %llu",
                13ull, LLU(rtn_id));
73 74 75
    rtn_anno = codes_mctx_get_annotation(&group_modulo, "bar", in);
    if (rtn_anno)
        ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
76

77 78
    rtn_id = codes_mctx_to_lpid(&group_rmodulo, "bar", in);
    if (rtn_id != 14ul)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
79 80
        ERR("group_rmodulo mapping: expected %llu, got %llu",
                14ull, LLU(rtn_id));
81 82 83 84
    rtn_anno = codes_mctx_get_annotation(&group_rmodulo, "bar", in);
    if (rtn_anno)
        ERR("group_rmodulo mapping: expected NULL anno, got %s", rtn_anno);

85 86
    rtn_id = codes_mctx_to_lpid(CODES_MCTX_DEFAULT, "bar", in);
    if (rtn_id != 13ul)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
87 88
        ERR("group_modulo mapping (default): expected %llu, got %llu",
                13ull, LLU(rtn_id));
89 90 91
    rtn_anno = codes_mctx_get_annotation(CODES_MCTX_DEFAULT, "bar", in);
    if (rtn_anno)
        ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
92

93 94
    rtn_id = codes_mctx_to_lpid(&group_modulo_anno, "bar", in);
    if (rtn_id != 15ul)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
95 96
        ERR("group_modulo annotated mapping: expected %llu, got %llu",
                15ull, LLU(rtn_id));
97 98 99
    rtn_anno = codes_mctx_get_annotation(&group_modulo_anno, "bar", in);
    if (strcmp(rtn_anno,"baz") != 0)
        ERR("group_modulo mapping: expected anno \"baz\", got %s", rtn_anno);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
100

101 102
    rtn_id = codes_mctx_to_lpid(&group_rmodulo_anno, "bar", in);
    if (rtn_id != 16ul)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
103 104
        ERR("group_rmodulo annotated mapping: expected %llu, got %llu",
                16ull, LLU(rtn_id));
105 106 107 108
    rtn_anno = codes_mctx_get_annotation(&group_rmodulo_anno, "bar", in);
    if (strcmp(rtn_anno,"baz") != 0)
        ERR("group_rmodulo mapping: expected anno \"baz\", got %s", rtn_anno);

109 110 111
    in = 10ul;
    rtn_id = codes_mctx_to_lpid(&group_direct, "bar", in);
    if (rtn_id != 14ul)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
112 113
        ERR("group_direct mapping (default): expected %llu, got %llu",
                14ull, LLU(rtn_id));
114 115 116
    rtn_anno = codes_mctx_get_annotation(&group_direct, "bar", in);
    if (rtn_anno)
        ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
117

118 119
    rtn_id = codes_mctx_to_lpid(&group_direct_anno, "bar", in);
    if (rtn_id != 16ul)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
120 121
        ERR("group_direct mapping (default): expected %llu, got %llu",
                16ull, LLU(rtn_id));
122 123 124
    rtn_anno = codes_mctx_get_annotation(&group_direct_anno, "bar", in);
    if (strcmp(rtn_anno,"baz") != 0)
        ERR("group_modulo mapping: expected anno \"baz\", got %s", rtn_anno);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
125 126 127 128 129 130 131 132 133 134 135 136 137

    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
 */