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
12
13
14 #define SIZE (1048576*4)
15
16 int main(int argc, char **argv)
17 {
18 int *buf, i, j, mynod, nprocs, ntimes=5, len, err, flag;
19 double stim, read_tim, write_tim, new_read_tim, new_write_tim;
20 double min_read_tim=10000000.0, min_write_tim=10000000.0, read_bw, write_bw;
21 MPI_File fh;
22 MPI_Status status;
23 char *filename;
24
25 MPI_Init(&argc,&argv);
26 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
27 MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
28
29
30
31 if (!mynod) {
32 i = 1;
33 while ((i < argc) && strcmp("-fname", *argv)) {
34 i++;
35 argv++;
36 }
37 if (i >= argc) {
38 fprintf(stderr, "\n*# Usage: perf -fname filename\n\n");
39 MPI_Abort(MPI_COMM_WORLD, 1);
40 }
41 argv++;
42 len = strlen(*argv);
43 filename = (char *) malloc(len+1);
44 strcpy(filename, *argv);
45 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
46 MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
47 fprintf(stderr, "Access size per process = %d bytes, ntimes = %d\n", SIZE, ntimes);
48 }
49 else {
50 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
51 filename = (char *) malloc(len+1);
52 MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
53 }
54
55
56 buf = (int *) malloc(SIZE);
57
58 for (j=0; j<ntimes; j++) {
59 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
60 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
61 MPI_File_seek(fh, mynod*SIZE, MPI_SEEK_SET);
62
63 MPI_Barrier(MPI_COMM_WORLD);
64 stim = MPI_Wtime();
65 MPI_File_write(fh, buf, SIZE, MPI_BYTE, &status);
66 write_tim = MPI_Wtime() - stim;
67
68 MPI_File_close(&fh);
69
70 MPI_Barrier(MPI_COMM_WORLD);
71
72 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
73 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
74 MPI_File_seek(fh, mynod*SIZE, MPI_SEEK_SET);
75
76 MPI_Barrier(MPI_COMM_WORLD);
77 stim = MPI_Wtime();
78 MPI_File_read(fh, buf, SIZE, MPI_BYTE, &status);
79 read_tim = MPI_Wtime() - stim;
80
81 MPI_File_close(&fh);
82
83 MPI_Allreduce(&write_tim, &new_write_tim, 1, MPI_DOUBLE, MPI_MAX,
84 MPI_COMM_WORLD);
85 MPI_Allreduce(&read_tim, &new_read_tim, 1, MPI_DOUBLE, MPI_MAX,
86 MPI_COMM_WORLD);
87
88 min_read_tim = (new_read_tim < min_read_tim) ?
89 new_read_tim : min_read_tim;
90 min_write_tim = (new_write_tim < min_write_tim) ?
91 new_write_tim : min_write_tim;
92 }
93
94 if (mynod == 0) {
95 read_bw = (SIZE*nprocs)/(min_read_tim*1024.0*1024.0);
96 write_bw = (SIZE*nprocs)/(min_write_tim*1024.0*1024.0);
97 fprintf(stderr, "Write bandwidth without file sync = %f Mbytes/sec\n", write_bw);
98 fprintf(stderr, "Read bandwidth without prior file sync = %f Mbytes/sec\n", read_bw);
99 }
100
101 min_write_tim=10000000.0;
102 min_read_tim=10000000.0;
103
104 flag = 0;
105 for (j=0; j<ntimes; j++) {
106 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
107 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
108 MPI_File_seek(fh, mynod*SIZE, MPI_SEEK_SET);
109
110 MPI_Barrier(MPI_COMM_WORLD);
111 stim = MPI_Wtime();
112 MPI_File_write(fh, buf, SIZE, MPI_BYTE, &status);
113 err = MPI_File_sync(fh);
114 write_tim = MPI_Wtime() - stim;
115 if (err == MPI_ERR_UNKNOWN) {
116 flag = 1;
117 break;
118 }
119
120 MPI_File_close(&fh);
121
122 MPI_Barrier(MPI_COMM_WORLD);
123
124 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
125 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
126 MPI_File_seek(fh, mynod*SIZE, MPI_SEEK_SET);
127
128 MPI_Barrier(MPI_COMM_WORLD);
129 stim = MPI_Wtime();
130 MPI_File_read(fh, buf, SIZE, MPI_BYTE, &status);
131 read_tim = MPI_Wtime() - stim;
132
133 MPI_File_close(&fh);
134
135 MPI_Allreduce(&write_tim, &new_write_tim, 1, MPI_DOUBLE, MPI_MAX,
136 MPI_COMM_WORLD);
137 MPI_Allreduce(&read_tim, &new_read_tim, 1, MPI_DOUBLE, MPI_MAX,
138 MPI_COMM_WORLD);
139
140 min_read_tim = (new_read_tim < min_read_tim) ?
141 new_read_tim : min_read_tim;
142 min_write_tim = (new_write_tim < min_write_tim) ?
143 new_write_tim : min_write_tim;
144 }
145
146 if (mynod == 0) {
147 if (flag) fprintf(stderr, "MPI_File_sync returns error.\n");
148 else {
149 read_bw = (SIZE*nprocs)/(min_read_tim*1024.0*1024.0);
150 write_bw = (SIZE*nprocs)/(min_write_tim*1024.0*1024.0);
151 fprintf(stderr, "Write bandwidth including file sync = %f Mbytes/sec\n", write_bw);
152 fprintf(stderr, "Read bandwidth after file sync = %f Mbytes/sec\n", read_bw);
153 }
154 }
155
156 free(buf);
157 free(filename);
158 MPI_Finalize();
159 return 0;
160 }