00001
00002
00003
00004
00005
00006 #include "mpi.h"
00007 #include <stdio.h>
00008 #include <string.h>
00009 #include <stdlib.h>
00010
00011
00012
00013
00014 #define SIZE (1048576*4)
00015
00016 int main(int argc, char **argv)
00017 {
00018 int *buf, i, j, mynod, nprocs, ntimes=5, len, err, flag;
00019 double stim, read_tim, write_tim, new_read_tim, new_write_tim;
00020 double min_read_tim=10000000.0, min_write_tim=10000000.0, read_bw, write_bw;
00021 MPI_File fh;
00022 MPI_Status status;
00023 char *filename;
00024
00025 MPI_Init(&argc,&argv);
00026 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
00027 MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
00028
00029
00030
00031 if (!mynod) {
00032 i = 1;
00033 while ((i < argc) && strcmp("-fname", *argv)) {
00034 i++;
00035 argv++;
00036 }
00037 if (i >= argc) {
00038 fprintf(stderr, "\n*# Usage: perf -fname filename\n\n");
00039 MPI_Abort(MPI_COMM_WORLD, 1);
00040 }
00041 argv++;
00042 len = strlen(*argv);
00043 filename = (char *) malloc(len+1);
00044 strcpy(filename, *argv);
00045 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00046 MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
00047 fprintf(stderr, "Access size per process = %d bytes, ntimes = %d\n", SIZE, ntimes);
00048 }
00049 else {
00050 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00051 filename = (char *) malloc(len+1);
00052 MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
00053 }
00054
00055
00056 buf = (int *) malloc(SIZE);
00057
00058 for (j=0; j<ntimes; j++) {
00059 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
00060 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00061 MPI_File_seek(fh, mynod*SIZE, MPI_SEEK_SET);
00062
00063 MPI_Barrier(MPI_COMM_WORLD);
00064 stim = MPI_Wtime();
00065 MPI_File_write(fh, buf, SIZE, MPI_BYTE, &status);
00066 write_tim = MPI_Wtime() - stim;
00067
00068 MPI_File_close(&fh);
00069
00070 MPI_Barrier(MPI_COMM_WORLD);
00071
00072 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
00073 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00074 MPI_File_seek(fh, mynod*SIZE, MPI_SEEK_SET);
00075
00076 MPI_Barrier(MPI_COMM_WORLD);
00077 stim = MPI_Wtime();
00078 MPI_File_read(fh, buf, SIZE, MPI_BYTE, &status);
00079 read_tim = MPI_Wtime() - stim;
00080
00081 MPI_File_close(&fh);
00082
00083 MPI_Allreduce(&write_tim, &new_write_tim, 1, MPI_DOUBLE, MPI_MAX,
00084 MPI_COMM_WORLD);
00085 MPI_Allreduce(&read_tim, &new_read_tim, 1, MPI_DOUBLE, MPI_MAX,
00086 MPI_COMM_WORLD);
00087
00088 min_read_tim = (new_read_tim < min_read_tim) ?
00089 new_read_tim : min_read_tim;
00090 min_write_tim = (new_write_tim < min_write_tim) ?
00091 new_write_tim : min_write_tim;
00092 }
00093
00094 if (mynod == 0) {
00095 read_bw = (SIZE*nprocs)/(min_read_tim*1024.0*1024.0);
00096 write_bw = (SIZE*nprocs)/(min_write_tim*1024.0*1024.0);
00097 fprintf(stderr, "Write bandwidth without file sync = %f Mbytes/sec\n", write_bw);
00098 fprintf(stderr, "Read bandwidth without prior file sync = %f Mbytes/sec\n", read_bw);
00099 }
00100
00101 min_write_tim=10000000.0;
00102 min_read_tim=10000000.0;
00103
00104 flag = 0;
00105 for (j=0; j<ntimes; j++) {
00106 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
00107 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00108 MPI_File_seek(fh, mynod*SIZE, MPI_SEEK_SET);
00109
00110 MPI_Barrier(MPI_COMM_WORLD);
00111 stim = MPI_Wtime();
00112 MPI_File_write(fh, buf, SIZE, MPI_BYTE, &status);
00113 err = MPI_File_sync(fh);
00114 write_tim = MPI_Wtime() - stim;
00115 if (err == MPI_ERR_UNKNOWN) {
00116 flag = 1;
00117 break;
00118 }
00119
00120 MPI_File_close(&fh);
00121
00122 MPI_Barrier(MPI_COMM_WORLD);
00123
00124 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
00125 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00126 MPI_File_seek(fh, mynod*SIZE, MPI_SEEK_SET);
00127
00128 MPI_Barrier(MPI_COMM_WORLD);
00129 stim = MPI_Wtime();
00130 MPI_File_read(fh, buf, SIZE, MPI_BYTE, &status);
00131 read_tim = MPI_Wtime() - stim;
00132
00133 MPI_File_close(&fh);
00134
00135 MPI_Allreduce(&write_tim, &new_write_tim, 1, MPI_DOUBLE, MPI_MAX,
00136 MPI_COMM_WORLD);
00137 MPI_Allreduce(&read_tim, &new_read_tim, 1, MPI_DOUBLE, MPI_MAX,
00138 MPI_COMM_WORLD);
00139
00140 min_read_tim = (new_read_tim < min_read_tim) ?
00141 new_read_tim : min_read_tim;
00142 min_write_tim = (new_write_tim < min_write_tim) ?
00143 new_write_tim : min_write_tim;
00144 }
00145
00146 if (mynod == 0) {
00147 if (flag) fprintf(stderr, "MPI_File_sync returns error.\n");
00148 else {
00149 read_bw = (SIZE*nprocs)/(min_read_tim*1024.0*1024.0);
00150 write_bw = (SIZE*nprocs)/(min_write_tim*1024.0*1024.0);
00151 fprintf(stderr, "Write bandwidth including file sync = %f Mbytes/sec\n", write_bw);
00152 fprintf(stderr, "Read bandwidth after file sync = %f Mbytes/sec\n", read_bw);
00153 }
00154 }
00155
00156 free(buf);
00157 free(filename);
00158 MPI_Finalize();
00159 return 0;
00160 }