Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e8dc8e15a77f62179e2b8a8df443eb5238184d7a
[simgrid.git] / teshsuite / smpi / mpich3-test / io / rdwrord.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test reading and writing ordered output";
14 */
15
16 int main(int argc, char *argv[])
17 {
18     int errs = 0;
19     int size, rank, i, *buf, rc;
20     MPI_File fh;
21     MPI_Comm comm;
22     MPI_Status status;
23
24     MTest_Init(&argc, &argv);
25
26     comm = MPI_COMM_WORLD;
27     MPI_File_open(comm, (char *) "/scratch/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) {
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 read_all */
43     MPI_File_seek(fh, 0, MPI_SEEK_SET);
44     MPI_File_read_all(fh, buf, size, MPI_INT, &status);
45
46 /*    for (i = 0; i < size; i++) {*/
47 /*        if (buf[i] != i) {*/
48 /*            errs++;*/
49 /*            fprintf(stderr, "%d: buf[%d] = %d\n", rank, i, buf[i]);*/
50 /*        }*/
51 /*    }*/
52
53     MPI_File_seek_shared(fh, 0, MPI_SEEK_SET);
54     for (i = 0; i < size; i++)
55         buf[i] = -1;
56     MPI_File_read_ordered(fh, buf, 1, MPI_INT, &status);
57     /*if (buf[0] != rank) {
58         errs++;
59         fprintf(stderr, "%d: buf[0] = %d\n", rank, buf[0]);
60     }*/
61
62     free(buf);
63     MPI_File_close(&fh);
64
65     MTest_Finalize(errs);
66     MPI_Finalize();
67     return 0;
68 }