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 SIZE (65536)
12
13
14
15
16
17
18
19
20 int main(int argc, char **argv)
21 {
22 int *buf, i, rank, nints, len;
23 char *filename, *tmp;
24 int errs=0, toterrs;
25 MPI_File fh;
26 MPI_Status status;
27
28 PMPI_Init(&argc,&argv);
29 PMPI_Comm_rank(MPI_COMM_WORLD, &rank);
30
31
32
33 if (!rank) {
34 i = 1;
35 while ((i < argc) && strcmp("-fname", *argv)) {
36 i++;
37 argv++;
38 }
39 if (i >= argc) {
40 fprintf(stderr, "\n*# Usage: simple -fname filename\n\n");
41 PMPI_Abort(MPI_COMM_WORLD, 1);
42 }
43 argv++;
44 len = strlen(*argv);
45 filename = (char *) malloc(len+10);
46 strcpy(filename, *argv);
47 PMPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
48 PMPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
49 }
50 else {
51 PMPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
52 filename = (char *) malloc(len+10);
53 PMPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
54 }
55
56
57 buf = (int *) malloc(SIZE);
58 nints = SIZE/sizeof(int);
59 for (i=0; i<nints; i++) buf[i] = rank*100000 + i;
60
61
62 tmp = (char *) malloc(len+10);
63 strcpy(tmp, filename);
64 sprintf(filename, "%s.%d", tmp, rank);
65
66 PMPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR,
67 MPI_INFO_NULL, &fh);
68 PMPI_File_write(fh, buf, nints, MPI_INT, &status);
69 PMPI_File_close(&fh);
70
71
72
73 for (i=0; i<nints; i++) buf[i] = 0;
74 PMPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR,
75 MPI_INFO_NULL, &fh);
76 PMPI_File_read(fh, buf, nints, MPI_INT, &status);
77 PMPI_File_close(&fh);
78
79
80 for (i=0; i<nints; i++) {
81 if (buf[i] != (rank*100000 + i)) {
82 errs++;
83 fprintf(stderr, "Process %d: error, read %d, should be %d\n", rank, buf[i], rank*100000+i);
84 }
85 }
86
87 MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
88 if (rank == 0) {
89 if( toterrs > 0) {
90 fprintf( stderr, "Found %d errors\n", toterrs );
91 }
92 else {
93 fprintf( stdout, " No Errors\n" );
94 }
95 }
96
97 free(buf);
98 free(filename);
99 free(tmp);
100
101 PMPI_Finalize();
102 return 0;
103 }