Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into depencencies
[simgrid.git] / teshsuite / smpi / mpich3-test / io / setinfo.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
16 /*
17 static char MTEST_Descrip[] = "Test file_set_view";
18 */
19
20 /*
21  * access style is explicitly described as modifiable.  values include
22  * read_once, read_mostly, write_once, write_mostlye, random
23  *
24  *
25  */
26 int main(int argc, char *argv[])
27 {
28     int errs = 0, err;
29     int buf[10];
30     int rank;
31     MPI_Comm comm;
32     MPI_Status status;
33     MPI_File fh;
34     MPI_Info infoin, infoout;
35     char value[1024];
36     int flag, count;
37
38     MTest_Init(&argc, &argv);
39     comm = MPI_COMM_WORLD;
40
41     MPI_Comm_rank(comm, &rank);
42     MPI_Info_create(&infoin);
43     MPI_Info_set(infoin, (char *) "access_style", (char *) "write_once,random");
44     MPI_File_open(comm, (char *) "/scratch/testfile", MPI_MODE_RDWR | MPI_MODE_CREATE, infoin, &fh);
45     buf[0] = rank;
46     err = MPI_File_write_ordered(fh, buf, 1, MPI_INT, &status);
47     if (err) {
48         errs++;
49         MTestPrintError(err);
50     }
51
52     MPI_Info_set(infoin, (char *) "access_style", (char *) "read_once");
53     err = MPI_File_seek_shared(fh, 0, MPI_SEEK_SET);
54     if (err) {
55         errs++;
56         MTestPrintError(err);
57     }
58
59     err = MPI_File_set_info(fh, infoin);
60     if (err) {
61         errs++;
62         MTestPrintError(err);
63     }
64     MPI_Info_free(&infoin);
65     buf[0] = -1;
66
67     err = MPI_File_read_ordered(fh, buf, 1, MPI_INT, &status);
68     if (err) {
69         errs++;
70         MTestPrintError(err);
71     }
72     MPI_Get_count(&status, MPI_INT, &count);
73     if (count != 1) {
74         errs++;
75         printf("Expected to read one int, read %d\n", count);
76     }
77 /*    if (buf[0] != rank) {*/
78 /*        errs++;*/
79 /*        printf("Did not read expected value (%d)\n", buf[0]);*/
80 /*    }*/
81
82     err = MPI_File_get_info(fh, &infoout);
83     if (err) {
84         errs++;
85         MTestPrintError(err);
86     }
87     MPI_Info_get(infoout, (char *) "access_style", 1024, value, &flag);
88     /* Note that an implementation is allowed to ignore the set_info,
89      * so we'll accept either the original or the updated version */
90     if (!flag) {
91         ;
92         /*
93          * errs++;
94          * printf("Access style hint not saved\n");
95          */
96     }
97     else {
98         if (strcmp(value, "read_once") != 0 && strcmp(value, "write_once,random") != 0) {
99             errs++;
100             printf("value for access_style unexpected; is %s\n", value);
101         }
102     }
103     MPI_Info_free(&infoout);
104     err = MPI_File_close(&fh);
105     if (err) {
106         errs++;
107         MTestPrintError(err);
108     }
109     MPI_Barrier(comm);
110     MPI_Comm_rank(comm, &rank);
111     if (rank == 0) {
112         err = MPI_File_delete((char *) "/scratch/testfile", MPI_INFO_NULL);
113         if (err) {
114             errs++;
115             MTestPrintError(err);
116         }
117     }
118
119     MTest_Finalize(errs);
120     MPI_Finalize();
121     return 0;
122 }