Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up code based on compiler warnings #299

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/build_ubuntu22_openmpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
-DMPIEXEC_PREFLAGS="--oversubscribe" \
-DMGMOL_WITH_CLANG_FORMAT=ON \
-DCMAKE_PREFIX_PATH=${HOME}/bin \
-D CMAKE_CXX_FLAGS="-Wall -pedantic -Wextra" \
-D CMAKE_CXX_FLAGS="-Wall -pedantic -Wextra -Wno-cast-function-type" \
..

# call make install
Expand Down
17 changes: 0 additions & 17 deletions src/Control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,6 @@ float Control::total_spin_ = 0.;
std::string Control::run_directory_(".");
bool Control::with_spin_ = false;

static void finishRead(std::ifstream& tfile)
{
// while( tfile.get()!='\n');
// string str;
// getline(tfile,str);
char str[256];
tfile.getline(str, 256);

char cc = (char)tfile.peek();
while (cc == ('#') || (cc == '\n') || cc == ' ')
{
while (tfile.get() != '\n')
;
cc = (char)tfile.peek(); // look at next character
}
}

Control::Control()
{
assert(comm_global_ != MPI_COMM_NULL);
Expand Down
13 changes: 6 additions & 7 deletions src/DistributedIonicData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "tools.h"

#include <string.h>
using namespace std;

DistributedIonicData::DistributedIonicData(
const std::vector<std::string>& local_names,
Expand All @@ -31,16 +30,16 @@ DistributedIonicData::DistributedIonicData(

int DistributedIonicData::pack(char* cbuff, double* dbuff)
{
vector<double>::iterator itf = data_.begin();
double* dptr = dbuff;
std::vector<double>::iterator itf = data_.begin();
double* dptr = dbuff;

int idx = 0;
for (vector<std::string>::iterator it = ion_names_.begin();
for (std::vector<std::string>::iterator it = ion_names_.begin();
it != ion_names_.end(); ++it)
{
string s(*it);
std::string s(*it);
FixedLengthString t;
strncpy(t.mystring, s.c_str(), IonData_MaxStrLength);
strncpy(t.mystring, s.c_str(), IonData_MaxStrLength - 1);
memcpy(&cbuff[idx], t.mystring, IonData_MaxStrLength);
idx += IonData_MaxStrLength;

Expand All @@ -58,7 +57,7 @@ void DistributedIonicData::unpack(char*& cptr, double*& dptr, const short ndata)
for (short i = 0; i < ndata; i++)
{
// get name
string name(cptr, IonData_MaxStrLength);
std::string name(cptr, IonData_MaxStrLength);
stripLeadingAndTrailingBlanks(name);
ion_names_.push_back(name);
cptr += IonData_MaxStrLength;
Expand Down
2 changes: 1 addition & 1 deletion src/HDFrestart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ void HDFrestart::addReleaseNumber2File(const char* release)
// if( onpe0 )
{
HDF_FixedLengthString t;
strncpy(t.mystring, release, MyHDFStrLength);
strncpy(t.mystring, release, MyHDFStrLength - 1);
herr_t status = H5Awrite(attribute_id, strtype, &t);
if (status < 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/HamiltonianMVP_DMStrategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ HamiltonianMVP_DMStrategy<MatrixType, ProjMatrixType,

template <class MatrixType, class ProjMatrixType, class OrbitalsType>
void HamiltonianMVP_DMStrategy<MatrixType, ProjMatrixType,
OrbitalsType>::initialize(OrbitalsType& orbitals)
OrbitalsType>::initialize(OrbitalsType&)
{
}

Expand Down
17 changes: 8 additions & 9 deletions src/IonData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
#include "IonData.h"
#include "tools.h"
#include <string.h>
using namespace std;

void IonData::unpack(char*& cptr, int*& iptr, double*& dptr)
{
// get name
string name(cptr, IonData_MaxStrLength);
std::string name(cptr, IonData_MaxStrLength);
stripLeadingAndTrailingBlanks(name);
ion_name = name;
cptr += IonData_MaxStrLength;
Expand Down Expand Up @@ -52,25 +51,25 @@ void IonData::unpack(char*& cptr, int*& iptr, double*& dptr)

// pack Ions data for communication
void IonData::packIonData(
char* cbuff, int* ibuff, double* dbuff, vector<IonData>& data)
char* cbuff, int* ibuff, double* dbuff, std::vector<IonData>& data)
{
// pack ion_names buffer
int idx = 0;
for (vector<IonData>::iterator idata = data.begin(); idata != data.end();
++idata)
for (std::vector<IonData>::iterator idata = data.begin();
idata != data.end(); ++idata)
{
string s = (*idata).ion_name;
std::string s = (*idata).ion_name;
FixedLengthString t;
strncpy(t.mystring, s.c_str(), IonData_MaxStrLength);
strncpy(t.mystring, s.c_str(), IonData_MaxStrLength - 1);
memcpy(&cbuff[idx], t.mystring, IonData_MaxStrLength);
idx += IonData_MaxStrLength;
}

// pack integer datatypes
int* iptr = &ibuff[0];
// first pack local data size
*(iptr++) = data.size();
vector<IonData>::iterator idata = data.begin();
*(iptr++) = data.size();
std::vector<IonData>::iterator idata = data.begin();
while (idata != data.end())
{
// pack atomic_num
Expand Down
6 changes: 0 additions & 6 deletions src/Ions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,6 @@ int Ions::readAtomsFromXYZ(
const std::string& filename, const bool cell_relative)
{
MGmol_MPI& mmpi(*(MGmol_MPI::instance()));
Control& ct(*(Control::instance()));

// set up list boundaries
// get radius of projectors
Expand Down Expand Up @@ -1698,9 +1697,6 @@ int Ions::readAtomsFromXYZ(
int Ions::setAtoms(
const std::vector<double>& crds, const std::vector<short>& spec)
{
MGmol_MPI& mmpi(*(MGmol_MPI::instance()));
Control& ct(*(Control::instance()));

const int natoms = crds.size() / 3;

double velocity[3] = { 0., 0., 0. };
Expand Down Expand Up @@ -1748,8 +1744,6 @@ int Ions::setAtoms(

addIonToList(species_[isp], aname, &crds[3 * ia], velocity, locked);
}
// std::cout<<mmpi.mype()<<"...list size = "<<list_ions_.size()<<" local
// ions size = "<<local_ions_.size()<<endl;

return natoms;
}
Expand Down
2 changes: 2 additions & 0 deletions src/MGmol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,8 @@ double MGmol<OrbitalsType>::evaluateDMandEnergyAndForces(Orbitals* orbitals,

force(*dorbitals, *ions_);

ions_->getForces(forces);

return eks;
}

Expand Down
2 changes: 1 addition & 1 deletion src/MVP_DMStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MVP_DMStrategy : public DMStrategy<OrbitalsType>
const std::vector<std::vector<int>>& overlappingGids,
ProjectedMatricesInterface* proj_matrices, const bool use_old_dm);

void initialize(OrbitalsType& orbitals) override{};
void initialize(OrbitalsType&) override{};
int update(OrbitalsType& orbitals) override;

// H is updated with MVP loop, so no need to compute it outside
Expand Down
3 changes: 1 addition & 2 deletions src/Potentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ Potentials::~Potentials()
#endif
}

Potentials::Potentials(const bool vh_frozen)
Potentials::Potentials()
{
//(*MPIdata::sout)<<"Potentials::setup()"<<endl;
diel_ = false; // default: no dielectric
itindex_vxc_ = -1;
itindex_vh_ = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/Potentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Potentials
const Vector3D& position, const Species& sp);

public:
Potentials(const bool vh_frozen = false);
Potentials();

~Potentials();

Expand Down
30 changes: 14 additions & 16 deletions src/hdf_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@

namespace mgmol_tools
{
void string2fixedlength(
std::vector<std::string>& data, std::vector<FixedLengthString>& tc)
{
tc.clear();
for (auto& d : data)
{
FixedLengthString t;
strncpy(t.mystring, d.c_str(), IonData_MaxStrLength - 1);
tc.push_back(t);
}
}

void write1d(hid_t file_id, const std::string& datasetname,
std::vector<int>& data, size_t length)
{
Expand Down Expand Up @@ -235,14 +247,7 @@ void write2d(hid_t file_id, const std::string& datasetname,

// First copy the contents of the vector into a temporary container
std::vector<FixedLengthString> tc;
for (std::vector<std::string>::const_iterator i = data.begin(),
end = data.end();
i != end; ++i)
{
FixedLengthString t;
strncpy(t.mystring, i->c_str(), IonData_MaxStrLength);
tc.push_back(t);
}
string2fixedlength(data, tc);

std::string attname("String_Length");
hsize_t dimsA[1] = { 1 };
Expand Down Expand Up @@ -583,14 +588,7 @@ void parallelWrite2d(hid_t file_id, const std::string& datasetname,

// First copy the contents of the vector into a temporary container
std::vector<FixedLengthString> tc;
for (std::vector<std::string>::const_iterator i = data.begin(),
end = data.end();
i != end; ++i)
{
FixedLengthString t;
strncpy(t.mystring, i->c_str(), IonData_MaxStrLength);
tc.push_back(t);
}
string2fixedlength(data, tc);
status = H5Dwrite(dset_id, strtype, memspace, filespace, plist_id, &tc[0]);
if (status < 0)
{
Expand Down
1 change: 0 additions & 1 deletion src/mgmol_run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ int mgmol_check()
Control& ct = *(Control::instance());
Mesh* mymesh = Mesh::instance();
const pb::PEenv& myPEenv = mymesh->peenv();
MGmol_MPI& mmpi = *(MGmol_MPI::instance());

if (myPEenv.color() > 0)
{
Expand Down
4 changes: 0 additions & 4 deletions tests/testSetGhostValues.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ TEST_CASE("Set ghost values", "[set ghosts")
const double ll = 1.;
const double lattice[3] = { ll, ll, ll };

const int nfunc = 10;

MGmol_MPI::setup(MPI_COMM_WORLD, std::cout);

MGmol_MPI& mmpi = *(MGmol_MPI::instance());
Expand Down Expand Up @@ -101,8 +99,6 @@ TEST_CASE("Set ghost values", "[set ghosts")
gf.assign(inner_data.data(), 'd');
gf.set_updated_boundaries(false);

double norm_before = gf.norm2();

// fill ghost values
const bool direction[3] = { true, true, true };
gf.defaultTrade_boundaries();
Expand Down