From 4f353a951dd50f8aecf2d8e7756745906bdcef10 Mon Sep 17 00:00:00 2001 From: Jean-Luc Fattebert Date: Thu, 16 Jan 2025 16:31:43 -0500 Subject: [PATCH] Clean up code based on compiler warnings --- scripts/build_ubuntu22_openmpi.sh | 2 +- src/Control.cc | 17 ----------------- src/DistributedIonicData.cc | 13 ++++++------- src/HDFrestart.cc | 2 +- src/HamiltonianMVP_DMStrategy.cc | 2 +- src/IonData.cc | 17 ++++++++--------- src/Ions.cc | 6 ------ src/MGmol.cc | 2 ++ src/MVP_DMStrategy.h | 2 +- src/Potentials.cc | 3 +-- src/Potentials.h | 2 +- src/hdf_tools.cc | 30 ++++++++++++++---------------- src/mgmol_run.cc | 1 - tests/testSetGhostValues.cc | 4 ---- 14 files changed, 36 insertions(+), 67 deletions(-) diff --git a/scripts/build_ubuntu22_openmpi.sh b/scripts/build_ubuntu22_openmpi.sh index 23f510b6..474d61e5 100755 --- a/scripts/build_ubuntu22_openmpi.sh +++ b/scripts/build_ubuntu22_openmpi.sh @@ -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 diff --git a/src/Control.cc b/src/Control.cc index 2272d3cb..2c501aa9 100644 --- a/src/Control.cc +++ b/src/Control.cc @@ -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); diff --git a/src/DistributedIonicData.cc b/src/DistributedIonicData.cc index 6652c41a..05399cac 100644 --- a/src/DistributedIonicData.cc +++ b/src/DistributedIonicData.cc @@ -12,7 +12,6 @@ #include "tools.h" #include -using namespace std; DistributedIonicData::DistributedIonicData( const std::vector& local_names, @@ -31,16 +30,16 @@ DistributedIonicData::DistributedIonicData( int DistributedIonicData::pack(char* cbuff, double* dbuff) { - vector::iterator itf = data_.begin(); - double* dptr = dbuff; + std::vector::iterator itf = data_.begin(); + double* dptr = dbuff; int idx = 0; - for (vector::iterator it = ion_names_.begin(); + for (std::vector::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; @@ -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; diff --git a/src/HDFrestart.cc b/src/HDFrestart.cc index ef658955..ac856ff2 100644 --- a/src/HDFrestart.cc +++ b/src/HDFrestart.cc @@ -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) { diff --git a/src/HamiltonianMVP_DMStrategy.cc b/src/HamiltonianMVP_DMStrategy.cc index 2b5f8913..be62b894 100644 --- a/src/HamiltonianMVP_DMStrategy.cc +++ b/src/HamiltonianMVP_DMStrategy.cc @@ -57,7 +57,7 @@ HamiltonianMVP_DMStrategy void HamiltonianMVP_DMStrategy::initialize(OrbitalsType& orbitals) + OrbitalsType>::initialize(OrbitalsType&) { } diff --git a/src/IonData.cc b/src/IonData.cc index 8f62ddd8..89c1bd0c 100644 --- a/src/IonData.cc +++ b/src/IonData.cc @@ -10,12 +10,11 @@ #include "IonData.h" #include "tools.h" #include -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; @@ -52,16 +51,16 @@ void IonData::unpack(char*& cptr, int*& iptr, double*& dptr) // pack Ions data for communication void IonData::packIonData( - char* cbuff, int* ibuff, double* dbuff, vector& data) + char* cbuff, int* ibuff, double* dbuff, std::vector& data) { // pack ion_names buffer int idx = 0; - for (vector::iterator idata = data.begin(); idata != data.end(); - ++idata) + for (std::vector::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; } @@ -69,8 +68,8 @@ void IonData::packIonData( // pack integer datatypes int* iptr = &ibuff[0]; // first pack local data size - *(iptr++) = data.size(); - vector::iterator idata = data.begin(); + *(iptr++) = data.size(); + std::vector::iterator idata = data.begin(); while (idata != data.end()) { // pack atomic_num diff --git a/src/Ions.cc b/src/Ions.cc index 852151c7..008fa2ba 100644 --- a/src/Ions.cc +++ b/src/Ions.cc @@ -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 @@ -1698,9 +1697,6 @@ int Ions::readAtomsFromXYZ( int Ions::setAtoms( const std::vector& crds, const std::vector& spec) { - MGmol_MPI& mmpi(*(MGmol_MPI::instance())); - Control& ct(*(Control::instance())); - const int natoms = crds.size() / 3; double velocity[3] = { 0., 0., 0. }; @@ -1748,8 +1744,6 @@ int Ions::setAtoms( addIonToList(species_[isp], aname, &crds[3 * ia], velocity, locked); } - // std::cout<& data, std::vector& 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& data, size_t length) { @@ -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 tc; - for (std::vector::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 }; @@ -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 tc; - for (std::vector::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) { diff --git a/src/mgmol_run.cc b/src/mgmol_run.cc index e746611c..a5de1ad5 100644 --- a/src/mgmol_run.cc +++ b/src/mgmol_run.cc @@ -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) { diff --git a/tests/testSetGhostValues.cc b/tests/testSetGhostValues.cc index f8520055..c3680087 100644 --- a/tests/testSetGhostValues.cc +++ b/tests/testSetGhostValues.cc @@ -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()); @@ -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();