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 static char MTEST_Descrip[] = "Test reading and writing ordered output";
15 int main(int argc, char *argv[])
18 int size, rank, i, *buf, rc;
24 MTest_Init(&argc, &argv);
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);
30 MPI_Comm_size(comm, &size);
31 MPI_Comm_rank(comm, &rank);
32 buf = (int *) malloc(size * sizeof(int));
34 rc = MPI_File_write_ordered(fh, buf, 1, MPI_INT, &status);
35 if (rc != MPI_SUCCESS) {
36 MTestPrintErrorMsg("File_write_ordered", rc);
39 /* make sure all writes finish before we seek/read */
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);
49 MPI_Wait(&request, &status);
51 for (i = 0; i < size; i++) {
54 fprintf(stderr, "%d: buf[%d] = %d\n", rank, i, buf[i]);
58 MPI_File_seek_shared(fh, 0, MPI_SEEK_SET);
59 for (i = 0; i < size; i++)
61 MPI_File_read_ordered(fh, buf, 1, MPI_INT, &status);
64 fprintf(stderr, "%d: buf[0] = %d\n", rank, buf[0]);