File: struct_verydeep.c

package info (click to toggle)
mpich 3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 131,836 kB
  • sloc: ansic: 975,868; cpp: 57,437; f90: 53,762; perl: 19,562; xml: 12,464; sh: 12,303; fortran: 7,875; makefile: 7,078; ruby: 126; java: 100; python: 98; lisp: 19; php: 8; sed: 4
file content (223 lines) | stat: -rw-r--r-- 4,842 bytes parent folder | download
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *  (C) 2009 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */
/* Regression test for MPICH trac ticket #972, originally written by
 * Rob Latham <robl@mcs.anl.gov> as a simplification of a type
 * encountered by the HDF5 library.
 *
 * Should be run with 1 process. */

#include <stdio.h>
#include "mpi.h"
#include "mpitest.h"

/* uncomment to use debugging routine in MPICH
extern int MPIR_Datatype_debug(MPI_Datatype type, int depth);
*/

int makeHDF5type0(MPI_Datatype * type);
int makeHDF5type0(MPI_Datatype * type)
{
    MPI_Datatype ctg, vect, structype, vec2, structype2, vec3, structype3, vec4, structype4, vec5;

    int b[3];
    MPI_Aint d[3];
    MPI_Datatype t[3];

    MPI_Type_contiguous(4, MPI_BYTE, &ctg);

    MPI_Type_vector(1, 5, 1, ctg, &vect);

    b[0] = b[1] = b[2] = 1;
    d[0] = 0;
    d[1] = 0;
    d[2] = 40;
    t[0] = MPI_LB;
    t[1] = vect;
    t[2] = MPI_UB;
    MPI_Type_create_struct(3, b, d, t, &structype);

    MPI_Type_vector(1, 5, 1, structype, &vec2);

    b[0] = b[1] = b[2] = 1;
    d[0] = 0;
    d[1] = 2000;
    d[2] = 400;
    t[0] = MPI_LB;
    t[1] = vec2;
    t[2] = MPI_UB;
    MPI_Type_create_struct(3, b, d, t, &structype2);

    MPI_Type_vector(1, 5, 1, structype2, &vec3);

    b[0] = b[1] = b[2] = 1;
    d[0] = 0;
    d[1] = 0;
    d[2] = 4000;
    t[0] = MPI_LB;
    t[1] = vec3;
    t[2] = MPI_UB;
    MPI_Type_create_struct(3, b, d, t, &structype3);

    MPI_Type_vector(1, 5, 1, structype3, &vec4);

    b[0] = b[1] = b[2] = 1;
    d[0] = 0;
    d[1] = 0;
    d[2] = 40000;
    t[0] = MPI_LB;
    t[1] = vec4;
    t[2] = MPI_UB;
    MPI_Type_create_struct(3, b, d, t, &structype4);

    MPI_Type_vector(1, 1, 1, structype4, &vec5);

    b[0] = b[1] = b[2] = 1;
    d[0] = 0;
    d[1] = 160000;
    d[2] = 200000;
    t[0] = MPI_LB;
    t[1] = vec5;
    t[2] = MPI_UB;
    MPI_Type_create_struct(3, b, d, t, type);

    MPI_Type_free(&ctg);
    MPI_Type_free(&vect);
    MPI_Type_free(&structype);
    MPI_Type_free(&vec2);
    MPI_Type_free(&structype2);
    MPI_Type_free(&vec3);
    MPI_Type_free(&structype3);
    MPI_Type_free(&vec4);
    MPI_Type_free(&structype4);
    MPI_Type_free(&vec5);
    MPI_Type_commit(type);

    return 0;
}

int makeHDF5type1(MPI_Datatype * type);
int makeHDF5type1(MPI_Datatype * type)
{
    MPI_Datatype ctg, vect, structype, vec2, structype2, vec3, structype3, vec4, structype4, vec5;

    int b[3];
    MPI_Aint d[3];
    MPI_Datatype t[3];

    MPI_Type_contiguous(4, MPI_BYTE, &ctg);

    MPI_Type_vector(1, 5, 1, ctg, &vect);

    b[0] = b[1] = b[2] = 1;
    d[0] = 0;
    d[1] = 20;
    d[2] = 40;
    t[0] = MPI_LB;
    t[1] = vect;
    t[2] = MPI_UB;
    MPI_Type_create_struct(3, b, d, t, &structype);

    MPI_Type_vector(1, 5, 1, structype, &vec2);

    b[0] = b[1] = b[2] = 1;
    d[0] = 0;
    d[1] = 0;
    d[2] = 400;
    t[0] = MPI_LB;
    t[1] = vec2;
    t[2] = MPI_UB;
    MPI_Type_create_struct(3, b, d, t, &structype2);

    MPI_Type_vector(1, 5, 1, structype2, &vec3);

    b[0] = b[1] = b[2] = 1;
    d[0] = 0;
    d[1] = 0;
    d[2] = 4000;
    t[0] = MPI_LB;
    t[1] = vec3;
    t[2] = MPI_UB;
    MPI_Type_create_struct(3, b, d, t, &structype3);

    MPI_Type_vector(1, 5, 1, structype3, &vec4);

    b[0] = b[1] = b[2] = 1;
    d[0] = 0;
    d[1] = 0;
    d[2] = 40000;
    t[0] = MPI_LB;
    t[1] = vec4;
    t[2] = MPI_UB;
    MPI_Type_create_struct(3, b, d, t, &structype4);

    MPI_Type_vector(1, 1, 1, structype4, &vec5);

    b[0] = b[1] = b[2] = 1;
    d[0] = 0;
    d[1] = 160000;
    d[2] = 200000;
    t[0] = MPI_LB;
    t[1] = vec5;
    t[2] = MPI_UB;
    MPI_Type_create_struct(3, b, d, t, type);

    MPI_Type_free(&ctg);
    MPI_Type_free(&vect);
    MPI_Type_free(&structype);
    MPI_Type_free(&vec2);
    MPI_Type_free(&structype2);
    MPI_Type_free(&vec3);
    MPI_Type_free(&structype3);
    MPI_Type_free(&vec4);
    MPI_Type_free(&structype4);
    MPI_Type_free(&vec5);
    MPI_Type_commit(type);

    return 0;
}

int makeHDF5type(MPI_Datatype * type);
int makeHDF5type(MPI_Datatype * type)
{
    int i;

#define NTYPES 2

    int blocklens[NTYPES];
    MPI_Aint disps[NTYPES];

    MPI_Datatype types[NTYPES];
    makeHDF5type0(&(types[0]));
    makeHDF5type1(&(types[1]));

    for (i = 0; i < NTYPES; i++) {
        blocklens[i] = 1;
        disps[i] = 0;
    }

    MPI_Type_create_struct(NTYPES, blocklens, disps, types, type);
    MPI_Type_commit(type);

    for (i = 0; i < NTYPES; i++) {
        MPI_Type_free(&(types[i]));
    }
    return 0;
}

int main(int argc, char **argv)
{
    MPI_Datatype hdf5type;

    MTest_Init(&argc, &argv);
    makeHDF5type(&hdf5type);

    /*MPIR_Datatype_debug(hdf5type, 32); */

    MPI_Type_free(&hdf5type);
    MTest_Finalize(0);

    return 0;
}