File: dataalign2.c

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 423,384 kB
  • sloc: ansic: 1,088,434; cpp: 71,364; javascript: 40,763; f90: 22,829; sh: 17,463; perl: 14,773; xml: 14,418; python: 10,265; makefile: 9,246; fortran: 8,008; java: 4,355; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (140 lines) | stat: -rw-r--r-- 2,529 bytes parent folder | download | duplicates (3)
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
59
60
61
62
63
64
65
66
67
68
69
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "mpi.h"
#include "mpitest.h"
#include <stddef.h>
#include <stdio.h>
#include <complex.h>
#include <stdbool.h>
#include <inttypes.h>

struct C_BOOL {
    char a;
    bool b;
};
struct CHAR {
    char a;
    char b;
};
struct SHORT {
    char a;
    short b;
};
struct INT {
    char a;
    int b;
};
struct LONG {
    char a;
    long b;
};
struct FLOAT {
    char a;
    float b;
};
struct DOUBLE {
    char a;
    double b;
};
struct LONG_DOUBLE {
    char a;
    long double b;
};
struct INT8_T {
    char a;
    int8_t b;
};
struct INT16_T {
    char a;
    int16_t b;
};
struct INT32_T {
    char a;
    int32_t b;
};
struct INT64_T {
    char a;
    int64_t b;
};
struct AINT {
    char a;
    MPI_Aint b;
};
struct COUNT {
    char a;
    MPI_Count b;
};
struct OFFSET {
    char a;
    MPI_Offset b;
};
struct C_COMPLEX {
    char a;
    float complex b;
};
struct C_DOUBLE_COMPLEX {
    char a;
    double complex b;
};
struct C_LONG_DOUBLE_COMPLEX {
    char a;
    long double complex b;
};

/* The resulting struct datatype's extent will round up to the alignment.
 * It should agree with C's struct size */
#define TEST_TYPE(T) \
    do { \
        displs[1] = offsetof(struct T, b); \
        MPI_Type_dup(MPI_ ## T, &types[1]); \
        MPI_Type_create_struct(2, blklens, displs, types, &newtype); \
        MPI_Type_get_extent(newtype, &lb, &extent); \
        if (extent != sizeof(struct T)) { \
            printf("Wrong extent with struct %s, expect %zd, got %lld\n", #T, sizeof(struct T), (long long)extent); \
            errs++; \
        } \
        MPI_Type_free(&types[1]); \
        MPI_Type_free(&newtype); \
    } while (0)

int main(int argc, char *argv[])
{
    int errs = 0;

    MTest_Init(&argc, &argv);

    int blklens[2] = { 1, 1 };
    MPI_Aint displs[2];
    MPI_Datatype types[2];

    MPI_Datatype newtype;
    MPI_Aint lb, extent;

    displs[0] = 0;
    types[0] = MPI_CHAR;

    TEST_TYPE(CHAR);
    TEST_TYPE(SHORT);
    TEST_TYPE(INT);
    TEST_TYPE(LONG);
    TEST_TYPE(FLOAT);
    TEST_TYPE(DOUBLE);
    TEST_TYPE(LONG_DOUBLE);
    TEST_TYPE(INT8_T);
    TEST_TYPE(INT16_T);
    TEST_TYPE(INT32_T);
    TEST_TYPE(INT64_T);
    TEST_TYPE(AINT);
    TEST_TYPE(COUNT);
    TEST_TYPE(OFFSET);
    TEST_TYPE(C_BOOL);
    TEST_TYPE(C_COMPLEX);
    TEST_TYPE(C_DOUBLE_COMPLEX);
    TEST_TYPE(C_LONG_DOUBLE_COMPLEX);

    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}