Commit 03ca7beb authored by Huihuo Zheng's avatar Huihuo Zheng
Browse files

test_cache

parent 005e1ee2
......@@ -7,9 +7,12 @@ HDF5_LIB=-L$(HDF5_ROOT)/lib -lhdf5
%.o: %.cpp
$(CXX) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
all: read_dataset_cache prepare_dataset
all: test_cache read_dataset_cache prepare_dataset
test_mmap: test_mmap.o
$(CXX) $(CFLAGS) -o $@ $<
$(CXX) $(CFLAGS) -o $@ $<
test_cache: test_cache.o ../utils/profiling.o
$(CXX) $(CFLAGS) -o $@ $< ../utils/profiling.o
test_mmap_mem: test_mmap_mem.o ../utils/profiling.o
$(CXX) $(CFLAGS) -o $@ $< ../utils/profiling.o
read_dataset_cache: read_dataset_cache.o H5Dio_cache.o ../utils/debug.o ../utils/profiling.o
......
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "profiling.h"
#include "timing.h"
using namespace std;
int main(int argc, char **argv) {
Timing tt;
int dim = 1024576;
int nbatch = 1024;
int niter = 10;
double dat[dim];
double vm, rss;
for (int i=1; i<argc; i++) {
if (strcmp(argv[i], "--dim")==0) {
dim = int(atof(argv[i+1])); i=i+2;
} else if (strcmp(argv[i], "--nbatch")==0) {
nbatch = int(atof(argv[i+1])); i=i+2;
} else if (strcmp(argv[i], "--niter")==0) {
niter = int(atof(argv[i+1])); i=i+2;
}
}
cout << "dim: " << dim << endl;
cout << "nbatch: " << nbatch << endl;
cout << "size of file [MiB]: " << dim*nbatch*sizeof(double)/1024/1024 << endl;
cout << "niter: " << niter << endl;
for(int it =0; it < niter; it++) {
dat[0] = it;
tt.start_clock("write");
char fname[255] = "cache.dat";
strcat(fname, to_string(it).c_str());
int fd = open(fname, O_RDWR | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
for(int i=0; i<nbatch; i++) {
pwrite(fd, dat, sizeof(double)*dim, sizeof(double)*i*dim);
}
tt.stop_clock("write");
fsync(fd);
cout << "Write rate: " << sizeof(double)*dim*nbatch/tt["write"].t_iter[it]/1024/1024 << endl;
close(fd);
}
for(int it =0; it < niter; it++) {
char fname[255] = "cache.dat";
strcat(fname, to_string(it).c_str());
int fd = open(fname, O_RDONLY);
tt.start_clock("read");
for(int i=0; i<nbatch; i++) {
pread(fd, dat, sizeof(double)*dim, sizeof(double)*i*dim);
}
tt.stop_clock("read");
cout << "Read rate: " << sizeof(double)*dim*nbatch/tt["read"].t_iter[it]/1024/1024 << endl;
close(fd);
remove(fname);
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment