Skip to content
Snippets Groups Projects
Commit 6f359846 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Fixed leaks

(cherry picked from commit 15823407)

Conflicts:
	src/tools/BiasRepresentation.cpp
parent 4bf62835
No related branches found
No related tags found
No related merge requests found
......@@ -61,6 +61,7 @@ class FilesHandler{
bool scanOneHill(BiasRepresentation *br, IFile *ifile );
void getMinMaxBin(vector<Value*> vals, Communicator &cc, vector<double> &vmin, vector<double> &vmax, vector<unsigned> &vbin);
void getMinMaxBin(vector<Value*> vals, Communicator &cc, vector<double> &vmin, vector<double> &vmax, vector<unsigned> &vbin, vector<double> &histosigma);
~FilesHandler();
};
FilesHandler::FilesHandler(const vector<string> &filenames, const bool &parallelread , Action &action , Log &mylog ):filenames(filenames),log(&mylog),parallelread(parallelread),beingread(0),isopen(false){
this->action=&action;
......@@ -73,6 +74,10 @@ FilesHandler::FilesHandler(const vector<string> &filenames, const bool &parallel
}
FilesHandler::~FilesHandler(){
for(unsigned i=0;i<ifiles.size();i++) delete ifiles[i];
}
// note that the FileHandler is completely transparent respect to the biasrepresentation
// no check are made at this level
bool FilesHandler::readBunch(BiasRepresentation *br , int stride = -1){
......@@ -226,7 +231,9 @@ parallelread(false),
negativebias(false),
nohistory(false),
beta(-1.),
fmt("%14.9f")
fmt("%14.9f"),
biasrep(NULL),
historep(NULL)
{
// format
......@@ -297,6 +304,7 @@ fmt("%14.9f")
Tools::convert(vmax[i],gmax[i]);
log<<" variable "<< getPntrToArgument(i)->getName()<<" min: "<<gmin[i]<<" max: "<<gmax[i]<<" nbin: "<<gbin[i]<<"\n";
}
delete hillsHandler;
}
// if at this stage bins are not there then do it with histo
if(gmin.size()==0){
......@@ -318,6 +326,7 @@ fmt("%14.9f")
Tools::convert(vmax[i],gmax[i]);
log<<" variable "<< getPntrToArgument(i)->getName()<<" min: "<<gmin[i]<<" max: "<<gmax[i]<<" nbin: "<<gbin[i]<<"\n";
}
delete histoHandler;
}
log<<" done!\n";
log<<" \n";
......@@ -403,6 +412,9 @@ fmt("%14.9f")
FilesHandler *hillsHandler;
FilesHandler *histoHandler;
hillsHandler=NULL;
histoHandler=NULL;
if(integratehills) hillsHandler=new FilesHandler(hillsFiles,parallelread,*this, log);
if(integratehisto) histoHandler=new FilesHandler(histoFiles,parallelread,*this, log);
......@@ -441,7 +453,7 @@ fmt("%14.9f")
smallGrid.writeToFile(gridfile);
gridfile.close();
if(!ibias)integratehills=false;// once you get to the final bunch just give up
delete Bw;
}
if(integratehisto){
......@@ -508,6 +520,8 @@ fmt("%14.9f")
nfiles++;
}
if(hillsHandler) delete hillsHandler;
if(histoHandler) delete histoHandler;
return;
}
......@@ -525,6 +539,8 @@ void FuncSumHills::calculate(){
}
FuncSumHills::~FuncSumHills(){
if(historep) delete historep;
if(biasrep) delete biasrep;
}
bool FuncSumHills::checkFilesAreExisting(const vector<string> & hills ){
......@@ -534,6 +550,7 @@ bool FuncSumHills::checkFilesAreExisting(const vector<string> & hills ){
for(unsigned i=0; i< hills.size();i++){
plumed_massert(ifile->FileExist(hills[i]),"missing file "+hills[i]);
}
delete ifile;
return true;
}
......
......@@ -34,7 +34,7 @@ An internal tool in plumed that is used to represent a bias
//+ENDPLUMEDOC
/// the constructor here
BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &cc ):hasgrid(false),mycomm(cc){
BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &cc ):hasgrid(false),mycomm(cc),BiasGrid_(NULL){
ndim=tmpvalues.size();
for(int i=0;i<ndim;i++){
values.push_back(tmpvalues[i]);
......@@ -42,7 +42,7 @@ BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &c
}
}
/// overload the constructor: add the sigma at constructor time
BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &cc, vector<double> sigma ):hasgrid(false),histosigma(sigma),mycomm(cc){
BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &cc, vector<double> sigma ):hasgrid(false),histosigma(sigma),mycomm(cc),BiasGrid_(NULL){
ndim=tmpvalues.size();
for(int i=0;i<ndim;i++){
values.push_back(tmpvalues[i]);
......@@ -50,7 +50,7 @@ BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &c
}
}
/// overload the constructor: add the grid at constructor time
BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &cc , vector<string> gmin, vector<string> gmax, vector<unsigned> nbin ):hasgrid(false), rescaledToBias(false), mycomm(cc){
BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &cc , vector<string> gmin, vector<string> gmax, vector<unsigned> nbin ):hasgrid(false), rescaledToBias(false), mycomm(cc), BiasGrid_(NULL){
ndim=tmpvalues.size();
for(int i=0;i<ndim;i++){
values.push_back(tmpvalues[i]);
......@@ -60,7 +60,7 @@ BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &c
addGrid(gmin,gmax,nbin);
}
/// overload the constructor with some external sigmas: needed for histogram
BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &cc , vector<string> gmin, vector<string> gmax, vector<unsigned> nbin , vector<double> sigma):hasgrid(false), rescaledToBias(false),histosigma(sigma),mycomm(cc){
BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &cc , vector<string> gmin, vector<string> gmax, vector<unsigned> nbin , vector<double> sigma):hasgrid(false), rescaledToBias(false),histosigma(sigma),mycomm(cc),BiasGrid_(NULL){
ndim=tmpvalues.size();
for(int i=0;i<ndim;i++){
values.push_back(tmpvalues[i]);
......@@ -70,6 +70,11 @@ BiasRepresentation::BiasRepresentation(vector<Value*> tmpvalues, Communicator &c
addGrid(gmin,gmax,nbin);
}
BiasRepresentation::~BiasRepresentation(){
if(BiasGrid_) delete BiasGrid_;
for(unsigned i=0;i<hills.size();i++) delete hills[i];
}
void BiasRepresentation::addGrid( vector<string> gmin, vector<string> gmax, vector<unsigned> nbin ){
plumed_massert(hills.size()==0,"you can set the grid before loading the hills");
plumed_massert(hasgrid==false,"to build the grid you should not having the grid in this bias representation");
......@@ -116,7 +121,7 @@ KernelFunctions* BiasRepresentation::readFromPoint(IFile *ifile){
return new KernelFunctions(cc,histosigma,"gaussian",false,h,false);
}
void BiasRepresentation::pushKernel( IFile *ifile ){
KernelFunctions *kk;
KernelFunctions *kk=NULL;
// here below the reading of the kernel is completely hidden
if(histosigma.size()==0){
ifile->allowIgnoredFields();
......
......@@ -52,6 +52,8 @@ class BiasRepresentation {
BiasRepresentation(vector<Value*> tmpvalues, Communicator &cc , vector<string> gmin, vector<string> gmax, vector<unsigned> nbin );
/// create a histogram with grid representation and sigmas in input
BiasRepresentation(vector<Value*> tmpvalues, Communicator &cc , vector<string> gmin, vector<string> gmax, vector<unsigned> nbin , vector<double> sigma);
/// destructor
~BiasRepresentation();
/// retrieve the number of dimension of the representation
unsigned getNumberOfDimensions();
/// add the grid to the representation
......@@ -91,8 +93,8 @@ class BiasRepresentation {
vector<KernelFunctions*> hills;
vector<double> biasf;
vector<double> histosigma;
Grid* BiasGrid_;
Communicator& mycomm;
Grid* BiasGrid_;
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment