Skip to content

Commit

Permalink
Merge pull request QMCPACK#3489 from prckent/ppconvertcmakeclean
Browse files Browse the repository at this point in the history
Fix ppconvert memory bugs and enable in testing
  • Loading branch information
ye-luo authored Oct 1, 2021
2 parents 91fa888 + 4042431 commit 4b9b609
Show file tree
Hide file tree
Showing 20 changed files with 56 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ make -j 8
and use float and double for CUDA base and full precision.
ENABLE_CUDA ON/OFF(default). Enable CUDA code path for NVIDIA GPU acceleration.
Production quality for AFQMC. Pre-production quality for real-space.
Use CUDA_ARCH, default sm_70, to set the actual GPU architecture.
Use CMAKE_CUDA_ARCHITECTURES, default 70, to set the actual GPU architecture.
ENABLE_OFFLOAD ON/OFF(default). Experimental feature. Enable OpenMP target offload for GPU acceleration.
ENABLE_TIMERS ON(default)/OFF. Enable fine-grained timers. Timers are on by default but at level coarse
to avoid potential slowdown in tiny systems.
Expand Down
6 changes: 3 additions & 3 deletions src/QMCTools/ppconvert/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ add_subdirectory(common)

target_sources(
ppconvert
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/CubicSpline.cc" "${CMAKE_CURRENT_SOURCE_DIR}/ParseCommand.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/XMLWriterClass2.cc" "${CMAKE_CURRENT_SOURCE_DIR}/NLPPClass.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/ParserClass.cc")
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/CubicSpline.cc" "${CMAKE_CURRENT_SOURCE_DIR}/ParseCommand.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/XMLWriterClass2.cc" "${CMAKE_CURRENT_SOURCE_DIR}/NLPPClass.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/ParserClass.cc")

target_link_libraries(ppconvert common platform_LA)
2 changes: 1 addition & 1 deletion src/QMCTools/ppconvert/src/NLPPClass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ PseudoClass::CalcProjector(std::string refstate, int lchannel)
atom.RadialWFs(i).Energy = -0.5;
}
// Define a grid for solving
OptimalGrid *grid = new OptimalGrid(PseudoCharge, PotentialGrid.End());
std::shared_ptr<Grid> grid = std::make_shared<OptimalGrid>(PseudoCharge, PotentialGrid.End());
atom.SetGrid (grid);
// Set the potential
atom.SetBarePot (this);
Expand Down
10 changes: 5 additions & 5 deletions src/QMCTools/ppconvert/src/XMLWriterClass2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ XMLWriterClass::StartElement(std::string name)
{
int level = Elements.size();

XMLElement* elem = new XMLElement(name, level);
auto elem = std::make_shared<XMLElement>(name, level);
if (level > 0)
Elements.back()->AddElement (elem);
Elements.push_back(elem);
Expand All @@ -175,7 +175,7 @@ XMLWriterClass::FullEndElement()
bool
XMLWriterClass::WriteAttribute (std::string name, std::string content)
{
XMLAttribute *attr = new XMLAttribute (name, content);
auto attr = std::make_shared<XMLAttribute>(name, content);
Elements.back()->AddAttribute (attr);
return true;
}
Expand All @@ -189,7 +189,7 @@ XMLWriterClass::WriteAttribute (std::string name, double val, bool scientific)
content << std::setprecision(14);
}
content << val;
XMLAttribute *attr = new XMLAttribute (name, content.str());
auto attr = std::make_shared<XMLAttribute>(name, content.str());
Elements.back()->AddAttribute (attr);
return true;
}
Expand All @@ -199,7 +199,7 @@ XMLWriterClass::WriteAttribute (std::string name, int val)
{
std::stringstream content;
content << val;
XMLAttribute *attr = new XMLAttribute (name, content.str());
auto attr = std::make_shared<XMLAttribute>(name, content.str());
Elements.back()->AddAttribute (attr);
return true;
}
Expand All @@ -223,7 +223,7 @@ bool
XMLWriterClass::WriteElement (std::string name, std::vector<double> data)
{
int level = Elements.size();
XMLElement *elem = new XMLElement (name, level);
auto elem = std::make_shared<XMLElement>(name, level);
elem->AddContent (data);
if (level > 0)
Elements.back()->AddElement (elem);
Expand Down
11 changes: 6 additions & 5 deletions src/QMCTools/ppconvert/src/XMLWriterClass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <memory> // std::shared_ptr


class XMLAttribute
Expand All @@ -38,8 +39,8 @@ class XMLAttribute

class XMLElement
{
std::vector<XMLAttribute*> Attributes;
std::vector<XMLElement*> Children;
std::vector<std::shared_ptr<XMLAttribute>> Attributes;
std::vector<std::shared_ptr<XMLElement>> Children;
std::string Name, Content;
int Level;
void Indent(std::ostream& out);
Expand All @@ -49,9 +50,9 @@ class XMLElement

inline int GetLevel() { return Level; }

void AddElement(XMLElement* elem) { Children.push_back(elem); }
void AddElement(std::shared_ptr<XMLElement>& elem) { Children.push_back(elem); }

void AddAttribute(XMLAttribute* attr) { Attributes.push_back(attr); }
void AddAttribute(std::shared_ptr<XMLAttribute>& attr) { Attributes.push_back(attr); }

void AddContent(std::string content) { Content += content; }

Expand All @@ -70,7 +71,7 @@ class XMLElement
class XMLWriterClass
{
private:
std::vector<XMLElement*> Elements;
std::vector<std::shared_ptr<XMLElement>> Elements;
void Write();
std::ofstream Out;

Expand Down
8 changes: 5 additions & 3 deletions src/QMCTools/ppconvert/src/common/AtomBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "RadialWF.h"

#include <memory> // std::shared_ptr

typedef enum
{
DFTType,
Expand All @@ -28,7 +30,7 @@ typedef enum
class Atom
{
protected:
Grid* grid;
std::shared_ptr<Grid> grid;

public:
Array<RadialWF, 1> RadialWFs;
Expand All @@ -38,8 +40,8 @@ class Atom
virtual void Solve() = 0;
virtual void Write(IOSectionClass& out) = 0;
virtual void Read(IOSectionClass& in) = 0;
virtual void SetGrid(Grid* newGrid) = 0;
inline Grid* GetGrid() { return grid; }
virtual void SetGrid(std::shared_ptr<Grid>& newGrid) = 0;
inline Grid* GetGrid() { return grid.get(); }
inline double NumElecs();
virtual void SetBarePot(Potential* pot) = 0;
};
Expand Down
5 changes: 1 addition & 4 deletions src/QMCTools/ppconvert/src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_library(common EXCLUDE_FROM_ALL "")

target_sources(
common
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/GKIntegration.cc
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/GKIntegration.cc
${CMAKE_CURRENT_SOURCE_DIR}/CoulombPot.cc
${CMAKE_CURRENT_SOURCE_DIR}/NLPP.cc
${CMAKE_CURRENT_SOURCE_DIR}/DFTAtom.cc
Expand All @@ -19,6 +19,3 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/PotentialBase.cc
${CMAKE_CURRENT_SOURCE_DIR}/IOASCII.cc
${CMAKE_CURRENT_SOURCE_DIR}/Functionals.cc)

target_include_directories(common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/blitz
${CMAKE_CURRENT_SOURCE_DIR}/blitz/array)
10 changes: 5 additions & 5 deletions src/QMCTools/ppconvert/src/common/CubicSplineCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CubicSplineCommon

public:
int NumParams;
Grid* grid;
std::shared_ptr<Grid> grid;
/// The values of the derivative of the represented function on the
/// boundary. If each value is greater that 1e30, we compute
/// boundary conditions assuming that the second derivative is zero at
Expand All @@ -61,7 +61,7 @@ class CubicSplineCommon

/// Initialize the cubic spline. See notes about start and end
/// deriv above.
inline void Init(Grid* NewGrid, Array<double, 1> NewYs, double startderiv, double endderiv)
inline void Init(std::shared_ptr<Grid>& NewGrid, Array<double, 1> NewYs, double startderiv, double endderiv)
{
StartDeriv = startderiv;
EndDeriv = endderiv;
Expand All @@ -82,17 +82,17 @@ class CubicSplineCommon

/// Simplified form which assumes that the second derivative at both
/// boundaries are zero.
inline void Init(Grid* NewGrid, Array<double, 1> NewYs) { Init(NewGrid, NewYs, 5.0e30, 5.0e30); }
inline void Init(std::shared_ptr<Grid>& NewGrid, Array<double, 1> NewYs) { Init(NewGrid, NewYs, 5.0e30, 5.0e30); }

/// Simplified constructor.
inline CubicSplineCommon(Grid* NewGrid, Array<double, 1> NewYs)
inline CubicSplineCommon(std::shared_ptr<Grid>& NewGrid, Array<double, 1> NewYs)
{
StartDeriv = EndDeriv = 5.0e30;
Init(NewGrid, NewYs, 5.0e30, 5.0e30);
}

/// Full constructor.
inline CubicSplineCommon(Grid* NewGrid, Array<double, 1> NewYs, double startderiv, double endderiv)
inline CubicSplineCommon(std::shared_ptr<Grid>& NewGrid, Array<double, 1> NewYs, double startderiv, double endderiv)
{
Init(NewGrid, NewYs, startderiv, endderiv);
Update();
Expand Down
2 changes: 1 addition & 1 deletion src/QMCTools/ppconvert/src/common/DFTAtom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void DFTAtom::UpdateExCorr()
}


void DFTAtom::SetGrid(Grid *newgrid)
void DFTAtom::SetGrid(std::shared_ptr<Grid>& newgrid)
{
grid = newgrid;
int N = grid->NumPoints;
Expand Down
2 changes: 1 addition & 1 deletion src/QMCTools/ppconvert/src/common/DFTAtom.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DFTAtom : public Atom
double SolveIter();
void Write(IOSectionClass& out) override;
void Read(IOSectionClass& in) override;
void SetGrid(Grid* newGrid) override;
void SetGrid(std::shared_ptr<Grid>& newGrid) override;
void SetBarePot(Potential* pot) override;

inline double rho(double r) { return ChargeDensity(r); }
Expand Down
6 changes: 0 additions & 6 deletions src/QMCTools/ppconvert/src/common/GeneralPot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,3 @@ GeneralPot::GeneralPot() : PotGrid(NULL)
{

}

GeneralPot::~GeneralPot()
{
if (PotGrid != NULL)
delete PotGrid;
}
4 changes: 2 additions & 2 deletions src/QMCTools/ppconvert/src/common/GeneralPot.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class GeneralPot : public Potential
{
protected:
Grid* PotGrid;
std::shared_ptr<Grid> PotGrid;
CubicSplineCommon PotSpline;
double Z;

Expand All @@ -34,7 +34,7 @@ class GeneralPot : public Potential
void Write(IOSectionClass& out) override;
void Read(IOSectionClass& in) override;
GeneralPot();
~GeneralPot();
~GeneralPot() = default;
};

#endif
18 changes: 9 additions & 9 deletions src/QMCTools/ppconvert/src/common/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,31 +630,31 @@ class ClusterGrid : public Grid
};


inline Grid* ReadGrid(IOSectionClass& inSection)
inline std::shared_ptr<Grid> ReadGrid(IOSectionClass& inSection)
{
std::string Type;
assert(inSection.ReadVar("Type", Type));

Grid* newGrid;
std::shared_ptr<Grid> newGrid;
if (Type == "Linear")
newGrid = new LinearGrid;
newGrid = std::make_shared<LinearGrid>();
else if (Type == "General")
newGrid = new GeneralGrid;
newGrid = std::make_shared<GeneralGrid>();
else if (Type == "Optimal")
newGrid = new OptimalGrid;
newGrid = std::make_shared<OptimalGrid>();
else if (Type == "Optimal2")
newGrid = new OptimalGrid2;
newGrid = std::make_shared<OptimalGrid2>();
else if (Type == "Log")
newGrid = new LogGrid;
newGrid = std::make_shared<LogGrid>();
else if (Type == "Cluster")
newGrid = new ClusterGrid;
newGrid = std::make_shared<ClusterGrid>();
else
{
std::cerr << "Unrecognized Grid type " << Type << "\n";
exit(1);
}
newGrid->Read(inSection);
return (newGrid);
return newGrid;
}


Expand Down
11 changes: 6 additions & 5 deletions src/QMCTools/ppconvert/src/common/NLPP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ NLPPClass::IsNonlocal()
}

void
ChannelPotential::Read(IOSectionClass &in, Grid *grid)
ChannelPotential::Read(IOSectionClass &in, std::shared_ptr<Grid>& grid)
{
assert (in.ReadVar("l", l));
assert (in.ReadVar("n_principal", n_principal));
Expand Down Expand Up @@ -232,7 +232,7 @@ ChannelPotential::SetupProjector (double G_max, double G_FFT)
zeta(0) = ProjectorNorm * DeltaV(0)*u(1.0e-8)*1.0e8;
for (int i=1; i<grid.NumPoints; i++)
zeta(i) = ProjectorNorm * DeltaV(i)*u(i)/grid(i);
zeta_r.Init (&grid, zeta);
zeta_r.Init (u.grid, zeta);

// Compute zeta(q)
Job = ZETA_Q;
Expand All @@ -242,15 +242,16 @@ ChannelPotential::SetupProjector (double G_max, double G_FFT)
qCurrent = qGrid(i);
zeta(i) = integrator.Integrate(0.0, grid.End, 1.0e-12);
}
zeta_q.Init (&qGrid, zeta);
std::shared_ptr<Grid> qGridSharedPtr(&qGrid);
zeta_q.Init (qGridSharedPtr, zeta);


double gamma = G_FFT - G_max;
// Zero out zeta_q above gamma;
Array<double,1> chi_q_data(qGrid.NumPoints);
for (int i=0; i<qGrid.NumPoints; i++)
chi_q_data(i) = (qGrid(i) >= gamma) ? 0.0 : zeta_q(i);
chi_q.Init (&qGrid, chi_q_data);
chi_q.Init (qGridSharedPtr, chi_q_data);

// Now for the magic: We adjust chi_q between G_max and gamma so
// that the real-space oscillations outside R0 are damped out
Expand Down Expand Up @@ -316,7 +317,7 @@ ChannelPotential::SetupProjector (double G_max, double G_FFT)
rCurrent = grid(i);
chi_r_data(i) = integrator.Integrate(0.0, gamma, 1.0e-10);
}
chi_r.Init (&grid, chi_r_data);
chi_r.Init (u.grid, chi_r_data);

// Finally, check to see if chi_r is small outside R0
Job = CHECK_CHI_R;
Expand Down
4 changes: 2 additions & 2 deletions src/QMCTools/ppconvert/src/common/NLPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ChannelPotential
inline double operator()(double x);

void SetupProjector(double G_max, double G_FFT);
void Read(IOSectionClass& in, Grid* grid);
void Read(IOSectionClass& in, std::shared_ptr<Grid>& grid);
void Write(IOSectionClass& out);
};

Expand All @@ -77,7 +77,7 @@ class NLPPClass : public Potential
double Zion;
int AtomicNumber;
std::string Symbol;
Grid* PotentialGrid;
std::shared_ptr<Grid> PotentialGrid;

public:
// General accessor functions
Expand Down
1 change: 1 addition & 0 deletions src/QMCTools/ppconvert/src/common/PotentialBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using namespace IO;
class Potential
{
public:
virtual ~Potential() = default;
// Optional member functions -- if you're not a pseudoHamiltonian,
// you do not need to define these
virtual bool IsPH();
Expand Down
2 changes: 1 addition & 1 deletion src/QMCTools/ppconvert/src/common/RadialWF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ RadialWF::CountNodes()
}

void
RadialWF::SetGrid(Grid *newgrid)
RadialWF::SetGrid(std::shared_ptr<Grid>& newgrid)
{
grid = newgrid;
int N = grid->NumPoints;
Expand Down
4 changes: 2 additions & 2 deletions src/QMCTools/ppconvert/src/common/RadialWF.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RadialWF
Potential* pot;

public:
Grid* grid;
std::shared_ptr<Grid> grid;
CubicSplineCommon u, dudr;
int n, l, CoreNodes;
double Energy, Occupancy, Weight;
Expand All @@ -49,7 +49,7 @@ class RadialWF
double LogDerivative();
void Solve(double tolerance = 1.0e-8);
void Normalize();
void SetGrid(Grid* newgrid);
void SetGrid(std::shared_ptr<Grid>& newgrid);
void SetPotential(Potential* newPot);
Potential* GetPotential();
void Write(IOSectionClass& out);
Expand Down
2 changes: 1 addition & 1 deletion src/QMCTools/ppconvert/src/common/SplinePot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ double SplinePot::d2Vdr2(double r)
void SplinePot::Read(IOSectionClass &in)
{
assert(in.OpenSection("Grid"));
Grid *grid = ReadGrid(in);
auto grid = ReadGrid(in);
in.CloseSection(); // "Grid"
Array<double,1> data;
assert(in.ReadVar("SplineData", data));
Expand Down
Loading

0 comments on commit 4b9b609

Please sign in to comment.