1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2014 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
12 /* tests noncontiguous reads/writes using nonblocking collective I/O */
17 int main(int argc, char **argv)
19 int *buf, i, mynod, nprocs, len, b[3];
20 int errs = 0, toterrs;
26 MPI_Datatype typevec, newtype, t[3];
28 MPI_Init(&argc, &argv);
29 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
30 MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
33 fprintf(stderr, "Run this program on two processes\n");
34 MPI_Abort(MPI_COMM_WORLD, 1);
37 /* process 0 broadcasts the file name to other processes */
39 filename = (char*)"testfile";
40 len = strlen(filename);
41 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
42 MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
45 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
46 filename = (char *) malloc(len + 1);
47 MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
50 buf = (int *) malloc(SIZE * sizeof(int));
52 MPI_Type_vector(SIZE / 2, 1, 2, MPI_INT, &typevec);
54 b[0] = b[1] = b[2] = 1;
56 d[1] = mynod * sizeof(int);
57 d[2] = SIZE * sizeof(int);
62 MPI_Type_struct(3, b, d, t, &newtype);
63 MPI_Type_commit(&newtype);
64 MPI_Type_free(&typevec);
68 fprintf(stderr, "\ntesting noncontiguous in memory, noncontiguous in "
69 "file using collective I/O\n");
71 MPI_File_delete(filename, MPI_INFO_NULL);
73 MPI_Barrier(MPI_COMM_WORLD);
75 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
77 MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL);
79 for (i = 0; i < SIZE; i++)
80 buf[i] = i + mynod * SIZE;
81 MPI_File_iwrite_all(fh, buf, 1, newtype, &request);
83 MPI_Barrier(MPI_COMM_WORLD);
84 MPI_Wait(&request, &status);
86 for (i = 0; i < SIZE; i++)
89 MPI_File_iread_at_all(fh, 0, buf, 1, newtype, &request);
90 MPI_Wait(&request, &status);
92 for (i = 0; i < SIZE; i++) {
94 if ((i % 2) && (buf[i] != -1)) {
96 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]);
98 if (!(i % 2) && (buf[i] != i)) {
100 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i);
104 if ((i % 2) && (buf[i] != i + mynod * SIZE)) {
106 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
107 mynod, i, buf[i], i + mynod * SIZE);
109 if (!(i % 2) && (buf[i] != -1)) {
111 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]);
118 MPI_Barrier(MPI_COMM_WORLD);
122 fprintf(stderr, "\ntesting noncontiguous in memory, contiguous in file "
123 "using collective I/O\n");
125 MPI_File_delete(filename, MPI_INFO_NULL);
127 MPI_Barrier(MPI_COMM_WORLD);
129 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
131 for (i = 0; i < SIZE; i++)
132 buf[i] = i + mynod * SIZE;
133 MPI_File_iwrite_at_all(fh, mynod * (SIZE / 2) * sizeof(int), buf, 1, newtype, &request);
135 MPI_Barrier(MPI_COMM_WORLD);
136 MPI_Wait(&request, &status);
138 for (i = 0; i < SIZE; i++)
141 MPI_File_iread_at_all(fh, mynod * (SIZE / 2) * sizeof(int), buf, 1, newtype, &request);
142 MPI_Wait(&request, &status);
144 for (i = 0; i < SIZE; i++) {
146 if ((i % 2) && (buf[i] != -1)) {
148 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]);
150 if (!(i % 2) && (buf[i] != i)) {
152 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i);
156 if ((i % 2) && (buf[i] != i + mynod * SIZE)) {
158 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
159 mynod, i, buf[i], i + mynod * SIZE);
161 if (!(i % 2) && (buf[i] != -1)) {
163 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]);
170 MPI_Barrier(MPI_COMM_WORLD);
174 fprintf(stderr, "\ntesting contiguous in memory, noncontiguous in file "
175 "using collective I/O\n");
177 MPI_File_delete(filename, MPI_INFO_NULL);
179 MPI_Barrier(MPI_COMM_WORLD);
181 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
183 MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL);
185 for (i = 0; i < SIZE; i++)
186 buf[i] = i + mynod * SIZE;
187 MPI_File_iwrite_all(fh, buf, SIZE, MPI_INT, &request);
189 MPI_Barrier(MPI_COMM_WORLD);
190 MPI_Wait(&request, &status);
192 for (i = 0; i < SIZE; i++)
195 MPI_File_iread_at_all(fh, 0, buf, SIZE, MPI_INT, &request);
196 MPI_Wait(&request, &status);
198 for (i = 0; i < SIZE; i++) {
202 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i);
206 if (buf[i] != i + mynod * SIZE) {
208 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
209 mynod, i, buf[i], i + mynod * SIZE);
216 MPI_Allreduce(&errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
219 fprintf(stderr, "Found %d errors\n", toterrs);
222 fprintf(stdout, " No Errors\n");
226 MPI_Type_free(&newtype);