Commit af25b46e authored by myron's avatar myron
Browse files

works with highfive

parent cd90a62c
......@@ -2752,11 +2752,14 @@ def superR_getVolume_Esynt(mydata):
DS.tofile(DSname)
DD.tofile(DDname)
SS.tofile(SSname)
SS.tofile(SSname)
h5py.File(DSname+".h5","w")["data"] = DS.astype("f")
h5py.File(DSname +".h5","w")["data"] = DS.astype("f")
h5py.File(DDname +".h5","w")["data"] = DD.astype("f")
h5py.File(SSname +".h5","w")["data"] = SS.astype("f")
h5py.File(COEFname+".h5","w")["data"] = coefficients.astype("f")
def superR_getVolume(mydata):
"""
Here an example of the input file dedicated section ::
......
......@@ -16,14 +16,14 @@
namespace h5 = HighFive;
struct DimPars_struct {
int NE ;
int NV ;
int NROI;
int DIMZ;
int DIMY;
int DIMX;
size_t NE ;
size_t NV ;
size_t NROI;
size_t DIMZ;
size_t DIMY;
size_t DIMX;
int ZSTART ;
int ZEND ;
int ZEND ;
};
typedef DimPars_struct DimPars;
......@@ -35,26 +35,27 @@ struct InputFileNames_struct {
};
typedef InputFileNames_struct InputFileNames;
float * read_volume(std::string fn, size_t nbytes) {
boost::filesystem::path file(fn);
if(!( boost::filesystem::file_size(file) == nbytes)){
std::cerr<< std::string("File ")+fn+std::string(" has not the required size ")<< nbytes<< " it is " <<boost::filesystem::file_size(file)<<std::endl;
}
assert(( boost::filesystem::file_size(file) == nbytes));
float *res = (float*) malloc(nbytes);
FILE * stream = fopen( fn.c_str() ,"r");
size_t bread = fread( res , nbytes, 1, stream);
assert(bread==1);
fclose(stream);
return res;
float * read_volume(std::string fn, std::vector<size_t> &dims) {
float * result;
std::string testh5_name(fn+".h5" ) ;
h5::File test_file( testh5_name , h5::File::ReadOnly);
h5::DataSet test_dataset = test_file.getDataSet("data");
dims = test_dataset.getDimensions();
size_t tot = 1;
for(size_t i=0; i< dims.size(); i++) tot *= dims[i];
result = (float*) malloc( tot * sizeof(float));
test_dataset.read( result , h5::AtomicType<float>() ) ;
return result;
}
void save_volume(std::string fn, float * X , size_t nbytes) {
FILE * stream = fopen( fn.c_str() ,"w");
size_t bcount = fwrite( X, nbytes, 1, stream);
assert(bcount==1);
fclose(stream);
void save_volume(std::string fn, float * X , std::vector<size_t> dims) {
std::string testh5_name(fn+".h5" ) ;
h5::File test_file( testh5_name , h5::File::ReadWrite | h5::File::Create | h5::File::Truncate );
h5::DataSet dataset = test_file.createDataSet<float>("data", h5::DataSpace(dims));
dataset.write_raw(X);
}
......@@ -84,55 +85,29 @@ public:
// SS SHAPE (7, 72, 241, 241)
class Problem {
public:
Problem(InputFileNames &if_names_a, DimPars & dimpars_a){
Problem(InputFileNames &if_names_a, DimPars & dimpars_a ){
this->if_names = if_names_a;
this->dimpars = dimpars_a;
{
std::string testh5_name(if_names.DSname+".h5" ) ;
h5::File test_file( testh5_name , h5::File::ReadOnly);
h5::DataSet test_dataset = test_file.getDataSet("data");
std::vector<size_t> test_dims = test_dataset.getDimensions();
printf( " %d %d %d %d %d\n", test_dims[0], test_dims[1], test_dims[2], test_dims[3], test_dims[4] );
this->dimpars.NV = test_dims[0] ;
this->dimpars.NROI = test_dims[0] ;
this->dimpars.DIMZ = test_dims[0] ;
this->dimpars.DIMY = test_dims[0] ;
this->dimpars.DIMX = test_dims[0] ;
this->DS = (float*) malloc( size_t(dimpars.NV)*
size_t(dimpars.NROI)*
size_t(dimpars.DIMZ)*
size_t(dimpars.DIMY)*
size_t(dimpars.DIMX) * sizeof(float));
test_dataset.read( this->DS , h5::AtomicType<float>() ) ;
std::vector<size_t> dims ;
this->DS = read_volume( if_names.DSname, dims) ;
dimpars.NV = dims[0] ;
dimpars.NROI = dims[1] ;
dimpars.DIMZ = dims[2] ;
dimpars.DIMY = dims[3] ;
dimpars.DIMX = dims[4] ;
}
this->DS = read_volume( if_names.DSname,
size_t(dimpars.NV)*
size_t(dimpars.NROI)*
size_t(dimpars.DIMZ)*
size_t(dimpars.DIMY)*
size_t(dimpars.DIMX) * sizeof(float));
if(dimpars.ZSTART>=0) {
int dimz = 1+dimpars.ZEND - dimpars.ZSTART ;
int dimz = 1+ dimpars.ZEND - dimpars.ZSTART ;
float *ds = (float*) malloc(size_t(dimpars.NV)*size_t(dimpars.NROI)*size_t(dimz)* size_t(dimpars.DIMY)* size_t(dimpars.DIMX) * sizeof(float) ) ;
size_t BLOCK = size_t(dimpars.DIMZ)* size_t(dimpars.DIMY)* size_t(dimpars.DIMX ) ;
size_t block = size_t( dimz)* size_t(dimpars.DIMY)* size_t(dimpars.DIMX ) ;
size_t offset = size_t(dimpars.ZSTART)* size_t(dimpars.DIMY)* size_t(dimpars.DIMX) ;
for(int iv=0; iv< dimpars.NV; iv++) {
for(int ir=0; ir< dimpars.NROI; ir++) {
for(int iv=0; iv< (int) dimpars.NV; iv++) {
for(int ir=0; ir< (int) dimpars.NROI; ir++) {
memcpy(
ds + (iv*dimpars.NROI+ir)*block ,
DS + (iv*dimpars.NROI+ir)*BLOCK+offset,
......@@ -145,20 +120,29 @@ public:
this->DS = ds ;
}
this->DD = read_volume( if_names.DDname,
size_t(dimpars.NV)* size_t(dimpars.NROI)* sizeof(float));
this->SS = read_volume( if_names.SSname,
size_t(dimpars.NROI)*
size_t(dimpars.DIMX)*
size_t(dimpars.DIMX)*
sizeof(float));
{
std::vector<size_t> dims ;
this->DD = read_volume( if_names.DDname, dims) ;
assert( dims[0] == dimpars.NV ) ;
assert( dims[1] == dimpars.NROI ) ;
}
{
std::vector<size_t> dims ;
this->SS = read_volume( if_names.SSname, dims) ;
assert( dims[0] == dimpars.NROI ) ;
assert( dims[1] == dimpars.DIMX ) ;
assert( dims[2] == dimpars.DIMX ) ;
}
{
std::vector<size_t> dims ;
this->coefficients = read_volume( if_names.COEFFSname, dims) ;
dimpars.NE = dims[0] ;
assert( dims[1] == dimpars.NV ) ;
assert( dims[2] == dimpars.NROI ) ;
}
this->coefficients = read_volume( if_names.COEFFSname,
size_t(dimpars.NE)*
size_t(dimpars.NV)*
size_t(dimpars.NROI)*
sizeof(float));
/*{
int cnt=0;
......@@ -191,6 +175,7 @@ public:
this->VectR = (float*) malloc( d->NROI * sizeof(float) ) ;
}
#define SOL_addr( iE, iz, iy , ix ) ((( (iE)*DIMZ + (iz))*DIMY+ (iy))*DIMX+ (ix))
#define SS_addr( iroi, ix1, ix2 ) (( (iroi)*DIMX+ (ix1))*DIMX+ (ix2))
#define PRO_addr( iV, iroi, iz, iy, ix ) ((( ( (iV)*NROI +iroi )*DIMZ + (iz))*DIMY+ (iy))*DIMX+ (ix))
......@@ -408,9 +393,8 @@ public:
};
void save(SolVol X, std::string name) {
save_volume( name,X.ptr,
size_t(dimpars.NE)*size_t(dimpars.DIMZ)* size_t(dimpars.DIMY)* size_t(dimpars.DIMX) * sizeof(float));
std::vector<size_t> dims = {size_t(dimpars.NE),size_t(dimpars.DIMZ), size_t(dimpars.DIMY), size_t(dimpars.DIMX) };
save_volume( name,X.ptr, dims);
};
......@@ -673,10 +657,11 @@ int main(int argc, char ** argv) {
assert( mockup_config["SSname"] ) ;
assert( mockup_config["COEFFSname"] ) ;
int zstart = -1, zend = 100000 ;
DimPars dimpars ;
dimpars.ZSTART = -1; dimpars.ZEND = 100000 ;
if( mockup_config["ZSTART"] ) {
zstart = mockup_config["ZSTART"].as<int>();
zend = mockup_config["ZEND" ].as<int>();
dimpars.ZSTART = mockup_config["ZSTART"].as<int>();
dimpars.ZEND = mockup_config["ZEND" ].as<int>();
} ;
......@@ -691,17 +676,6 @@ int main(int argc, char ** argv) {
} ;
DimPars dimpars = {
mockup_config["NE" ].as<int>(),
mockup_config["NV" ].as<int>(),
mockup_config["NROI" ].as<int>(),
mockup_config["DIMZ" ].as<int>(),
mockup_config["DIMY" ].as<int>(),
mockup_config["DIMX" ].as<int>(),
zstart,
zend
};
boost::filesystem::path p(argv[index_input]);
std::string dirname = p.parent_path().string()+"/";
......@@ -713,7 +687,7 @@ int main(int argc, char ** argv) {
dirname + mockup_config["COEFFSname"].as<std::string>()
};
Problem pb( if_names, dimpars );
Problem pb( if_names, dimpars );
SolVol X, grad , XvectA, Xtmp;
......
Supports Markdown
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