Commit 89911fa2 authored by Huihuo Zheng's avatar Huihuo Zheng
Browse files

remove cpp dependence

parent 41f4262f
......@@ -7,11 +7,13 @@ HDF5_LIB=-L$(HDF5_ROOT)/lib -lhdf5
%.o: %.cpp
$(CXX) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
%.o: %.c
$(CXX) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
test_hdf5: test_hdf5.o ../utils/profiling.o
$(CXX) $(CFLAGS) -o $@ $< ../utils/profiling.o $(HDF5_LIB)
test: test_cache test_mmap_mem
test_hdf5: test_hdf5.o ../utils/profiling.o ../utils/debug.o
$(CXX) $(CFLAGS) -o $@ $< ../utils/profiling.o ../utils/debug.o $(HDF5_LIB)
test: test_cache test_mmap_mem
test_cache: test_cache.o ../utils/profiling.o
......
#include <iostream>
#include <fcntl.h>
#include <sys/stat.h>
#include "hdf5.h"
#include "stdio.h"
#include "stdlib.h"
......@@ -15,10 +13,9 @@
#include <stdio.h>
#include <sys/statvfs.h>
#include <stdlib.h>
using namespace std;
int CACHE_BLOCK_SIZE=1073741824;
int CACHE_NUM_FILES=10;
int MEMORY_CAPACITY=128;
int MEMORY_PER_RANK=15;
double *dummy_data;
bool allocated = false;
void int2char(int a, char str[255]) {
......@@ -29,20 +26,22 @@ void clear_cache(char *rank) {
char *a = new char [CACHE_BLOCK_SIZE];
double vm, rss;
process_mem_usage(vm, rss);
printf(" VM: %5.2f MB; RSS: %5.2f MB \n", vm, rss);
size_t dim = size_t((MEMORY_CAPACITY - rss/1024)*0.95*1024*1024*1024/64);
if (not allocated) {
printf("dimension is : %u GB\n", dim*64/1024/1024/1024);
//printf(" VM: %5.2f MB; RSS: %5.2f MB \n", vm, rss);
if ((not allocated) and getenv("MEMORY_PER_RANK")) {
size_t dim = size_t(atof(getenv("MEMORY_PER_RANK")))*1024*1024*1024/8;
printf("* Dimension is : %u GB\n", dim*8/1024/1024/1024);
dummy_data = new double[dim];
for(int i=0; i<dim; i++) dummy_data[i] = i;
allocated = true;
}
process_mem_usage(vm, rss);
printf(" VM: %5.2f MB; RSS: %5.2f MB \n", vm, rss);
//process_mem_usage(vm, rss);
//printf(" VM: %5.2f MB; RSS: %5.2f MB \n", vm, rss);
//delete [] dummy_data;
//process_mem_usage(vm, rss);
//printf(" VM: %5.2f MB; RSS: %5.2f MB \n", vm, rss);
///allocated = false;
for(int i=0; i<CACHE_NUM_FILES; i++) {
char fname[255];
if (getenv("CACHE_SSD")) {
mkdir("/local/scratch/cache/",0777);
strcpy(fname, "/local/scratch/cache/tmp");
......@@ -80,9 +79,7 @@ int main(int argc, char **argv) {
if (getenv("CACHE_NUM_FILES")) {
CACHE_NUM_FILES = int(atof(getenv("CACHE_NUM_FILES")));
}
if (getenv("MEMORY_CAPACITY")) {
MEMORY_CAPACITY= int(atof(getenv("MEMORY_CAPACITY")));
}
int i=0;
int bufferm = 8;
int niter = 8;
......@@ -130,11 +127,13 @@ int main(int argc, char **argv) {
H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);
for(int it = 0; it < niter; it++) {
hid_t fd = H5Fcreate("test.hdf5", H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
tt.start_clock("WRITE");
hid_t dset_id = H5Dcreate(fd, "dset", H5T_NATIVE_INT, filespace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
tt.start_clock("WRITE");
H5Dwrite(dset_id, H5T_NATIVE_INT, memspace, filespace, dxf_id, data);
H5Dclose(dset_id);
tt.stop_clock("WRITE");
H5Dclose(dset_id);
H5Fflush(fd, H5F_SCOPE_LOCAL);
H5Fclose(fd);
char srank[255];
......@@ -145,11 +144,13 @@ int main(int argc, char **argv) {
MPI_Barrier(MPI_COMM_WORLD);
tt.stop_clock("CLEAR_CACHE");
fd = H5Fopen("test.hdf5", H5F_ACC_RDONLY, plist_id);
tt.start_clock("READ");
dset_id = H5Dopen(fd, "dset", H5P_DEFAULT);
tt.start_clock("READ");
H5Dread(dset_id, H5T_NATIVE_INT, memspace, filespace, dxf_id, data_r);
H5Dclose(dset_id);
tt.stop_clock("READ");
H5Dclose(dset_id);
H5Fclose(fd);
for (int i=0; i<buffer; i++)
assert(data[i]==data_r[i]);
......@@ -159,6 +160,7 @@ int main(int argc, char **argv) {
}
H5Pclose(plist_id);
H5Pclose(dxf_id);
delete [] dummy_data;
MPI_Finalize();
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