1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2015 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
11 static void read_file(const char *name, void *buf, MPI_Datatype dt)
15 char datarep[] = "external32";
16 int amode = MPI_MODE_RDONLY;
21 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24 rc = MPI_File_open(MPI_COMM_WORLD, (char *) name,
25 amode, MPI_INFO_NULL, &fh);
26 if (rc != MPI_SUCCESS) {
27 printf("Rank %d: Failed to open file %s\n", rank, name);
29 MPI_Abort(MPI_COMM_WORLD, 1);
33 /* set file view to be sequence of datatypes past header */
34 MPI_File_set_view(fh, 0, dt, dt, datarep, MPI_INFO_NULL);
36 /* issue a collective read: In 3.2 and older the external32 code
37 * path had a bug that would cause an overlapping memcopy and crash
40 MPI_File_read_at_all(fh, offset, buf, 1, dt, &status);
48 static void write_file(const char *name, void *buf, MPI_Datatype dt)
51 char datarep[] = "external32";
56 /* get our rank in job */
57 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
60 amode = MPI_MODE_WRONLY | MPI_MODE_CREATE;
61 MPI_File_open(MPI_COMM_WORLD, (char *) name, amode, MPI_INFO_NULL, &fh);
63 /* truncate file to 0 bytes */
64 MPI_File_set_size(fh, 0);
66 /* set file view to be sequence of datatypes past header */
67 MPI_File_set_view(fh, 0, dt, dt, datarep, MPI_INFO_NULL);
69 /* collective write of file info */
71 MPI_File_write_at_all(fh, offset, buf, 1, dt, &status);
79 /* write and read a file in which each process writes one int
81 int main(int argc, char *argv[])
86 int blocks[2] = { 1, 1 };
87 int disps[2] = { 0, 1 };
89 MPI_Init(&argc, &argv);
90 MPI_Type_indexed(2, blocks, disps, MPI_CHAR, &dt);
93 write_file("testfile", buf, dt);
95 read_file("testfile", buf, dt);
99 /* if we get this far, then we've passed. No verification in this test at
101 fprintf(stdout, " No Errors\n");