This source file includes following definitions.
- main
1
2
3
4
5
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <string.h>
9 #include <stdlib.h>
10
11 #define VERBOSE 0
12
13
14 int main(int argc, char **argv)
15 {
16 int i, rank, len, err;
17 int errs = 0;
18 char *filename, *tmp;
19 MPI_File fh;
20 char string[MPI_MAX_ERROR_STRING];
21
22 MPI_Init(&argc,&argv);
23 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24
25 #if VERBOSE
26 if (!rank) {
27 fprintf(stderr, "Tests if errors are reported correctly...\n");
28 fprintf(stderr, "Should say \"Invalid displacement argument\"\n\n");
29 }
30 #endif
31
32
33
34 if (!rank) {
35 i = 1;
36 while ((i < argc) && strcmp("-fname", *argv)) {
37 i++;
38 argv++;
39 }
40 if (i >= argc) {
41 fprintf(stderr, "\n*# Usage: simple -fname filename\n\n");
42 MPI_Abort(MPI_COMM_WORLD, 1);
43 }
44 argv++;
45 len = strlen(*argv);
46 filename = (char *) malloc(len+10);
47 strcpy(filename, *argv);
48 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
49 MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
50 }
51 else {
52 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
53 filename = (char *) malloc(len+10);
54 MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
55 }
56
57
58 tmp = (char *) malloc(len+10);
59 strcpy(tmp, filename);
60 sprintf(filename, "%s.%d", tmp, rank);
61
62 err = MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE+MPI_MODE_RDWR,
63 MPI_INFO_NULL, &fh);
64 err = MPI_File_set_view(fh, -1, MPI_BYTE, MPI_BYTE, "native",
65 MPI_INFO_NULL);
66
67
68
69
70 if (err != MPI_SUCCESS) {
71 MPI_Error_string(err, string, &len);
72 if (!rank) {
73 #if VERBOSE
74 fprintf(stderr, "%s\n", string);
75 #else
76
77
78 if (strstr( string, "displacement" ) == 0) {
79 fprintf( stderr, "Unexpected error message %s\n", string );
80 errs++;
81 }
82 #endif
83 }
84 }
85 else {
86 errs++;
87 fprintf( stderr, "File set view did not return an error\n" );
88 }
89
90 MPI_File_close(&fh);
91
92 free(filename);
93 free(tmp);
94
95 if (!rank) {
96 if (errs == 0) {
97 printf( " No Errors\n" );
98 }
99 else {
100 printf( " Found %d errors\n", errs );
101 }
102 }
103
104 MPI_Finalize();
105 return 0;
106 }