Fix restart. Use boost::property_tree if available. Remove adios read/write for qmc state and random number generator.

git-svn-id: https://subversion.assembla.com/svn/qmcdev/trunk@6100 e5b18d87-469d-4833-9cc0-8cdfa06e9491
This commit is contained in:
Jeongnim Kim 2013-12-04 16:42:14 +00:00
parent d8b5de914a
commit 01fba83a4a
11 changed files with 445 additions and 462 deletions

View File

@ -219,7 +219,6 @@ Communicate::~Communicate() {}
void Communicate::initialize(int argc, char **argv)
{
std::string when="qmc."+getDateAndTime("%Y%m%d_%H%M");
hpmInit(QMC_MAIN_EVENT,when.c_str());
}
void Communicate::set_world()
@ -228,7 +227,6 @@ void Communicate::set_world()
void Communicate::finalize()
{
hpmTerminate(QMC_MAIN_EVENT);
}
void Communicate::abort()

View File

@ -25,12 +25,16 @@
#include <HDFVersion.h>
#include <io/hdf_archive.h>
#include <mpi/collectives.h>
#ifdef HAVE_ADIOS
#include "ADIOS/ADIOS_config.h"
#ifdef ADIOS_VERIFY
#include "ADIOS/ADIOS_verify.h"
#endif
#if defined(HAVE_LIBBOOST)
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/foreach.hpp>
#include <string>
#include <set>
#include <exception>
#include <iostream>
#endif
#include <Utilities/SimpleParser.h>
namespace qmcplusplus
{
@ -237,97 +241,55 @@ bool RandomNumberControl::put(xmlNodePtr cur)
void RandomNumberControl::read(const string& fname, Communicate* comm)
{
return;
int nthreads=omp_get_max_threads();
vector<uint_type> vt_tot, vt;
TinyVector<int,2> shape(0);
TinyVector<hsize_t,2> shape_t(0);
shape_t[1]=Random.state_size();
hyperslab_proxy<vector<uint_type>,2> slab(vt_tot,shape_t);
vector<int> shape(2,0),shape_now(2,0);
shape_now[0]=comm->size()*nthreads;
shape_now[1]=Random.state_size();
if(comm->rank()==0)
{
string h5name(fname);
if(fname.find("config.h5")>= fname.size()) h5name.append(".config.h5");
hdf_archive hout(comm);
hout.open(h5name,H5F_ACC_RDONLY);
hout.push(hdf::main_state);
hout.push("random");
hout.read(slab,Random.EngineName);
shape[0]=static_cast<int>(slab.size(0));
shape[1]=static_cast<int>(slab.size(1));
}
//bcast of hsize_t is not working
mpi::bcast(*comm,shape);
if(shape[0]!=comm->size()*nthreads || shape[1] != Random.state_size())
{
app_log() << "Mismatched random number generators."
<< "\n Number of streams : old=" << shape[0] << " new= " << comm->size()*nthreads
<< "\n State size per stream : old=" << shape[1] << " new= " << Random.state_size()
<< "\n Using the random streams generated at the initialization." << endl;
return;
}
app_log() << " Restart from the random number streams from the previous configuration." << endl;
vt_tot.resize(shape[0]);
vt.resize(nthreads*Random.state_size());
if(comm->size()>1)
mpi::scatter(*comm,vt_tot,vt);
else
std::copy(vt_tot.begin(),vt_tot.begin()+vt.size(),vt.begin());
{
if(nthreads>1)
#if defined(HAVE_LIBBOOST)
using boost::property_tree::ptree;
ptree pt;
string xname=fname+".random.xml";
read_xml(xname, pt);
if(!pt.empty())
{
vector<uint_type>::iterator vt_it(vt.begin());
for(int ip=0; ip<nthreads; ip++, vt_it += shape[1])
string engname=pt.get<string>("random.engine");
if(engname==Random.EngineName)
{
vector<uint_type> c(vt_it,vt_it+shape[1]);
Children[ip]->load(c);
istringstream dims(pt.get<string>("random.dims"));
dims >> shape[0] >> shape[1];
if(shape[0]==shape_now[0] && shape[1]==shape_now[1])
{
vt_tot.resize(shape[0]*shape[1]);
istringstream v(pt.get<string>("random.states"));
for(int i=0; i<vt_tot.size(); ++i) v>>vt_tot[i];
}
else
shape[0]=shape[1]=0;
}
}
else
Random.load(vt);
}
}
#ifdef HAVE_ADIOS
void RandomNumberControl::read_adios(const string& fname, Communicate* comm)
{
//do not use adios for random number generators
int nthreads=omp_get_max_threads();
vector<uint_type> vt_tot, vt;
TinyVector<int,2> shape(0);
if(ADIOS::getRdADIOS())
{
ADIOS::open(fname, comm->getMPI());
TinyVector<hsize_t,2> shape_t(0);
shape_t[1]=Random.state_size();
ADIOS::read_random(vt_tot, shape, "random");
ADIOS::close();
}
else if(ADIOS::getRdHDF5())
{
//read it
string h5name(fname);
if(fname.find("config.h5")>= fname.size())
h5name.append(".config.h5");
hdf_archive hout(comm);
hout.open(h5name,H5F_ACC_RDONLY);
hout.push(hdf::main_state);
hout.push("random");
#else
TinyVector<hsize_t,2> shape_t(0);
shape_t[1]=Random.state_size();
hyperslab_proxy<vector<uint_type>,2> slab(vt_tot,shape_t);
string h5name=fname+".random.h5";
hdf_archive hout(comm);
hout.open(h5name,H5F_ACC_RDONLY);
hout.push(hdf::main_state);
hout.push("random");
string engname;
hout.read(slab,Random.EngineName);
shape[0]=static_cast<int>(slab.size(0));
shape[1]=static_cast<int>(slab.size(1));
#endif
}
//bcast of hsize_t is not working
mpi::bcast(*comm,shape);
if(shape[0]!=comm->size()*nthreads || shape[1] != Random.state_size())
if(shape[0]!=shape_now[0] || shape[1] != shape_now[1])
{
app_log() << "Mismatched random number generators."
<< "\n Number of streams : old=" << shape[0] << " new= " << comm->size()*nthreads
@ -335,17 +297,14 @@ void RandomNumberControl::read_adios(const string& fname, Communicate* comm)
<< "\n Using the random streams generated at the initialization." << endl;
return;
}
app_log() << " Restart from the random number streams from the previous configuration." << endl;
vt_tot.resize(shape[0]);
vt.resize(nthreads*Random.state_size());
if(comm->size()>1)
{
mpi::scatter(*comm,vt_tot,vt);
//MPI_Datatype type_id=mpi::get_mpi_datatype(*vt_tot.data());
//MPI_Scatter(vt_tot.data(), shape[0], type_id, vt.data(), nthreads*Random.state_size(), type_id, 0, *comm);
}
else
std::copy(vt_tot.begin(),vt_tot.begin()+vt.size(),vt.begin());
std::copy(vt_tot.begin(),vt_tot.end(),vt.begin());
{
if(nthreads>1)
@ -362,75 +321,8 @@ void RandomNumberControl::read_adios(const string& fname, Communicate* comm)
}
}
uint64_t RandomNumberControl::get_group_size()
{
return 4 * omp_get_max_threads() * Random.state_size() + 4 * 4;
}
void RandomNumberControl::adios_checkpoint(int64_t adios_handle)
{
int nthreads=omp_get_max_threads();
vector<uint_type> vt, vt_tot;
vt.reserve(nthreads * Random.state_size());
if(nthreads>1)
for(int ip=0; ip<nthreads; ++ip)
{
vector<uint_type> c;
Children[ip]->save(c);
vt.insert(vt.end(),c.begin(),c.end());
}
else
Random.save(vt);
//write these values to variables that random.ch is looking for
void* random = (void*)vt.data();
int thread_size = omp_get_max_threads();
int random_size = Random.state_size();
int rank = OHMMS::Controller->rank() * omp_get_max_threads();
int global_size = OHMMS::Controller->size() * omp_get_max_threads();
int local_size = omp_get_max_threads();
adios_write (adios_handle, "random_size", &random_size);
adios_write (adios_handle, "thread_rank", &rank);
adios_write (adios_handle, "global_size", &global_size);
adios_write (adios_handle, "local_size", &local_size);
adios_write (adios_handle, "random", random);
}
#ifdef ADIOS_VERIFY
void RandomNumberControl::adios_checkpoint_verify(ADIOS_FILE *fp)
{
int nthreads=omp_get_max_threads();
vector<uint_type> vt, vt_tot;
vt.reserve(nthreads * Random.state_size());
if(nthreads>1)
for(int ip=0; ip<nthreads; ++ip)
{
vector<uint_type> c;
Children[ip]->save(c);
vt.insert(vt.end(),c.begin(),c.end());
}
else
Random.save(vt);
//write these values to variables that random.ch is looking for
//void* random = (void*)vt.data();
int thread_size = omp_get_max_threads();
int random_size = Random.state_size();
int rank = OHMMS::Controller->rank() * omp_get_max_threads();
int global_size = OHMMS::Controller->size() * omp_get_max_threads();
int local_size = omp_get_max_threads();
IO_VERIFY::adios_checkpoint_verify_variables(fp, "random_size", &random_size);
IO_VERIFY::adios_checkpoint_verify_variables(fp, "thread_rank", &rank);
IO_VERIFY::adios_checkpoint_verify_variables(fp, "global_size", &global_size);
IO_VERIFY::adios_checkpoint_verify_variables(fp, "local_size", &local_size);
IO_VERIFY::adios_checkpoint_verify_random_variables(fp, "random", (uint_type *)vt.data());
}
#endif
#endif
void RandomNumberControl::write(const string& fname, Communicate* comm)
{
return;
int nthreads=omp_get_max_threads();
vector<uint_type> vt, vt_tot;
vt.reserve(nthreads*1024);
@ -450,17 +342,38 @@ void RandomNumberControl::write(const string& fname, Communicate* comm)
}
else
vt_tot=vt;
string h5name(fname);
if(fname.find("config.h5")>= fname.size())
h5name.append(".config.h5");
hdf_archive hout(comm);
hout.open(h5name,H5F_ACC_RDWR);
hout.push(hdf::main_state);
hout.push("random");
TinyVector<hsize_t,2> shape(comm->size()*nthreads,Random.state_size());
hyperslab_proxy<vector<uint_type>,2> slab(vt_tot,shape);
hout.write(slab,Random.EngineName);
hout.close();
if(comm->rank()==0)
{
#if defined(HAVE_LIBBOOST)
using boost::property_tree::ptree;
ptree pt;
ostringstream dims,vt_o;
dims<<comm->size()*nthreads << " " << Random.state_size();
vector<uint_type>::iterator v=vt_tot.begin();
for(int i=0; i<comm->size()*nthreads; ++i)
{
std::copy(v,v+Random.state_size(),std::ostream_iterator<uint_type>(vt_o," "));
vt_o<<endl;
v+=Random.state_size();
}
pt.put("random.engine", Random.EngineName);
pt.put("random.dims",dims.str());
pt.put("random.states",vt_o.str());
string xname=fname+".random.xml";
write_xml(xname, pt);
#else
string h5name=fname+".random.h5";
hdf_archive hout(comm);
hout.create(h5name);
hout.push(hdf::main_state);
hout.push("random");
TinyVector<hsize_t,2> shape(comm->size()*nthreads,Random.state_size());
hyperslab_proxy<vector<uint_type>,2> slab(vt_tot,shape);
hout.write(slab,Random.EngineName);
hout.close();
#endif
}
}
}
/***************************************************************************

View File

@ -22,14 +22,6 @@
#include "Utilities/RandomGenerator.h"
#include "Utilities/PrimeNumberSet.h"
#ifdef HAVE_ADIOS
#include "adios.h"
#ifdef ADIOS_VERIFY
#include "adios_read.h"
#include "adios_error.h"
#endif
#endif
class Communicate;
namespace qmcplusplus
@ -77,19 +69,6 @@ public:
*/
static void write(const string& fname, Communicate* comm);
#ifdef HAVE_ADIOS
static void read_adios(const string& fname, Communicate* comm);
/*
* * Write data with adios.
* */
static void adios_checkpoint(int64_t adios_handle);
static uint64_t get_group_size();
#ifdef ADIOS_VERIFY
static void adios_checkpoint_verify(ADIOS_FILE *fp);
#endif
#endif
private:
bool NeverBeenInitialized;

