-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench.c
93 lines (72 loc) · 2.26 KB
/
bench.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#define MASTER 0
static const long LIMIT=1048576;
MPI_Offset read_file(const int size, const int rank, char * name, long block_size) {
int err, i;
double start_read, readtime, end_read, total_time;
char *chunk;
long mypart;
MPI_Offset file_size, read_size;
MPI_File in;
MPI_File_open(MPI_COMM_WORLD, name, MPI_MODE_RDONLY, MPI_INFO_NULL, &in);
err = MPI_File_get_size(in, &file_size);
if(err != 0){
printf("Error: file open. code: %d. \n", err);
MPI_Finalize();
exit(1);
}
mypart=file_size/size;
chunk = malloc(block_size * sizeof(char));
MPI_Barrier(MPI_COMM_WORLD);
start_read = MPI_Wtime();
for(i = rank; i < mypart/block_size; i++){
read_size = block_size;
// if (i * block_size + block_size > mypart)
// read_size = file_size - i * block_size;
MPI_File_read_at(in, rank*mypart+i * block_size, chunk, read_size, MPI_CHAR, MPI_STATUS_IGNORE);
}
MPI_Barrier(MPI_COMM_WORLD);
end_read = MPI_Wtime();
readtime=end_read-start_read;
MPI_Reduce(&readtime, &total_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
if (rank == MASTER) {
printf("Time for whole read: %.2lf secs.\n", total_time);
printf("Total size: %lu bytes.\n", (unsigned long)file_size);
printf("Bandwidth: %.21f MB/s.\n", file_size / (1024*1024) / total_time);
}
free(chunk);
MPI_File_close(&in);
return file_size;
}
int main(int argc, char * argv[]) {
int size, rank; long block_size;
int namelen;
double start=0.0, end;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Offset file_size;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Get_processor_name(processor_name, &namelen);
fprintf(stdout, "Process %d of %d is on %s\n",
rank, size, processor_name);
fflush(stdout);
block_size = atol(argv[2]);
if (rank == MASTER)
start=MPI_Wtime();
//process_file(&in, size, rank, &out, argv[1], argv[2]);
//if (rank == MASTER){
// end=MPI_Wtime();
// printf("Wallclock time elapsed: %.2lf seconds\n", end-start);
//}
file_size = read_file(size, rank, argv[1], block_size);
//write_file(size, rank, argv[2], file_size);
if(rank==MASTER){
end=MPI_Wtime();
printf("Total wall clock time: %.21lf seconds.\n", end-start);
}
MPI_Finalize();
return 0;
}