This source file includes following definitions.
- handle_error
- typestats
- verify_type
- testtype
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <mpi.h>
15 #include <stdint.h>
16 #include <math.h>
17 #include <stdio.h>
18
19 #define CHECK(fn) {int errcode; errcode = (fn); if (errcode != MPI_SUCCESS) handle_error(errcode, NULL); }
20
21
22 static void handle_error(int errcode, char *str)
23 {
24 char msg[MPI_MAX_ERROR_STRING];
25 int resultlen;
26 MPI_Error_string(errcode, msg, &resultlen);
27 fprintf(stderr, "%s: %s\n", str, msg);
28 MPI_Abort(MPI_COMM_WORLD, 1);
29 }
30
31 static void typestats(MPI_Datatype type)
32 {
33 MPI_Aint lb, extent;
34 MPI_Count size;
35
36 MPI_Type_get_extent(type, &lb, &extent);
37 MPI_Type_size_x(type, &size);
38
39 printf("dtype %d: lb = %ld extent = %ld size = %ld...",
40 type, (long)lb, (long)extent, size);
41
42 }
43
44 static int verify_type(char *filename, MPI_Datatype type,
45 int64_t expected_extent, int do_coll)
46 {
47 int rank, canary;
48 MPI_Count tsize;
49 int compare=-1;
50 int errs=0, toterrs=0;
51 MPI_Status status;
52 MPI_File fh;
53
54 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
55
56 CHECK( MPI_File_open(MPI_COMM_WORLD, filename,
57 MPI_MODE_CREATE|MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
58 CHECK( MPI_File_set_view(fh, rank*sizeof(int),
59 MPI_BYTE, type, "native", MPI_INFO_NULL));
60
61 MPI_Type_size_x(type, &tsize);
62
63 canary=rank+1000000;
64
65
66 if (do_coll) {
67 CHECK( MPI_File_write_at_all(fh, tsize, &canary, 1, MPI_INT, &status));
68 } else {
69 CHECK( MPI_File_write_at(fh, tsize, &canary, 1, MPI_INT, &status));
70 }
71
72 CHECK( MPI_File_set_view(fh, 0, MPI_INT, MPI_INT, "native",
73 MPI_INFO_NULL));
74
75 if (do_coll) {
76 CHECK( MPI_File_read_at_all(fh, expected_extent/sizeof(int)+rank,
77 &compare, 1, MPI_INT, &status));
78 } else {
79 CHECK( MPI_File_read_at(fh, expected_extent/sizeof(int)+rank,
80 &compare, 1, MPI_INT, &status));
81 }
82
83 if (compare != canary)
84 errs=1;
85 MPI_Allreduce(&errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
86
87 MPI_File_close(&fh);
88
89 if (toterrs) {
90 printf("%d: got %d expected %d\n", rank, compare, canary);
91
92 } else {
93 if (rank == 0) MPI_File_delete(filename, MPI_INFO_NULL);
94 }
95
96 return (toterrs);
97
98 }
99
100 static int testtype(char *filename, MPI_Datatype type, int64_t expected_extent)
101 {
102 int rank, ret, errs=0;
103 int collective=1, nocollective=0;
104
105 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
106 if (!rank) typestats(type);
107
108 ret = verify_type(filename, type, expected_extent, nocollective);
109 if (ret) {
110 errs++;
111 fprintf(stderr, "type %d failed indep\n", type);
112 } else
113 if (!rank) printf("indep: OK ");
114
115 ret = verify_type(filename, type, expected_extent, collective);
116 if (ret) {
117 errs++;
118 fprintf(stderr, "type %d failed collective\n", type);
119 } else
120 if (!rank) printf("coll: OK\n");
121
122 return errs;
123 }
124
125 int main(int argc, char **argv)
126 {
127 int count=2;
128 int blocks[2];
129 int disps[2];
130
131 int ndims=2;
132 int sizes[2];
133 int subs[2];
134 int starts[2];
135
136 MPI_Datatype baseindex, indexed1G, indexed3G, indexed6G;
137 MPI_Datatype subarray1G, subarray3G, subarray6G;
138 int ret, rank;
139
140 MPI_Init(&argc, &argv);
141
142 if (argc != 2) {
143 fprintf(stderr, "usage: %s <filename>\n", argv[0]);
144 MPI_Abort(MPI_COMM_WORLD, 1);
145 }
146
147 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
148
149
150 count = 2;
151 blocks[0] = 1;
152 disps[0] = 0;
153 blocks[1] = 1;
154 disps[1] = 1024*256-1;
155
156 MPI_Type_indexed(count, blocks, disps, MPI_INT, &baseindex);
157
158 MPI_Type_contiguous(1024, baseindex, &indexed1G);
159 MPI_Type_commit(&indexed1G);
160
161
162 MPI_Type_contiguous(3072, baseindex, &indexed3G);
163 MPI_Type_commit(&indexed3G);
164
165
166 MPI_Type_contiguous(6144, baseindex, &indexed6G);
167 MPI_Type_commit(&indexed6G);
168
169
170
171
172 sizes[0] = 1024*16;
173 sizes[1] = 1024*16;
174 subs[0] = subs[1] = 256;
175 starts[0] = starts[1] = 0;
176
177 MPI_Type_create_subarray(ndims, sizes, subs, starts,
178 MPI_ORDER_C, MPI_INT, &subarray1G);
179 MPI_Type_commit(&subarray1G);
180
181 sizes[1] = 1024*16*3;
182 MPI_Type_create_subarray(ndims, sizes, subs, starts,
183 MPI_ORDER_C, MPI_INT, &subarray3G);
184 MPI_Type_commit(&subarray3G);
185
186 sizes[1] = 1024*16*6;
187 MPI_Type_create_subarray(ndims, sizes, subs, starts,
188 MPI_ORDER_C, MPI_INT, &subarray6G);
189 MPI_Type_commit(&subarray6G);
190
191
192 ret = testtype(argv[1], indexed1G, (int64_t)1024*1024*1024);
193
194 ret = testtype(argv[1], indexed3G, (int64_t)1024*1024*1024*3);
195
196 ret = testtype(argv[1], indexed6G, (int64_t)1024*1024*1024*6);
197
198 ret = testtype(argv[1], subarray1G, (int64_t)1024*1024*1024);
199
200 ret = testtype(argv[1], subarray3G, (int64_t)1024*1024*1024*3);
201
202 ret = testtype(argv[1], subarray6G, (int64_t)1024*1024*1024*6);
203
204 if(!ret && !rank) fprintf(stderr, " No Errors\n");
205
206 MPI_Finalize();
207 return (-ret);
208
209 }
210
211
212