1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
12 /* tests noncontiguous reads/writes using nonblocking I/O */
15 static char MTEST_Descrip[] = "Test nonblocking I/O";
22 int main(int argc, char **argv)
24 int *buf, i, mynod, nprocs, len, b[3];
30 MPI_Datatype typevec, newtype, t[3];
33 MTest_Init(&argc, &argv);
34 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
35 MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
38 fprintf(stderr, "Run this program on two processes\n");
39 MPI_Abort(MPI_COMM_WORLD, 1);
42 /* process 0 takes the file name as a command-line argument and
43 broadcasts it to other processes */
46 while ((i < argc) && strcmp("-fname", *argv)) {
52 filename = (char *) malloc(len + 10);
53 strcpy(filename, "testfile");
55 * fprintf(stderr, "\n*# Usage: i_noncontig -fname filename\n\n");
56 * MPI_Abort(MPI_COMM_WORLD, 1);
61 len = (int) strlen(*argv);
62 filename = (char *) malloc(len + 1);
63 strcpy(filename, *argv);
65 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
66 MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
69 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
70 filename = (char *) malloc(len + 1);
71 MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
74 buf = (int *) malloc(SIZE * sizeof(int));
76 MPI_Type_vector(SIZE / 2, 1, 2, MPI_INT, &typevec);
78 b[0] = b[1] = b[2] = 1;
80 d[1] = mynod * sizeof(int);
81 d[2] = SIZE * sizeof(int);
86 MPI_Type_struct(3, b, d, t, &newtype);
87 MPI_Type_commit(&newtype);
88 MPI_Type_free(&typevec);
93 "\ntesting noncontiguous in memory, noncontiguous in file using nonblocking I/O\n");
95 MPI_File_delete(filename, MPI_INFO_NULL);
97 MPI_Barrier(MPI_COMM_WORLD);
99 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
101 MPI_File_set_view(fh, 0, MPI_INT, newtype, (char *) "native", MPI_INFO_NULL);
103 for (i = 0; i < SIZE; i++)
104 buf[i] = i + mynod * SIZE;
105 MPI_File_iwrite(fh, buf, 1, newtype, &req);
106 MPI_Wait(&req, &status);
108 MPI_Barrier(MPI_COMM_WORLD);
110 for (i = 0; i < SIZE; i++)
113 MPI_File_iread_at(fh, 0, buf, 1, newtype, &req);
114 MPI_Wait(&req, &status);
116 for (i = 0; i < SIZE; i++) {
118 if ((i % 2) && (buf[i] != -1)) {
120 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]);
122 if (!(i % 2) && (buf[i] != i)) {
124 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i);
128 if ((i % 2) && (buf[i] != i + mynod * SIZE)) {
130 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
131 mynod, i, buf[i], i + mynod * SIZE);
133 if (!(i % 2) && (buf[i] != -1)) {
135 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]);
142 MPI_Barrier(MPI_COMM_WORLD);
147 "\ntesting noncontiguous in memory, contiguous in file using nonblocking I/O\n");
149 MPI_File_delete(filename, MPI_INFO_NULL);
151 MPI_Barrier(MPI_COMM_WORLD);
153 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
155 for (i = 0; i < SIZE; i++)
156 buf[i] = i + mynod * SIZE;
157 MPI_File_iwrite_at(fh, mynod * (SIZE / 2) * sizeof(int), buf, 1, newtype, &req);
158 MPI_Wait(&req, &status);
160 MPI_Barrier(MPI_COMM_WORLD);
162 for (i = 0; i < SIZE; i++)
165 MPI_File_iread_at(fh, mynod * (SIZE / 2) * sizeof(int), buf, 1, newtype, &req);
166 MPI_Wait(&req, &status);
168 for (i = 0; i < SIZE; i++) {
170 if ((i % 2) && (buf[i] != -1)) {
172 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]);
174 if (!(i % 2) && (buf[i] != i)) {
176 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i);
180 if ((i % 2) && (buf[i] != i + mynod * SIZE)) {
182 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
183 mynod, i, buf[i], i + mynod * SIZE);
185 if (!(i % 2) && (buf[i] != -1)) {
187 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]);
194 MPI_Barrier(MPI_COMM_WORLD);
199 "\ntesting contiguous in memory, noncontiguous in file using nonblocking I/O\n");
201 MPI_File_delete(filename, MPI_INFO_NULL);
203 MPI_Barrier(MPI_COMM_WORLD);
205 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
207 MPI_File_set_view(fh, 0, MPI_INT, newtype, (char *) "native", MPI_INFO_NULL);
209 for (i = 0; i < SIZE; i++)
210 buf[i] = i + mynod * SIZE;
211 MPI_File_iwrite(fh, buf, SIZE, MPI_INT, &req);
212 MPI_Wait(&req, &status);
214 MPI_Barrier(MPI_COMM_WORLD);
216 for (i = 0; i < SIZE; i++)
219 MPI_File_iread_at(fh, 0, buf, SIZE, MPI_INT, &req);
220 MPI_Wait(&req, &status);
222 for (i = 0; i < SIZE; i++) {
226 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i);
230 if (buf[i] != i + mynod * SIZE) {
232 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
233 mynod, i, buf[i], i + mynod * SIZE);
240 MPI_Type_free(&newtype);
243 MTest_Finalize(errs);