This source file includes following definitions.
- handle_error
- main
1
2
3
4
5
6
7
8
9
10 #include <mpi.h>
11
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <time.h>
15
16 #include <sys/types.h>
17 #include <unistd.h>
18
19 #include <string.h>
20
21 #define BUFSIZE 512
22
23 static void handle_error(int errcode, const char *str)
24 {
25 char msg[MPI_MAX_ERROR_STRING];
26 int resultlen;
27 MPI_Error_string(errcode, msg, &resultlen);
28 fprintf(stderr, "%s: %s\n", str, msg);
29 MPI_Abort(MPI_COMM_WORLD, 1);
30 }
31
32 int main(int argc, char ** argv)
33 {
34 MPI_Info info = MPI_INFO_NULL;
35 MPI_File fh;
36 MPI_Offset off=0;
37 MPI_Status status;
38 int errcode;
39 int i, rank, errs=0, toterrs, buffer[BUFSIZE], buf2[BUFSIZE];
40
41 MPI_Init(&argc, &argv);
42
43 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
44
45 MPI_Info_create(&info);
46 MPI_Info_set(info, "romio_cb_write", "enable");
47 MPI_Info_set(info, "cb_nodes", "1");
48
49 for (i=0; i<BUFSIZE; i++) {
50 buffer[i] = 10000+rank;
51 }
52 off = rank*sizeof(buffer);
53
54 errcode = MPI_File_open(MPI_COMM_WORLD, argv[1],
55 MPI_MODE_WRONLY|MPI_MODE_CREATE, info, &fh);
56 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_open");
57 errcode = MPI_File_write_at_all(fh, off, buffer, BUFSIZE,
58 MPI_INT, &status);
59 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_write_at_all");
60 errcode = MPI_File_close(&fh);
61 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_close");
62
63 errcode = MPI_File_open(MPI_COMM_WORLD, argv[1],
64 MPI_MODE_RDONLY, info, &fh);
65 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_open");
66 errcode = MPI_File_read_at_all(fh, off, buf2, BUFSIZE,
67 MPI_INT, &status);
68 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_read_at_all");
69 errcode = MPI_File_close(&fh);
70 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_close");
71
72 for (i=0; i<BUFSIZE; i++) {
73 if (buf2[i] != 10000+rank)
74 errs++;
75 }
76 MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
77 if (rank == 0) {
78 if( toterrs > 0) {
79 fprintf( stderr, "Found %d errors\n", toterrs );
80 }
81 else {
82 fprintf( stdout, " No Errors\n" );
83 }
84 }
85 MPI_Info_free(&info);
86 MPI_Finalize();
87
88 return 0;
89 }