Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into depencencies
[simgrid.git] / teshsuite / smpi / mpich3-test / io / rdwrzero.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 #include "mpitestconf.h"
12 #ifdef HAVE_STRING_H
13 #include <string.h>
14 #endif
15 #ifdef HAVE_MEMORY_H
16 #include <memory.h>
17 #endif
18
19 /*
20 static char MTEST_Descrip[] = "Test reading and writing zero bytes (set status correctly)";
21 */
22
23 int main(int argc, char *argv[])
24 {
25     int errs = 0;
26     int size, rank, i, *buf, count, rc;
27     MPI_File fh;
28     MPI_Comm comm;
29     MPI_Status status;
30
31     MTest_Init(&argc, &argv);
32
33     comm = MPI_COMM_WORLD;
34     rc = MPI_File_open(comm, (char *) "/scratch/test.ord",
35                        MPI_MODE_RDWR | MPI_MODE_CREATE |
36                        MPI_MODE_DELETE_ON_CLOSE, MPI_INFO_NULL, &fh);
37     if (rc) {
38         MTestPrintErrorMsg("File_open", rc);
39         errs++;
40         /* If the open fails, there isn't anything else that we can do */
41         goto fn_fail;
42     }
43
44
45     MPI_Comm_size(comm, &size);
46     MPI_Comm_rank(comm, &rank);
47     buf = (int *) malloc(size * sizeof(int));
48     buf[0] = rank;
49     /* Write to file */
50     rc = MPI_File_write_ordered(fh, buf, 1, MPI_INT, &status);
51     if (rc) {
52         MTestPrintErrorMsg("File_write_ordered", rc);
53         errs++;
54     }
55     else {
56         MPI_Get_count(&status, MPI_INT, &count);
57         if (count != 1) {
58             errs++;
59             fprintf(stderr, "Wrong count (%d) on write-ordered\n", count);
60         }
61     }
62
63     /* Set the individual pointer to 0, since we want to use a read_all */
64     MPI_File_seek(fh, 0, MPI_SEEK_SET);
65
66     /* Read nothing (check status) */
67     memset(&status, 0xff, sizeof(MPI_Status));
68     MPI_File_read(fh, buf, 0, MPI_INT, &status);
69     MPI_Get_count(&status, MPI_INT, &count);
70     if (count != 0) {
71         errs++;
72         fprintf(stderr, "Count not zero (%d) on read\n", count);
73     }
74
75     /* Write nothing (check status) */
76     memset(&status, 0xff, sizeof(MPI_Status));
77     MPI_File_write(fh, buf, 0, MPI_INT, &status);
78     if (count != 0) {
79         errs++;
80         fprintf(stderr, "Count not zero (%d) on write\n", count);
81     }
82
83     /* Read shared nothing (check status) */
84     MPI_File_seek_shared(fh, 0, MPI_SEEK_SET);
85     /* Read nothing (check status) */
86     memset(&status, 0xff, sizeof(MPI_Status));
87     MPI_File_read_shared(fh, buf, 0, MPI_INT, &status);
88     MPI_Get_count(&status, MPI_INT, &count);
89     if (count != 0) {
90         errs++;
91         fprintf(stderr, "Count not zero (%d) on read shared\n", count);
92     }
93
94     /* Write nothing (check status) */
95     memset(&status, 0xff, sizeof(MPI_Status));
96     MPI_File_write_shared(fh, buf, 0, MPI_INT, &status);
97     if (count != 0) {
98         errs++;
99         fprintf(stderr, "Count not zero (%d) on write\n", count);
100     }
101
102     MPI_Barrier(comm);
103
104     MPI_File_seek_shared(fh, 0, MPI_SEEK_SET);
105     for (i = 0; i < size; i++)
106         buf[i] = -1;
107     MPI_File_read_ordered(fh, buf, 1, MPI_INT, &status);
108 /*    if (buf[0] != rank) {*/
109 /*        errs++;*/
110 /*        fprintf(stderr, "%d: buf = %d\n", rank, buf[0]);*/
111 /*    }*/
112
113     free(buf);
114
115     MPI_File_close(&fh);
116
117   fn_fail:
118     MTest_Finalize(errs);
119     MPI_Finalize();
120     return 0;
121 }