View File

@ -26,10 +26,38 @@
#include "ADIOS/ADIOS_verify.h"
#endif
#endif
#if defined(HAVE_LIBBOOST)
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/foreach.hpp>
#include <string>
#include <set>
#include <exception>
#include <iostream>
#endif
//#include <boost/archive/text_oarchive.hpp>
//
namespace qmcplusplus
{
#if defined(HAVE_LIBBOOST)
template<typename T>
inline void put_histogram(string name, accumulator_set<T> a, boost::property_tree::ptree &pt)
{
pt.put(name+".value",a.properties[0]);
pt.put(name+".value_squared",a.properties[1]);
pt.put(name+".weight",a.properties[2]);
}
template<typename T>
inline void get_histogram(string name, accumulator_set<T>& a, boost::property_tree::ptree &pt)
{
a.properties[0]=pt.get<T>(name+".value");
a.properties[1]=pt.get<T>(name+".value_squared");
a.properties[2]=pt.get<T>(name+".weight");
}
#endif
template<typename T>
struct h5data_proxy<accumulator_set<T> >: public h5_space_type<T,1>
{
@ -65,8 +93,242 @@ struct h5data_proxy<accumulator_set<T> >: public h5_space_type<T,1>
}
};
#ifdef HAVE_ADIOS
vector<string> BranchIO::vParamName;
vector<string> BranchIO::iParamName;
void BranchIO::initAttributes()
{
if(vParamName.size()) return;
vParamName.resize(10);
vParamName[0]="tau";
vParamName[1]="taueff";
vParamName[2]="etrial";
vParamName[3]="eref";
vParamName[4]="branchmax";
vParamName[5]="branchcutoff";
vParamName[6]="branchfilter";
vParamName[7]="sigma";
vParamName[8]="acc_energy";
vParamName[9]="acc_samples";
iParamName.resize(7);
iParamName[0]="warmupsteps";
iParamName[1]="energyupdateinterval";
iParamName[2]="counter";
iParamName[3]="targetwalkers";
iParamName[4]="maxwalkers";
iParamName[5]="minwalkers";
iParamName[6]="brnachinterval";
}
bool BranchIO::write(const string& fname)
{
if(myComm->rank()) return true;
#if defined(HAVE_LIBBOOST)
initAttributes();
using boost::property_tree::ptree;
ptree pt;
// Put log filename in property tree
pt.put("state.branchmode", ref.BranchMode);
for(int i=0;i<vParamName.size(); ++i)
pt.put("state.vparam."+vParamName[i], ref.vParam[i]);
for(int i=0;i<iParamName.size(); ++i)
pt.put("state.iparam."+iParamName[i], ref.iParam[i]);
put_histogram("state.energy",ref.EnergyHist,pt);
put_histogram("state.variance",ref.VarianceHist,pt);
put_histogram("state.r2accepted",ref.R2Accepted,pt);
put_histogram("state.r2proposed",ref.R2Proposed,pt);
string xname=fname+".qmc.xml";
write_xml(xname, pt);
#else
//append .qmc.h5 if missing
string h5name(fname);
if(fname.find("qmc.h5")>= fname.size()) h5name.append(".qmc.h5");
hdf_archive dump(myComm);
hid_t fid = dump.create(h5name);
dump.push(hdf::main_state);
dump.push(hdf::qmc_status);
string v_header("tau:taueff:etrial:eref:branchmax:branchcutoff:branchfilter:sigma:acc_energy:acc_samples");
string i_header("warmupsteps:energyupdateinterval:counter:targetwalkers:maxwalkers:minwalkers:branchinterval");
dump.write(v_header,"vparam_def");
dump.write(i_header,"iparam_def");
dump.write(ref.vParam,"vparam");
dump.write(ref.iParam,"iparam");
dump.write(ref.BranchMode,"branchmode");
dump.push("histogram");
dump.write(ref.EnergyHist,"energy");
dump.write(ref.VarianceHist,"variance");
dump.write(ref.R2Accepted,"r2accepted");
dump.write(ref.R2Proposed,"r2proposed");
//PopHist is not being used in 2010-10-19
//if(ref.BranchMode[SimpleFixedNodeBranch::B_DMC])
//{
// dump.push("population");
// dump.write(ref.PopHist.myData,"histogram");
//}
#endif
return true;
}
bool BranchIO::read(const string& fname)
{
int found_config=0;
#if defined(HAVE_LIBBOOST)
if(myComm->rank()==0)
{
initAttributes();
using boost::property_tree::ptree;
ptree pt;
string xname=fname+".qmc.xml";
read_xml(xname, pt);
if(!pt.empty())
{
ref.BranchMode=pt.get<BranchModeType>("state.branchmode");
get_histogram("state.energy",ref.EnergyHist,pt);
get_histogram("state.variance",ref.VarianceHist,pt);
get_histogram("state.r2accepted",ref.R2Accepted,pt);
get_histogram("state.r2proposed",ref.R2Proposed,pt);
int i=0;
BOOST_FOREACH(const ptree::value_type& v, pt.get_child("state.iparam"))
{
ref.iParam[i++]=v.second.get_value<int>();
}
i=0;
BOOST_FOREACH(const ptree::value_type& v, pt.get_child("state.vparam"))
{
ref.vParam[i++]=v.second.get_value<double>();
}
found_config=1;
}
}
#else
if(myComm->rank()==0)
{
HDFVersion res_version(0,4); //start using major=0 and minor=4
HDFVersion res_20080624(0,5);//major revision on 2008-06-24 0.5
HDFVersion in_version(0,1);
//append .config.h5 if missing
string h5name(fname);
if(fname.find("qmc.h5")>= fname.size()) h5name.append(".qmc.h5");
hdf_archive prevconfig(myComm,true);
found_config=prevconfig.open(h5name,H5F_ACC_RDONLY);
if(found_config)
{
int n=ref.vParam.size()+ref.iParam.size();
/** temporary storage to broadcast restart data */
prevconfig.read(in_version.version,hdf::version);
myComm->bcast(in_version.version);
prevconfig.push(hdf::main_state,false);
if(in_version>= res_20080624)
{
//need a better version control
prevconfig.push(hdf::qmc_status,false);
prevconfig.read(ref.vParam,"vparam");
prevconfig.read(ref.iParam,"iparam");
prevconfig.read(ref.BranchMode,"branchmode");
prevconfig.push("histogram",false);
prevconfig.read(ref.EnergyHist,"energy");
prevconfig.read(ref.VarianceHist,"variance");
prevconfig.read(ref.R2Accepted,"r2accepted");
prevconfig.read(ref.R2Proposed,"r2proposed");
prevconfig.pop();
prevconfig.pop();
}
else
found_config=false;
prevconfig.pop();
}
}
#endif
myComm->bcast(found_config);
if(!found_config) return false;
bcast_state();
return true;
}
bool BranchIO::read_adios(const string& fname)
{//do not use this
#ifdef HAVE_ADIOS
if(ADIOS::getRdADIOS())
{
ADIOS::open(fname, myComm->getMPI());
/** temporary storage to broadcast restart data */
ADIOS::read(ref.vParam.data(),"vparam");
ADIOS::read(ref.iParam.data(),"iparam");
ADIOS::read(&ref.BranchMode,"branchmode");
ADIOS::read(&ref.EnergyHist,"energy");
ADIOS::read(&ref.VarianceHist,"variance");
ADIOS::read(&ref.R2Accepted,"r2accepted");
ADIOS::read(&ref.R2Proposed,"r2proposed");
ADIOS::close();
}
bcast_state();
#endif
return true;
}
void BranchIO::bcast_state()
{
int n=ref.vParam.size()+ref.iParam.size();
vector<RealType> pdata(n+1+16,-1);
if(myComm->rank()==0)
{
std::copy(ref.vParam.begin(),ref.vParam.end(),pdata.begin());
std::copy(ref.iParam.begin(),ref.iParam.end(),pdata.begin()+ref.vParam.size());
int offset=n;
pdata[offset++]=ref.BranchMode.to_ulong();
std::copy(ref.EnergyHist.properties,ref.EnergyHist.properties+4,pdata.begin()+offset);
offset+=4;
std::copy(ref.VarianceHist.properties,ref.VarianceHist.properties+4,pdata.begin()+offset);
offset+=4;
std::copy(ref.R2Accepted.properties,ref.R2Accepted.properties+4,pdata.begin()+offset);
offset+=4;
std::copy(ref.R2Proposed.properties,ref.R2Proposed.properties+4,pdata.begin()+offset);
}
//broadcast to the nodes : need to add a namespace mpi::
myComm->bcast(pdata);
if(myComm->rank())
{
int ii=0;
for(int i=0; i<ref.vParam.size(); ++i,++ii)
ref.vParam[i]=pdata[ii];
for(int i=0; i<ref.iParam.size(); ++i,++ii)
ref.iParam[i]=static_cast<int>(pdata[ii]);
ref.BranchMode=static_cast<unsigned long>(pdata[ii]);
}
{
//update historgram
int ii=n+1;
ref.EnergyHist.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
ref.VarianceHist.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
ref.R2Accepted.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
ref.R2Proposed.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
}
}
#ifdef HAVE_ADIOS
int64_t BranchIO::get_Checkpoint_size()
{
int64_t adios_groupsize = 8 \
@ -115,194 +377,7 @@ void BranchIO::adios_checkpoint_verify(ADIOS_FILE *fp)
#endif
bool BranchIO::write(const string& fname)
{
//append .config.h5 if missing
string h5name(fname);
if(fname.find("config.h5")>= fname.size())
h5name.append(".config.h5");
hdf_archive dump(myComm,false);
hid_t fid = dump.open(h5name);
//cannot find the file, return false
if(fid<0)
return false;
dump.push(hdf::main_state);
bool firsttime=!dump.is_group(hdf::qmc_status);
dump.push(hdf::qmc_status);
if(firsttime)
{
string v_header("tau:taueff:etrial:eref:branchmax:branchcutoff:branchfilter:sigma:acc_energy:acc_samples");
string i_header("warmupsteps:energyupdateinterval:counter:targetwalkers:maxwalkers:minwalkers:branchinterval");
dump.write(v_header,"vparam_def");
dump.write(i_header,"iparam_def");
}
dump.write(ref.vParam,"vparam");
dump.write(ref.iParam,"iparam");
dump.write(ref.BranchMode,"branchmode");
dump.push("histogram");
dump.write(ref.EnergyHist,"energy");
dump.write(ref.VarianceHist,"variance");
dump.write(ref.R2Accepted,"r2accepted");
dump.write(ref.R2Proposed,"r2proposed");
//PopHist is not being used in 2010-10-19
//if(ref.BranchMode[SimpleFixedNodeBranch::B_DMC])
//{
// dump.push("population");
// dump.write(ref.PopHist.myData,"histogram");
//}
return true;
}
bool BranchIO::read(const string& fname)
{
//append .config.h5 if missing
string h5name(fname);
if(fname.find("config.h5")>= fname.size())
h5name.append(".config.h5");
hdf_archive prevconfig(myComm,true);
int found_config=prevconfig.open(h5name,H5F_ACC_RDONLY);
myComm->bcast(found_config);
if(found_config==0) return false;
app_log() << "BranchIO::read from " << fname << endl;
HDFVersion res_version(0,4); //start using major=0 and minor=4
HDFVersion res_20080624(0,5);//major revision on 2008-06-24 0.5
HDFVersion in_version(0,1);
int n=ref.vParam.size()+ref.iParam.size();
/** temporary storage to broadcast restart data */
vector<RealType> pdata(n+3+16,-1);
prevconfig.read(in_version.version,hdf::version);
myComm->bcast(in_version.version);
prevconfig.push(hdf::main_state,false);
if(in_version>= res_20080624)
{
//need a better version control
prevconfig.push(hdf::qmc_status,false);
prevconfig.read(ref.vParam,"vparam");
prevconfig.read(ref.iParam,"iparam");
prevconfig.read(ref.BranchMode,"branchmode");
std::copy(ref.vParam.begin(),ref.vParam.end(),pdata.begin());
std::copy(ref.iParam.begin(),ref.iParam.end(),pdata.begin()+ref.vParam.size());
int offset=n;
pdata[offset++]=ref.BranchMode.to_ulong();
pdata[offset++]=in_version[0];
pdata[offset++]=in_version[1];
{
//get histogram
prevconfig.push("histogram",false);
accumulator_set<RealType> temp;
prevconfig.read(temp,"energy");
std::copy(temp.properties,temp.properties+4,pdata.begin()+offset);
offset+=4;
prevconfig.read(temp,"variance");
std::copy(temp.properties,temp.properties+4,pdata.begin()+offset);
offset+=4;
prevconfig.read(temp,"r2accepted");
std::copy(temp.properties,temp.properties+4,pdata.begin()+offset);
offset+=4;
prevconfig.read(temp,"r2proposed");
std::copy(temp.properties,temp.properties+4,pdata.begin()+offset);
offset+=4;
prevconfig.pop();
}
prevconfig.pop();
}
prevconfig.pop();
//broadcast to the nodes : need to add a namespace mpi::
myComm->bcast(pdata);
if(myComm->rank())
{
//\since 2008-06-24
if(in_version>=res_20080624)
{
int ii=0;
for(int i=0; i<ref.vParam.size(); ++i,++ii)
ref.vParam[i]=pdata[ii];
for(int i=0; i<ref.iParam.size(); ++i,++ii)
ref.iParam[i]=static_cast<int>(pdata[ii]);
ref.BranchMode=static_cast<unsigned long>(pdata[ii]);
}
}
{
//update historgram
int ii=n+3;
ref.EnergyHist.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
ref.VarianceHist.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
ref.R2Accepted.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
ref.R2Proposed.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
}
return true;
}
bool BranchIO::read_adios(const string& fname)
{//do not use this
#ifdef HAVE_ADIOS
if(ADIOS::getRdADIOS())
{
ADIOS::open(fname, myComm->getMPI());
int n=ref.vParam.size()+ref.iParam.size();
/** temporary storage to broadcast restart data */
vector<RealType> pdata(n+3+16,-1);
ADIOS::read(ref.vParam.data(),"vparam");
ADIOS::read(ref.iParam.data(),"iparam");
ADIOS::read(&ref.BranchMode,"branchmode");
std::copy(ref.vParam.begin(),ref.vParam.end(),pdata.begin());
std::copy(ref.iParam.begin(),ref.iParam.end(),pdata.begin()+ref.vParam.size());
int offset=n;
HDFVersion res_version(0,4); //start using major=0 and minor=4
HDFVersion res_20080624(0,5);//major revision on 2008-06-24 0.5
HDFVersion in_version(0,1);
pdata[offset++]=ref.BranchMode.to_ulong();
pdata[offset++]=in_version[0];
pdata[offset++]=in_version[1];
accumulator_set<RealType> temp;
ADIOS::read(&temp,"energy");
std::copy(temp.properties,temp.properties+4,pdata.begin()+offset);
offset+=4;
ADIOS::read(&temp,"variance");
std::copy(temp.properties,temp.properties+4,pdata.begin()+offset);
offset+=4;
ADIOS::read(&temp,"r2accepted");
std::copy(temp.properties,temp.properties+4,pdata.begin()+offset);
offset+=4;
ADIOS::read(&temp,"r2proposed");
std::copy(temp.properties,temp.properties+4,pdata.begin()+offset);
offset+=4;
myComm->bcast(pdata);
if(myComm->rank())
{
int ii=0;
for(int i=0; i<ref.vParam.size(); ++i,++ii)
ref.vParam[i]=pdata[ii];
for(int i=0; i<ref.iParam.size(); ++i,++ii)
ref.iParam[i]=static_cast<int>(pdata[ii]);
ref.BranchMode=static_cast<unsigned long>(pdata[ii]);
}
{
int ii=n+3;
ref.EnergyHist.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
ref.VarianceHist.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
ref.R2Accepted.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
ref.R2Proposed.reset(pdata[ii],pdata[ii+1],pdata[ii+2]);
ii+=4;
}
ADIOS::close();
return true;
}
#endif
return true;
}
}
/***************************************************************************

View File

@ -47,6 +47,12 @@ struct BranchIO
bool write(const string& fname);
bool read(const string& fname);
bool read_adios(const string& fname);
void bcast_state();
static vector<string> vParamName;
static vector<string> iParamName;
static void initAttributes();
};
}
#endif

View File

@ -284,27 +284,33 @@ void QMCDriver::adiosCheckpoint(int block)
{
adios_open(&adios_handle, "checkpoint_float", (getRotationName(RootName) + ".config.bp").c_str(), "w", myComm->getMPI());
}
if (myEstimator->is_manager())
{
BranchIO hh(*branchEngine,myEstimator->getCommunicator());
adios_groupsize = hh.get_Checkpoint_size();
adios_groupsize += RandomNumberControl::get_group_size();
adios_groupsize += wOut->get_group_size(W);
adios_group_size(adios_handle, adios_groupsize, &adios_totalsize);
hh.adios_checkpoint(adios_handle);
branchEngine->save_energy();
wOut->adios_checkpoint(W, adios_handle, block);
RandomNumberControl::adios_checkpoint(adios_handle);
}
else
{
adios_groupsize = RandomNumberControl::get_group_size();
adios_groupsize += wOut->get_group_size(W);
adios_group_size(adios_handle, adios_groupsize, &adios_totalsize);
wOut->adios_checkpoint(W, adios_handle, block);
RandomNumberControl::adios_checkpoint(adios_handle);
}
adios_groupsize = wOut->get_group_size(W);
adios_group_size(adios_handle, adios_groupsize, &adios_totalsize);
wOut->adios_checkpoint(W, adios_handle, block);
//if (myEstimator->is_manager())
//{
// BranchIO hh(*branchEngine,myEstimator->getCommunicator());
// adios_groupsize = hh.get_Checkpoint_size();
// adios_groupsize += RandomNumberControl::get_group_size();
// adios_groupsize += wOut->get_group_size(W);
// adios_group_size(adios_handle, adios_groupsize, &adios_totalsize);
// hh.adios_checkpoint(adios_handle);
// branchEngine->save_energy();
// wOut->adios_checkpoint(W, adios_handle, block);
// RandomNumberControl::adios_checkpoint(adios_handle);
//}
//else
//{
// adios_groupsize = RandomNumberControl::get_group_size();
// adios_groupsize += wOut->get_group_size(W);
// adios_group_size(adios_handle, adios_groupsize, &adios_totalsize);
// wOut->adios_checkpoint(W, adios_handle, block);
// RandomNumberControl::adios_checkpoint(adios_handle);
//}
adios_close(adios_handle);
#ifdef IO_PROFILE
ADIOS_PROFILE::profile_adios_size(myComm, ADIOS_PROFILE::CKPOINT, adios_groupsize, adios_totalsize);
#endif
@ -314,12 +320,12 @@ void QMCDriver::adiosCheckpoint(int block)
myComm->getMPI());
if (fp == NULL)
app_error() << "Fail to open adios file "<<(getLastRotationName(RootName) + ".config.bp").c_str()<<" Abort. "<<endl;
if (myEstimator->is_manager())
{
BranchIO hh(*branchEngine,myEstimator->getCommunicator());
hh.adios_checkpoint_verify(fp);
}
RandomNumberControl::adios_checkpoint_verify(fp);
//if (myEstimator->is_manager())
//{
// BranchIO hh(*branchEngine,myEstimator->getCommunicator());
// hh.adios_checkpoint_verify(fp);
//}
//RandomNumberControl::adios_checkpoint_verify(fp);
wOut->adios_checkpoint_verify(W, fp);
adios_read_close(fp);
#endif
@ -345,21 +351,23 @@ void QMCDriver::adiosCheckpointFinal(int block, bool dumpwalkers)
{
adios_open(&adios_handle, "checkpoint_float", (getRotationName(RootName) + ".config.bp").c_str(), "w", myComm->getMPI());
}
if (myEstimator->is_manager())
{
//Since we are in the main process we need to write out some more information
BranchIO hh(*branchEngine,myEstimator->getCommunicator());
//Get the size of the data we are writing out for qmc_status
adios_groupsize += hh.get_Checkpoint_size();
//Tell adios how much space we are using for this write out.
adios_group_size(adios_handle, adios_groupsize, &adios_totalsize);
//Checkpoint qmc status related data
branchEngine->save_energy(); //save energy_history
hh.adios_checkpoint(adios_handle);
}
else
adios_group_size(adios_handle, adios_groupsize, &adios_totalsize);
//if (myEstimator->is_manager())
//{
// //Since we are in the main process we need to write out some more information
// BranchIO hh(*branchEngine,myEstimator->getCommunicator());
// //Get the size of the data we are writing out for qmc_status
// adios_groupsize += hh.get_Checkpoint_size();
// //Tell adios how much space we are using for this write out.
// adios_group_size(adios_handle, adios_groupsize, &adios_totalsize);
// //Checkpoint qmc status related data
// branchEngine->save_energy(); //save energy_history
// hh.adios_checkpoint(adios_handle);
//}
//else
// adios_group_size(adios_handle, adios_groupsize, &adios_totalsize);
//Checkpoint the data for RandomNumber Control
adios_group_size(adios_handle, adios_groupsize, &adios_totalsize);
RandomNumberControl::adios_checkpoint(adios_handle);
if(DumpConfig && dumpwalkers)
//If we are checkpointing
@ -369,24 +377,24 @@ void QMCDriver::adiosCheckpointFinal(int block, bool dumpwalkers)
ADIOS_FILE *fp = adios_read_open_file((getLastRotationName(RootName) + ".config.bp").c_str(),
ADIOS_READ_METHOD_BP,
myComm->getMPI());
if (myEstimator->is_manager())
{
BranchIO hh(*branchEngine,myEstimator->getCommunicator());
hh.adios_checkpoint_verify(fp);
}
RandomNumberControl::adios_checkpoint_verify(fp);
//if (myEstimator->is_manager())
//{
// BranchIO hh(*branchEngine,myEstimator->getCommunicator());
// hh.adios_checkpoint_verify(fp);
//}
//RandomNumberControl::adios_checkpoint_verify(fp);
if(DumpConfig && dumpwalkers)
wOut->adios_checkpoint_verify(W, fp);
adios_read_close(fp);
#endif
if(!ADIOS::useHDF5()){
branchEngine->finalize(W);
delete wOut;
wOut=0;
nTargetWalkers = W.getActiveWalkers();
MyCounter++;
OhmmsInfo::flush();
}
//if(!ADIOS::useHDF5()){
// branchEngine->finalize(W);
// delete wOut;
// wOut=0;
// nTargetWalkers = W.getActiveWalkers();
// MyCounter++;
// OhmmsInfo::flush();
//}
#endif
}
@ -395,18 +403,9 @@ void QMCDriver::recordBlock(int block)
if(DumpConfig && block % Period4CheckPoint == 0)
{
if(ADIOS::useADIOS()) adiosCheckpoint(block);
if(ADIOS::useHDF5())
{
wOut->dump(W, block);
branchEngine->write(RootName,true); //save energy_history
//RandomNumberControl::write(RootName,myComm);
//if (storeConfigs) wOut->dump( ForwardWalkingHistory);
//save positions for optimization: this is done within VMC
//if(QMCDriverMode[QMC_OPTIMIZE]) W.saveEnsemble();
//if(Period4WalkerDump>0) wOut->append(W);
//flush the ostream
//OhmmsInfo::flush();
}
if(ADIOS::useHDF5()) wOut->dump(W, block);
branchEngine->write(RootName,true); //save energy_history
RandomNumberControl::write(RootName,myComm);
}
}
@ -414,21 +413,24 @@ bool QMCDriver::finalize(int block, bool dumpwalkers)
{
if(ADIOS::useADIOS())
adiosCheckpointFinal(block, dumpwalkers);
if(ADIOS::useHDF5())
{
TimerManager.print(myComm);
TimerManager.reset();
if(DumpConfig && dumpwalkers) wOut->dump(W, block);
branchEngine->finalize(W);
// RandomNumberControl::write(RootName,myComm);
delete wOut;
wOut=0;
//Estimators->finalize();
nTargetWalkers = W.getActiveWalkers();
MyCounter++;
OhmmsInfo::flush();
}
branchEngine->finalize(W);
if(DumpConfig) RandomNumberControl::write(RootName,myComm);
return true;
}

View File

@ -828,15 +828,6 @@ void SimpleFixedNodeBranch::read(const string& fname)
<< "\n r2accepted = " << R2Accepted.mean()
<< "\n r2proposed = " << R2Proposed.mean()
<<endl;
//char fname2[128];
//sprintf(fname2,"%s.p%03d.config",fname.c_str(),OHMMS::Controller->rank());
//ofstream fout(fname2);
//fout << " Restarting, cummulative properties:"
// << "\n energy = " << EnergyHist.mean()
// << "\n variance = " << VarianceHist.mean()
// << "\n r2accepted = " << R2Accepted.mean()
// << "\n r2proposed = " << R2Proposed.mean()
// <<endl;
}
else
{
@ -847,6 +838,16 @@ void SimpleFixedNodeBranch::read(const string& fname)
BranchMode[B_POPCONTROL]=bmode[B_POPCONTROL];
}
}
//char fname2[128];
//sprintf(fname2,"%s.p%03d.config",fname.c_str(),OHMMS::Controller->rank());
//ofstream fout(fname2);
//fout << " Restarting, cummulative properties:"
// << "\n energy = " << EnergyHist.mean()
// << "\n variance = " << VarianceHist.mean()
// << "\n r2accepted = " << R2Accepted.mean()
// << "\n r2proposed = " << R2Proposed.mean()
// <<endl;
app_log().flush();
}

View File

@ -94,5 +94,5 @@ endif()
#ADD_EXECUTABLE(time_multi time_multi_new.c)
#target_link_libraries(time_multi einspline)
#add_dependencies(time_multi ${PROJECT_BINARY_HOME}/include/einspline/bspline.h)
ADD_EXECUTABLE(test_multi_single test_multi_single.cpp)
target_link_libraries(test_multi_single einspline)
#ADD_EXECUTABLE(test_multi_single test_multi_single.cpp)
#target_link_libraries(test_multi_single einspline)

View File

@ -1611,8 +1611,12 @@ set_multi_UBspline_3d_z (multi_UBspline_3d_z* spline, int num, complex_double *d
int N = spline->num_splines;
int zs = spline->z_stride;
// First, solve in the X-direction
#pragma omp parallel
{
for (int iy=0; iy<My; iy++)
#pragma omp parallel for
{
#pragma omp for
for (int iz=0; iz<Mz; iz++) {
intptr_t doffset = 2*(iy*Mz+iz);
intptr_t coffset = 2*(iy*Nz+iz)*zs;
@ -1625,10 +1629,12 @@ set_multi_UBspline_3d_z (multi_UBspline_3d_z* spline, int num, complex_double *d
((double*)data)+doffset+1, (intptr_t)2*My*Mz,
((double*)coefs)+coffset+1, (intptr_t)2*Ny*Nz*zs);
}
}
// Now, solve in the Y-direction
for (int ix=0; ix<Nx; ix++)
#pragma omp parallel for
{
#pragma omp for
for (int iz=0; iz<Nz; iz++) {
intptr_t doffset = 2*(ix*Ny*Nz + iz)*zs;
intptr_t coffset = 2*(ix*Ny*Nz + iz)*zs;
@ -1641,10 +1647,12 @@ set_multi_UBspline_3d_z (multi_UBspline_3d_z* spline, int num, complex_double *d
((double*)coefs)+doffset+1, (intptr_t)2*Nz*zs,
((double*)coefs)+coffset+1, (intptr_t)2*Nz*zs);
}
}
// Now, solve in the Z-direction
for (int ix=0; ix<Nx; ix++)
#pragma omp parallel for
{
#pragma omp for
for (int iy=0; iy<Ny; iy++) {
intptr_t doffset = 2*((ix*Ny+iy)*Nz)*zs;
intptr_t coffset = 2*((ix*Ny+iy)*Nz)*zs;
@ -1657,6 +1665,9 @@ set_multi_UBspline_3d_z (multi_UBspline_3d_z* spline, int num, complex_double *d
((double*)coefs)+doffset+1, (intptr_t)2*zs,
((double*)coefs)+coffset+1, (intptr_t)2*zs);
}
}
}
}

View File

@ -33,8 +33,6 @@ hdf_archive::~hdf_archive()
if(access_id != H5P_DEFAULT) H5Pclose(access_id);
#endif
close();
if(xfer_plist != H5P_DEFAULT) H5Pclose(xfer_plist);
if(access_id!= H5P_DEFAULT) H5Pclose(access_id);
H5Eset_auto (err_func, client_data);
}
@ -138,5 +136,5 @@ hid_t hdf_archive::push(const std::string& gname, bool createit)
/***************************************************************************
* $RCSfile$ $Author: jnkim $
* $Revision: 894 $ $Date: 2006-02-03 10:52:38 -0600 (Fri, 03 Feb 2006) $
* $Id: hdf_file.cpp 894 2006-02-03 16:52:38Z jnkim $
* $Id: hdf_archive.cpp 894 2006-02-03 16:52:38Z jnkim $
***************************************************************************/

View File

@ -111,7 +111,7 @@ inline void scatterv(const communicator& comm, CT& in, CT& out, IV& counts, IV&
{
container_proxy<CT> t_in(in),t_out(out);
container_proxy<IV> t_counts(counts), t_displ(displ);
MPI_Datatype type_id=get_mpi_datatype(*t_in.data());
MPI_Datatype type_id=get_mpi_datatype(*t_out.data());
int ierr=MPI_Scatterv(t_in.data(),t_counts.data(),t_displ.data(),type_id
,t_out.data(),t_out.size(),type_id,dest,comm);
}
@ -124,7 +124,7 @@ template<typename CT>
inline void scatter(const communicator& comm, CT& in, CT& out, int dest=0)
{
container_proxy<CT> t_in(in),t_out(out);
MPI_Datatype type_id=get_mpi_datatype(*t_in.data());
MPI_Datatype type_id=get_mpi_datatype(*t_out.data());
int ierr=MPI_Scatter(t_in.data(),t_out.size(),type_id
,t_out.data(),t_out.size(),type_id,dest,comm);
}