1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Test reading and writing ordered output";
13 */
14
main(int argc,char * argv[])15 int main(int argc, char *argv[])
16 {
17 int errs = 0;
18 int size, rank, i, *buf, rc;
19 MPI_File fh;
20 MPI_Comm comm;
21 MPI_Status status;
22 MPI_Request request;
23
24 MTest_Init(&argc, &argv);
25
26 comm = MPI_COMM_WORLD;
27 MPI_File_open(comm, (char *) "test.ord",
28 MPI_MODE_RDWR | MPI_MODE_CREATE | MPI_MODE_DELETE_ON_CLOSE, MPI_INFO_NULL, &fh);
29
30 MPI_Comm_size(comm, &size);
31 MPI_Comm_rank(comm, &rank);
32 buf = (int *) malloc(size * sizeof(int));
33 buf[0] = rank;
34 rc = MPI_File_write_ordered(fh, buf, 1, MPI_INT, &status);
35 if (rc != MPI_SUCCESS) {
36 MTestPrintErrorMsg("File_write_ordered", rc);
37 errs++;
38 }
39 /* make sure all writes finish before we seek/read */
40 MPI_Barrier(comm);
41
42 /* Set the individual pointer to 0, since we want to use a iread_all */
43 MPI_File_seek(fh, 0, MPI_SEEK_SET);
44 rc = MPI_File_iread_all(fh, buf, size, MPI_INT, &request);
45 if (rc != MPI_SUCCESS) {
46 MTestPrintErrorMsg("File_iread_all", rc);
47 errs++;
48 }
49 MPI_Wait(&request, &status);
50
51 for (i = 0; i < size; i++) {
52 if (buf[i] != i) {
53 errs++;
54 fprintf(stderr, "%d: buf[%d] = %d\n", rank, i, buf[i]);
55 }
56 }
57
58 MPI_File_seek_shared(fh, 0, MPI_SEEK_SET);
59 for (i = 0; i < size; i++)
60 buf[i] = -1;
61 MPI_File_read_ordered(fh, buf, 1, MPI_INT, &status);
62 if (buf[0] != rank) {
63 errs++;
64 fprintf(stderr, "%d: buf[0] = %d\n", rank, buf[0]);
65 }
66
67 free(buf);
68 MPI_File_close(&fh);
69
70 MTest_Finalize(errs);
71 return MTestReturnValue(errs);
72 }
73