This source file includes following definitions.
- main
1
2
3
4
5
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <string.h>
9 #include <stdlib.h>
10
11
12
13 #define SIZE 5000
14
15 #define VERBOSE 0
16
17 int main(int argc, char **argv)
18 {
19 int *buf, i, mynod, nprocs, len, b[3];
20 int errs=0, toterrs;
21 MPI_Aint d[3];
22 MPI_File fh;
23 MPI_Status status;
24 char *filename;
25 MPI_Datatype typevec, newtype, t[3];
26 MPIO_Request req;
27
28 MPI_Init(&argc,&argv);
29 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
30 MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
31
32 if (nprocs != 2) {
33 fprintf(stderr, "Run this program on two processes\n");
34 MPI_Abort(MPI_COMM_WORLD, 1);
35 }
36
37
38
39 if (!mynod) {
40 i = 1;
41 while ((i < argc) && strcmp("-fname", *argv)) {
42 i++;
43 argv++;
44 }
45 if (i >= argc) {
46 fprintf(stderr, "\n*# Usage: i_noncontig -fname filename\n\n");
47 MPI_Abort(MPI_COMM_WORLD, 1);
48 }
49 argv++;
50 len = strlen(*argv);
51 filename = (char *) malloc(len+1);
52 strcpy(filename, *argv);
53 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
54 MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
55 }
56 else {
57 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
58 filename = (char *) malloc(len+1);
59 MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
60 }
61
62 buf = (int *) malloc(SIZE*sizeof(int));
63
64 MPI_Type_vector(SIZE/2, 1, 2, MPI_INT, &typevec);
65
66 b[0] = b[1] = b[2] = 1;
67 d[0] = 0;
68 d[1] = mynod*sizeof(int);
69 d[2] = SIZE*sizeof(int);
70 t[0] = MPI_LB;
71 t[1] = typevec;
72 t[2] = MPI_UB;
73
74 MPI_Type_struct(3, b, d, t, &newtype);
75 MPI_Type_commit(&newtype);
76 MPI_Type_free(&typevec);
77
78 if (!mynod) {
79 #if VERBOSE
80 fprintf(stderr, "\ntesting noncontiguous in memory, noncontiguous in file using nonblocking I/O\n");
81 #endif
82 MPI_File_delete(filename, MPI_INFO_NULL);
83 }
84 MPI_Barrier(MPI_COMM_WORLD);
85
86 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
87 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
88
89 MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL);
90
91 for (i=0; i<SIZE; i++) buf[i] = i + mynod*SIZE;
92 MPI_File_iwrite(fh, buf, 1, newtype, &req);
93 #ifdef MPIO_USES_MPI_REQUEST
94 MPI_Wait(&req, &status);
95 #else
96 MPIO_Wait(&req, &status);
97 #endif
98
99 MPI_Barrier(MPI_COMM_WORLD);
100
101 for (i=0; i<SIZE; i++) buf[i] = -1;
102
103 MPI_File_iread_at(fh, 0, buf, 1, newtype, &req);
104 #ifdef MPIO_USES_MPI_REQUEST
105 MPI_Wait(&req, &status);
106 #else
107 MPIO_Wait(&req, &status);
108 #endif
109
110 for (i=0; i<SIZE; i++) {
111 if (!mynod) {
112 if ((i%2) && (buf[i] != -1)) {
113 errs++;
114 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n",
115 mynod, i, buf[i]);
116 }
117 if (!(i%2) && (buf[i] != i)) {
118 errs++;
119 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
120 mynod, i, buf[i], i);
121 }
122 }
123 else {
124 if ((i%2) && (buf[i] != i + mynod*SIZE)) {
125 errs++;
126 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
127 mynod, i, buf[i], i + mynod*SIZE);
128 }
129 if (!(i%2) && (buf[i] != -1)) {
130 errs++;
131 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n",
132 mynod, i, buf[i]);
133 }
134 }
135 }
136
137 MPI_File_close(&fh);
138
139 MPI_Barrier(MPI_COMM_WORLD);
140
141 if (!mynod) {
142 #if VERBOSE
143 fprintf(stderr, "\ntesting noncontiguous in memory, contiguous in file using nonblocking I/O\n");
144 #endif
145 MPI_File_delete(filename, MPI_INFO_NULL);
146 }
147 MPI_Barrier(MPI_COMM_WORLD);
148
149 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
150 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
151
152 for (i=0; i<SIZE; i++) buf[i] = i + mynod*SIZE;
153 MPI_File_iwrite_at(fh, mynod*(SIZE/2)*sizeof(int), buf, 1, newtype, &req);
154 #ifdef MPIO_USES_MPI_REQUEST
155 MPI_Wait(&req, &status);
156 #else
157 MPIO_Wait(&req, &status);
158 #endif
159
160 MPI_Barrier(MPI_COMM_WORLD);
161
162 for (i=0; i<SIZE; i++) buf[i] = -1;
163
164 MPI_File_iread_at(fh, mynod*(SIZE/2)*sizeof(int), buf, 1, newtype, &req);
165 #ifdef MPIO_USES_MPI_REQUEST
166 MPI_Wait(&req, &status);
167 #else
168 MPIO_Wait(&req, &status);
169 #endif
170
171 for (i=0; i<SIZE; i++) {
172 if (!mynod) {
173 if ((i%2) && (buf[i] != -1)) {
174 errs++;
175 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n",
176 mynod, i, buf[i]);
177 }
178 if (!(i%2) && (buf[i] != i)) {
179 errs++;
180 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
181 mynod, i, buf[i], i);
182 }
183 }
184 else {
185 if ((i%2) && (buf[i] != i + mynod*SIZE)) {
186 errs++;
187 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
188 mynod, i, buf[i], i + mynod*SIZE);
189 }
190 if (!(i%2) && (buf[i] != -1)) {
191 errs++;
192 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n",
193 mynod, i, buf[i]);
194 }
195 }
196 }
197
198 MPI_File_close(&fh);
199
200 MPI_Barrier(MPI_COMM_WORLD);
201
202 if (!mynod) {
203 #if VERBOSE
204 fprintf(stderr, "\ntesting contiguous in memory, noncontiguous in file using nonblocking I/O\n");
205 #endif
206 MPI_File_delete(filename, MPI_INFO_NULL);
207 }
208 MPI_Barrier(MPI_COMM_WORLD);
209
210 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
211 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
212
213 MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL);
214
215 for (i=0; i<SIZE; i++) buf[i] = i + mynod*SIZE;
216 MPI_File_iwrite(fh, buf, SIZE, MPI_INT, &req);
217 #ifdef MPIO_USES_MPI_REQUEST
218 MPI_Wait(&req, &status);
219 #else
220 MPIO_Wait(&req, &status);
221 #endif
222
223 MPI_Barrier(MPI_COMM_WORLD);
224
225 for (i=0; i<SIZE; i++) buf[i] = -1;
226
227 MPI_File_iread_at(fh, 0, buf, SIZE, MPI_INT, &req);
228 #ifdef MPIO_USES_MPI_REQUEST
229 MPI_Wait(&req, &status);
230 #else
231 MPIO_Wait(&req, &status);
232 #endif
233
234 for (i=0; i<SIZE; i++) {
235 if (!mynod) {
236 if (buf[i] != i) {
237 errs++;
238 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
239 mynod, i, buf[i], i);
240 }
241 }
242 else {
243 if (buf[i] != i + mynod*SIZE) {
244 errs++;
245 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
246 mynod, i, buf[i], i + mynod*SIZE);
247 }
248 }
249 }
250
251 MPI_File_close(&fh);
252
253 MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
254 if (mynod == 0) {
255 if( toterrs > 0) {
256 fprintf( stderr, "Found %d errors\n", toterrs );
257 }
258 else {
259 fprintf( stdout, " No Errors\n" );
260 }
261 }
262 MPI_Type_free(&newtype);
263 free(buf);
264 free(filename);
265 MPI_Finalize();
266 return 0;
267 }