From 2919a87c98ab73219a8ec7b43808ff50b6467f47 Mon Sep 17 00:00:00 2001 From: Tom Epperly Date: Mon, 2 Oct 2023 07:08:36 -0700 Subject: [PATCH] Make compile -Wall/-Werror proof (#653) * Try resolving issues discovered with -Wall -Werror * Remove unused private data members, resolve overridden virtual functions * try to fix the CI tests on github (#654) * try to fix the CI tests on github * try to fix the CI tests on github * add deepcheck * pass quartz CI * build on lassen * remove some unused var * fix PNNL CI v1 * try to fix ginkgo issue * create branch, switch to cpp14 (#661) * rebase and fix issues introduced by rebase --------- Co-authored-by: Nai-Yuan Chiang Co-authored-by: nychiang --- CMakeLists.txt | 1 + src/Drivers/Dense/NlpDenseConsEx1.cpp | 30 ++++--- src/Drivers/Dense/NlpDenseConsEx1.hpp | 8 +- src/Drivers/Dense/NlpDenseConsEx1Driver.cpp | 3 +- src/Drivers/Dense/NlpDenseConsEx2.cpp | 6 +- src/Drivers/Dense/NlpDenseConsEx2.hpp | 2 + src/Drivers/Dense/NlpDenseConsEx3.hpp | 5 +- src/Drivers/Dense/NlpDenseConsEx4.cpp | 8 +- src/Drivers/Dense/NlpDenseConsEx4.hpp | 2 + src/Drivers/MDS/NlpMdsEx1Driver.cpp | 2 +- src/Drivers/MDS/NlpMdsEx2Driver.cpp | 2 +- src/Drivers/MDS/NlpMdsRajaEx1.cpp | 4 +- src/Drivers/MDS/hpc_multisolves.cpp | 2 +- src/Drivers/PriDec/NlpPriDecEx1.cpp | 12 +-- src/Drivers/PriDec/NlpPriDecEx1.hpp | 16 ++-- src/Drivers/PriDec/NlpPriDecEx2.cpp | 18 +++-- src/Drivers/PriDec/NlpPriDecEx2.hpp | 20 ++--- src/Drivers/PriDec/NlpPriDecEx2Sparse.cpp | 16 ++-- src/Drivers/PriDec/NlpPriDecEx2Sparse.hpp | 20 ++--- src/Drivers/PriDec/NlpPriDecEx2SparseRaja.cpp | 10 +-- src/Drivers/PriDec/NlpPriDecEx2SparseRaja.hpp | 20 ++--- .../PriDec/NlpPriDecEx2UserBasecase.hpp | 1 + .../PriDec/NlpPriDecEx2UserRecourseMds.hpp | 7 +- .../PriDec/NlpPriDecEx2UserRecourseSparse.hpp | 8 +- .../NlpPriDecEx2UserRecourseSparseRaja.hpp | 10 +-- src/Drivers/PriDec/NlpPriDecEx3Sparse.hpp | 52 +++++++----- src/Drivers/Sparse/NlpSparseEx2.cpp | 42 +++++----- src/Drivers/Sparse/NlpSparseEx2.hpp | 7 +- src/Interface/chiopInterface.cpp | 3 +- src/Interface/hiopInterfacePrimalDecomp.hpp | 10 +-- src/LinAlg/hiopLinSolverSparseGinkgo.cpp | 17 ++-- src/LinAlg/hiopLinSolverSymDenseLapack.hpp | 3 +- src/LinAlg/hiopLinSolverSymDenseMagma.cpp | 4 - src/LinAlg/hiopLinSolverSymSparseMA57.cpp | 7 +- src/LinAlg/hiopLinSolverUMFPACKZ.cpp | 6 +- src/LinAlg/hiopMatrixDenseRajaImpl.hpp | 3 - src/LinAlg/hiopMatrixDenseRowMajor.cpp | 3 - src/LinAlg/hiopMatrixMDS.hpp | 1 - src/LinAlg/hiopMatrixRajaSparseTriplet.hpp | 4 +- .../hiopMatrixRajaSparseTripletImpl.hpp | 33 +++----- src/LinAlg/hiopMatrixSparseCSRSeq.cpp | 14 +--- src/LinAlg/hiopMatrixSparseCsrCuda.cpp | 8 -- src/LinAlg/hiopMatrixSparseTriplet.cpp | 18 +---- src/LinAlg/hiopVectorCompoundPD.cpp | 11 +-- src/LinAlg/hiopVectorCuda.cpp | 4 +- src/LinAlg/hiopVectorHip.cpp | 4 +- src/LinAlg/hiopVectorPar.cpp | 1 - src/LinAlg/hiopVectorRajaImpl.hpp | 4 +- src/Optimization/hiopAlgFilterIPM.cpp | 34 ++++---- src/Optimization/hiopAlgPrimalDecomp.cpp | 80 +++++++------------ src/Optimization/hiopAlgPrimalDecomp.hpp | 4 - src/Optimization/hiopDualsUpdater.cpp | 7 +- src/Optimization/hiopFRProb.cpp | 13 +-- src/Optimization/hiopHessianLowRank.cpp | 34 ++++---- src/Optimization/hiopKKTLinSys.cpp | 29 +++---- src/Optimization/hiopKKTLinSys.hpp | 2 +- src/Optimization/hiopKKTLinSysMDS.cpp | 17 ++-- src/Optimization/hiopKKTLinSysSparse.cpp | 1 - .../hiopKKTLinSysSparseCondensed.cpp | 13 +-- .../hiopKKTLinSysSparseNormalEqn.cpp | 16 ++-- src/Optimization/hiopNlpFormulation.cpp | 25 ++---- src/Optimization/hiopNlpFormulation.hpp | 4 +- src/Optimization/hiopNlpTransforms.cpp | 39 ++++----- src/Optimization/hiopPDPerturbation.hpp | 38 ++++----- src/Utils/hiopCSR_IO.hpp | 32 +++++--- src/Utils/hiopKronReduction.cpp | 4 +- src/Utils/hiopOptions.cpp | 8 +- src/Utils/hiopRunStats.hpp | 6 +- tests/LinAlg/matrixTestsDense.hpp | 8 -- tests/LinAlg/matrixTestsDenseRowMajor.cpp | 3 +- tests/LinAlg/matrixTestsSparse.hpp | 33 +------- tests/LinAlg/matrixTestsSparseTriplet.cpp | 1 - tests/LinAlg/matrixTestsSymSparse.hpp | 7 +- tests/LinAlg/vectorTests.hpp | 1 - tests/LinAlg/vectorTestsInt.hpp | 1 - tests/test_bicgstab.cpp | 14 ++-- tests/test_pcg.cpp | 17 ++-- 77 files changed, 442 insertions(+), 541 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed9fee305..9e34ab785 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_CUDA_SEPARABLE_COMPILATION ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_CXX_FLAGS "-Wall -Werror") if (POLICY CMP0074) cmake_policy(SET CMP0074 NEW) diff --git a/src/Drivers/Dense/NlpDenseConsEx1.cpp b/src/Drivers/Dense/NlpDenseConsEx1.cpp index 5a4b30ef3..df97ee21e 100644 --- a/src/Drivers/Dense/NlpDenseConsEx1.cpp +++ b/src/Drivers/Dense/NlpDenseConsEx1.cpp @@ -106,23 +106,29 @@ DiscretizedFunction::DiscretizedFunction(Ex1Meshing1D* meshing) } // u'*v = u'*M*v, where u is 'this' -double DiscretizedFunction::dotProductWith( const DiscretizedFunction& v_ ) const +double DiscretizedFunction::dotProductWith( const hiopVector& v_ ) const { - assert(v_._mesh->matches(this->_mesh)); - double* M=_mesh->_mass->local_data(); - double* u= this->data_; - double* v= v_.data_; + auto discretizedFunction(dynamic_cast(&v_)); + if (discretizedFunction) { + assert(discretizedFunction->_mesh->matches(this->_mesh)); + double* M=_mesh->_mass->local_data(); + double* u= this->data_; + double* v= discretizedFunction->data_; - double dot=0.; - for(int i=0; i DenseConsEx2::DenseConsEx2(int n, bool unconstrained) - : unconstrained_(unconstrained), - n_vars_(n), + : n_vars_(n), n_cons_(4), - comm(MPI_COMM_WORLD) + unconstrained_(unconstrained) { comm_size = 1; my_rank = 0; #ifdef HIOP_USE_MPI + comm = MPI_COMM_WORLD; int ierr = MPI_Comm_size(comm, &comm_size); assert(MPI_SUCCESS==ierr); ierr = MPI_Comm_rank(comm, &my_rank); assert(MPI_SUCCESS==ierr); #endif diff --git a/src/Drivers/Dense/NlpDenseConsEx2.hpp b/src/Drivers/Dense/NlpDenseConsEx2.hpp index 0006a8d76..b9761013c 100644 --- a/src/Drivers/Dense/NlpDenseConsEx2.hpp +++ b/src/Drivers/Dense/NlpDenseConsEx2.hpp @@ -90,7 +90,9 @@ class DenseConsEx2 : public hiop::hiopInterfaceDenseConstraints */ private: size_type n_vars_, n_cons_; +#ifdef HIOP_USE_MPI MPI_Comm comm; +#endif int my_rank; int comm_size; index_type* col_partition_; diff --git a/src/Drivers/Dense/NlpDenseConsEx3.hpp b/src/Drivers/Dense/NlpDenseConsEx3.hpp index d912db52d..d539c5c77 100644 --- a/src/Drivers/Dense/NlpDenseConsEx3.hpp +++ b/src/Drivers/Dense/NlpDenseConsEx3.hpp @@ -33,10 +33,11 @@ class DenseConsEx3 : public hiop::hiopInterfaceDenseConstraints { public: DenseConsEx3(int n) - : n_vars(n), n_cons(2), comm(MPI_COMM_WORLD) + : n_vars(n), n_cons(2) { comm_size=1; my_rank=0; #ifdef HIOP_USE_MPI + comm = MPI_COMM_WORLD; int ierr = MPI_Comm_size(comm, &comm_size); assert(MPI_SUCCESS==ierr); ierr = MPI_Comm_rank(comm, &my_rank); assert(MPI_SUCCESS==ierr); #endif @@ -226,7 +227,9 @@ class DenseConsEx3 : public hiop::hiopInterfaceDenseConstraints private: int n_vars, n_cons; +#ifdef HIOP_USE_MPI MPI_Comm comm; +#endif int my_rank, comm_size; index_type* col_partition; public: diff --git a/src/Drivers/Dense/NlpDenseConsEx4.cpp b/src/Drivers/Dense/NlpDenseConsEx4.cpp index 6e3933f1f..bcca2e40a 100644 --- a/src/Drivers/Dense/NlpDenseConsEx4.cpp +++ b/src/Drivers/Dense/NlpDenseConsEx4.cpp @@ -5,14 +5,14 @@ #include DenseConsEx4::DenseConsEx4() - : unconstrained_(false), - n_vars_(2), + : n_vars_(2), n_cons_(4), - comm(MPI_COMM_WORLD) + unconstrained_(false) { comm_size = 1; my_rank = 0; #ifdef HIOP_USE_MPI + comm = MPI_COMM_WORLD; int ierr = MPI_Comm_size(comm, &comm_size); assert(MPI_SUCCESS==ierr); ierr = MPI_Comm_rank(comm, &my_rank); assert(MPI_SUCCESS==ierr); #endif @@ -96,7 +96,6 @@ bool DenseConsEx4::get_cons_info(const size_type& m, double* clow, double* cupp, bool DenseConsEx4::eval_f(const size_type& n, const double* x, bool new_x, double& obj_value) { - size_type n_local = col_partition_[my_rank+1] - col_partition_[my_rank]; obj_value = 0.; index_type i_local; @@ -247,7 +246,6 @@ bool DenseConsEx4::eval_Jac_cons(const size_type& n, assert(n==n_vars_); assert(m==n_cons_); size_type n_local = col_partition_[my_rank+1] - col_partition_[my_rank]; - int i; //here we will iterate over the local indexes, however we still need to work with the //global indexes to correctly determine the entries in the Jacobian corresponding //to the 'rebels' variables x_1, x_2, x_3 diff --git a/src/Drivers/Dense/NlpDenseConsEx4.hpp b/src/Drivers/Dense/NlpDenseConsEx4.hpp index 451bf467c..e9cc78628 100644 --- a/src/Drivers/Dense/NlpDenseConsEx4.hpp +++ b/src/Drivers/Dense/NlpDenseConsEx4.hpp @@ -87,7 +87,9 @@ class DenseConsEx4 : public hiop::hiopInterfaceDenseConstraints */ private: size_type n_vars_, n_cons_; +#ifdef HIOP_USE_MPI MPI_Comm comm; +#endif int my_rank; int comm_size; index_type* col_partition_; diff --git a/src/Drivers/MDS/NlpMdsEx1Driver.cpp b/src/Drivers/MDS/NlpMdsEx1Driver.cpp index 1fe7a64fd..d03499ce3 100644 --- a/src/Drivers/MDS/NlpMdsEx1Driver.cpp +++ b/src/Drivers/MDS/NlpMdsEx1Driver.cpp @@ -11,7 +11,7 @@ using namespace hiop; -static bool self_check(size_type n, double obj_value); +// static bool self_check(size_type n, double obj_value); static bool parse_arguments(int argc, char **argv, bool& self_check, diff --git a/src/Drivers/MDS/NlpMdsEx2Driver.cpp b/src/Drivers/MDS/NlpMdsEx2Driver.cpp index d779a4dcc..5dbe9372e 100644 --- a/src/Drivers/MDS/NlpMdsEx2Driver.cpp +++ b/src/Drivers/MDS/NlpMdsEx2Driver.cpp @@ -11,7 +11,7 @@ using namespace hiop; -static bool self_check(size_type n, double obj_value); +// static bool self_check(size_type n, double obj_value); static bool parse_arguments(int argc, char **argv, bool& self_check, diff --git a/src/Drivers/MDS/NlpMdsRajaEx1.cpp b/src/Drivers/MDS/NlpMdsRajaEx1.cpp index 4533a1002..064c1d05a 100644 --- a/src/Drivers/MDS/NlpMdsRajaEx1.cpp +++ b/src/Drivers/MDS/NlpMdsRajaEx1.cpp @@ -94,8 +94,8 @@ using hiopMatrixRajaDense = hiop::hiopMatrixDenseRaja implementation of hiop::hiopInterfaceMDS MdsEx1* my_nlp = new MdsEx1(n_sp, n_de); diff --git a/src/Drivers/PriDec/NlpPriDecEx1.cpp b/src/Drivers/PriDec/NlpPriDecEx1.cpp index fdcf4b306..1f847886b 100644 --- a/src/Drivers/PriDec/NlpPriDecEx1.cpp +++ b/src/Drivers/PriDec/NlpPriDecEx1.cpp @@ -211,7 +211,7 @@ solve_master(hiopVector& x, } } - bool ierr = my_nlp->set_include(include_r); + [[maybe_unused]] bool ierr = my_nlp->set_include(include_r); if(include_r) { assert(my_nlp->quad_is_defined()); } @@ -257,11 +257,11 @@ solve_master(hiopVector& x, }; -bool PriDecMasterProblemEx1::eval_f_rterm(size_t idx, const int& n,const double* x, double& rval) +bool PriDecMasterProblemEx1::eval_f_rterm(size_type idx, const int& n,const double* x, double& rval) { rval = 0.; for(int i=0; i(idx)) { rval += (x[i]+S_)*(x[i]+S_); } else { rval += x[i]*x[i]; @@ -273,12 +273,12 @@ bool PriDecMasterProblemEx1::eval_f_rterm(size_t idx, const int& n,const double }; // x is handled by primalDecomp to be the correct coupled x -bool PriDecMasterProblemEx1::eval_grad_rterm(size_t idx, const int& n, double* x, hiopVector& grad) +bool PriDecMasterProblemEx1::eval_grad_rterm(size_type idx, const int& n, double* x, hiopVector& grad) { - assert(nc_ == n); + assert(static_cast(nc_) == n); double* grad_vec = grad.local_data(); for(int i=0; i(idx)) { grad_vec[i] = (x[i]+S_); } else { grad_vec[i] = x[i]; diff --git a/src/Drivers/PriDec/NlpPriDecEx1.hpp b/src/Drivers/PriDec/NlpPriDecEx1.hpp index ee9af9df0..a0d3663f8 100644 --- a/src/Drivers/PriDec/NlpPriDecEx1.hpp +++ b/src/Drivers/PriDec/NlpPriDecEx1.hpp @@ -151,12 +151,12 @@ class PriDecMasterProblemEx1 : public hiopInterfacePriDecProblem /** * This function returns the recourse objective, which is 0.5*(x+Se_i)(x+Se_i). */ - virtual bool eval_f_rterm(size_t idx, const int& n,const double* x, double& rval); + virtual bool eval_f_rterm(size_type idx, const int& n,const double* x, double& rval); /** * This function returns the recourse gradient. */ - virtual bool eval_grad_rterm(size_t idx, const int& n, double* x, hiopVector& grad); + virtual bool eval_grad_rterm(size_type idx, const int& n, double* x, hiopVector& grad); /** * This function sets up the approximation of the recourse objective based on the function value and gradient @@ -167,19 +167,19 @@ class PriDecMasterProblemEx1 : public hiopInterfacePriDecProblem virtual bool set_recourse_approx_evaluator(const int n, hiopInterfacePriDecProblem::RecourseApproxEvaluator* evaluator); // Returns the number S of recourse terms. - size_t get_num_rterms() const {return S_;} - size_t get_num_vars() const {return n_;} + size_type get_num_rterms() const {return S_;} + size_type get_num_vars() const {return n_;} // Returns the solution. void get_solution(double* x) const { - for(int i=0; i(n_); i++) x[i] = sol_[i]; } double get_objective() {return obj_;} private: - size_t n_; - size_t S_; - size_t nc_; + size_type n_; + size_type S_; + size_type nc_; PriDecEx1* my_nlp; double obj_; double* sol_; diff --git a/src/Drivers/PriDec/NlpPriDecEx2.cpp b/src/Drivers/PriDec/NlpPriDecEx2.cpp index 7f3dd565f..906f943e7 100644 --- a/src/Drivers/PriDec/NlpPriDecEx2.cpp +++ b/src/Drivers/PriDec/NlpPriDecEx2.cpp @@ -10,7 +10,7 @@ using namespace hiop; PriDecMasterProbleEx2:: -PriDecMasterProbleEx2(size_t nx, size_t ny, size_t nS, size_t S) : nx_(nx), ny_(ny),nS_(nS),S_(S) +PriDecMasterProbleEx2(size_type nx, size_type ny, size_type nS, size_type S) : nx_(nx), ny_(ny),nS_(nS),S_(S) { assert(nx==ny); y_ = new double[ny_]; @@ -103,16 +103,17 @@ set_recourse_approx_evaluator(const int n, return true; } -bool PriDecMasterProbleEx2::eval_f_rterm(size_t idx, const int& n, const double* x, double& rval) +bool PriDecMasterProbleEx2::eval_f_rterm(size_type idx, const int& n, const double* x, double& rval) { assert(nx_==n); rval=-1e+20; - hiopSolveStatus status; double* xi; + hiopSolveStatus status; #ifdef HIOP_USE_MPI - double t3 = MPI_Wtime(); - double t4 = 0.; + // uncomment if want to monitor contingency computing time + //double t3 = MPI_Wtime(); + //double t4 = 0.; #endif // xi can be set below @@ -149,6 +150,7 @@ bool PriDecMasterProbleEx2::eval_f_rterm(size_t idx, const int& n, const double* //assert("for debugging" && false); //for debugging purpose status = solver.run(); + assert(status<=hiopSolveStatus::User_Stopped); //check solver status if necessary rval = solver.getObjective(); if(y_==NULL) { y_ = new double[ny_]; @@ -171,7 +173,7 @@ bool PriDecMasterProbleEx2::eval_f_rterm(size_t idx, const int& n, const double* }; // returns the gradient computed in eval_f_rterm -bool PriDecMasterProbleEx2::eval_grad_rterm(size_t idx, const int& n, double* x, hiopVector& grad) +bool PriDecMasterProbleEx2::eval_grad_rterm(size_type idx, const int& n, double* x, hiopVector& grad) { assert(nx_==n); double* grad_vec = grad.local_data(); @@ -181,12 +183,12 @@ bool PriDecMasterProbleEx2::eval_grad_rterm(size_t idx, const int& n, double* x, return true; }; -inline size_t PriDecMasterProbleEx2::get_num_rterms() const +inline size_type PriDecMasterProbleEx2::get_num_rterms() const { return S_; } -inline size_t PriDecMasterProbleEx2::get_num_vars() const +inline size_type PriDecMasterProbleEx2::get_num_vars() const { return nx_; } diff --git a/src/Drivers/PriDec/NlpPriDecEx2.hpp b/src/Drivers/PriDec/NlpPriDecEx2.hpp index 3d76e8399..e2e78248c 100644 --- a/src/Drivers/PriDec/NlpPriDecEx2.hpp +++ b/src/Drivers/PriDec/NlpPriDecEx2.hpp @@ -67,7 +67,7 @@ using namespace hiop; class PriDecMasterProbleEx2 : public hiop::hiopInterfacePriDecProblem { public: - PriDecMasterProbleEx2(size_t nx, size_t ny, size_t nS, size_t S); + PriDecMasterProbleEx2(size_type nx, size_type ny, size_type nS, size_type S); virtual ~PriDecMasterProbleEx2(); @@ -86,18 +86,18 @@ class PriDecMasterProbleEx2 : public hiop::hiopInterfacePriDecProblem * n is the number of coupled x, not the entire dimension of x, and might be denoted as nc_ elsewhere. * rval is the return value of the recourse solution function evaluation. */ - bool eval_f_rterm(size_t idx, const int& n, const double* x, double& rval); + bool eval_f_rterm(size_type idx, const int& n, const double* x, double& rval); /** * This function computes the gradient of the recourse solution function w.r.t x. * n is the number of coupled x, not the entire dimension of x, and * grad is the output. */ - bool eval_grad_rterm(size_t idx, const int& n, double* x, hiopVector& grad); + bool eval_grad_rterm(size_type idx, const int& n, double* x, hiopVector& grad); - inline size_t get_num_rterms() const; + inline size_type get_num_rterms() const; - inline size_t get_num_vars() const; + inline size_type get_num_vars() const; void get_solution(double* x) const; @@ -105,15 +105,15 @@ class PriDecMasterProbleEx2 : public hiop::hiopInterfacePriDecProblem private: /// dimension of primal variable `x` - size_t nx_; + size_type nx_; /// dimension of the coupled variable, nc_<=nx_ - size_t nc_; + size_type nc_; ///dimension of recourse problem primal variable `y` for each contingency - size_t ny_; + size_type ny_; /// dimension of uncertainty dimension entering the recourse problem - size_t nS_; + size_type nS_; ///number of sample to use, effectively the number of recourse terms - size_t S_; + size_type S_; double* y_; diff --git a/src/Drivers/PriDec/NlpPriDecEx2Sparse.cpp b/src/Drivers/PriDec/NlpPriDecEx2Sparse.cpp index 3ed40422f..e2dcc2565 100644 --- a/src/Drivers/PriDec/NlpPriDecEx2Sparse.cpp +++ b/src/Drivers/PriDec/NlpPriDecEx2Sparse.cpp @@ -5,7 +5,7 @@ using namespace hiop; PriDecMasterProbleEx2Sparse:: -PriDecMasterProbleEx2Sparse(size_t nx, size_t ny, size_t nS, size_t S) : nx_(nx), ny_(ny),nS_(nS),S_(S) +PriDecMasterProbleEx2Sparse(size_type nx, size_type ny, size_type nS, size_type S) : nx_(nx), ny_(ny),nS_(nS),S_(S) { assert(nx==ny); y_ = new double[ny_]; @@ -95,7 +95,7 @@ set_recourse_approx_evaluator(const int n, return true; } -bool PriDecMasterProbleEx2Sparse::eval_f_rterm(size_t idx, const int& n, const double* x, double& rval) +bool PriDecMasterProbleEx2Sparse::eval_f_rterm(size_type idx, const int& n, const double* x, double& rval) { assert(nx_==n); rval=-1e+20; @@ -103,8 +103,9 @@ bool PriDecMasterProbleEx2Sparse::eval_f_rterm(size_t idx, const int& n, const d double* xi; #ifdef HIOP_USE_MPI - double t3 = MPI_Wtime(); - double t4 = 0.; + // uncomment if want to monitor contingency computing time + //double t3 = MPI_Wtime(); + //double t4 = 0.; #endif xi = new double[nS_]; @@ -142,6 +143,7 @@ bool PriDecMasterProbleEx2Sparse::eval_f_rterm(size_t idx, const int& n, const d //assert("for debugging" && false); //for debugging purpose status = solver.run(); + assert(status<=hiopSolveStatus::User_Stopped); //check solver status if necessary rval = solver.getObjective(); if(y_==nullptr) { y_ = new double[ny_]; @@ -164,7 +166,7 @@ bool PriDecMasterProbleEx2Sparse::eval_f_rterm(size_t idx, const int& n, const d }; // returns the gradient computed in eval_f_rterm -bool PriDecMasterProbleEx2Sparse::eval_grad_rterm(size_t idx, const int& n, double* x, hiopVector& grad) +bool PriDecMasterProbleEx2Sparse::eval_grad_rterm(size_type idx, const int& n, double* x, hiopVector& grad) { assert(nx_==n); double* grad_vec = grad.local_data(); @@ -174,12 +176,12 @@ bool PriDecMasterProbleEx2Sparse::eval_grad_rterm(size_t idx, const int& n, doub return true; }; -inline size_t PriDecMasterProbleEx2Sparse::get_num_rterms() const +inline size_type PriDecMasterProbleEx2Sparse::get_num_rterms() const { return S_; } -inline size_t PriDecMasterProbleEx2Sparse::get_num_vars() const +inline size_type PriDecMasterProbleEx2Sparse::get_num_vars() const { return nx_; } diff --git a/src/Drivers/PriDec/NlpPriDecEx2Sparse.hpp b/src/Drivers/PriDec/NlpPriDecEx2Sparse.hpp index d99acc48f..47a44320e 100644 --- a/src/Drivers/PriDec/NlpPriDecEx2Sparse.hpp +++ b/src/Drivers/PriDec/NlpPriDecEx2Sparse.hpp @@ -66,7 +66,7 @@ using namespace hiop; class PriDecMasterProbleEx2Sparse : public hiop::hiopInterfacePriDecProblem { public: - PriDecMasterProbleEx2Sparse(size_t nx, size_t ny, size_t nS, size_t S); + PriDecMasterProbleEx2Sparse(size_type nx, size_type ny, size_type nS, size_type S); virtual ~PriDecMasterProbleEx2Sparse(); @@ -85,18 +85,18 @@ class PriDecMasterProbleEx2Sparse : public hiop::hiopInterfacePriDecProblem * n is the number of coupled x, not the entire dimension of x, and might be denoted as nc_ elsewhere. * rval is the return value of the recourse solution function evaluation. */ - bool eval_f_rterm(size_t idx, const int& n, const double* x, double& rval); + bool eval_f_rterm(size_type idx, const int& n, const double* x, double& rval); /** * This function computes the gradient of the recourse solution function w.r.t x. * n is the number of coupled x, not the entire dimension of x, and * grad is the output. */ - bool eval_grad_rterm(size_t idx, const int& n, double* x, hiopVector& grad); + bool eval_grad_rterm(size_type idx, const int& n, double* x, hiopVector& grad); - inline size_t get_num_rterms() const; + inline size_type get_num_rterms() const; - inline size_t get_num_vars() const; + inline size_type get_num_vars() const; void get_solution(double* x) const; @@ -104,15 +104,15 @@ class PriDecMasterProbleEx2Sparse : public hiop::hiopInterfacePriDecProblem private: /// dimension of primal variable `x` - size_t nx_; + size_type nx_; /// dimension of the coupled variable, nc_<=nx_ - size_t nc_; + size_type nc_; ///dimension of recourse problem primal variable `y` for each contingency - size_t ny_; + size_type ny_; /// dimension of uncertainty dimension entering the recourse problem - size_t nS_; + size_type nS_; ///number of sample to use, effectively the number of recourse terms - size_t S_; + size_type S_; double* y_; diff --git a/src/Drivers/PriDec/NlpPriDecEx2SparseRaja.cpp b/src/Drivers/PriDec/NlpPriDecEx2SparseRaja.cpp index abcf6c552..eaa43fe91 100644 --- a/src/Drivers/PriDec/NlpPriDecEx2SparseRaja.cpp +++ b/src/Drivers/PriDec/NlpPriDecEx2SparseRaja.cpp @@ -22,7 +22,7 @@ using ex9_raja_reduce = hiop::ExecRajaPoliciesBackend:: using namespace hiop; PriDecMasterProbleEx2Sparse:: -PriDecMasterProbleEx2Sparse(size_t nx, size_t ny, size_t nS, size_t S, std::string mem_space) +PriDecMasterProbleEx2Sparse(size_type nx, size_type ny, size_type nS, size_type S, std::string mem_space) : nx_(nx), ny_(ny), nS_(nS), @@ -118,7 +118,7 @@ set_recourse_approx_evaluator(const int n, } // all the memory management is done through umpire in the PriDecRecourseProbleEx2Sparse class -bool PriDecMasterProbleEx2Sparse::eval_f_rterm(size_t idx, const int& n, const double* x, double& rval) +bool PriDecMasterProbleEx2Sparse::eval_f_rterm(size_type idx, const int& n, const double* x, double& rval) { assert(nx_==n); rval=-1e+20; @@ -186,7 +186,7 @@ bool PriDecMasterProbleEx2Sparse::eval_f_rterm(size_t idx, const int& n, const d }; // returns the gradient computed in eval_f_rterm -bool PriDecMasterProbleEx2Sparse::eval_grad_rterm(size_t idx, const int& n, double* x, hiopVector& grad) +bool PriDecMasterProbleEx2Sparse::eval_grad_rterm(size_type idx, const int& n, double* x, hiopVector& grad) { assert(nx_==n); double* grad_vec = grad.local_data(); @@ -196,12 +196,12 @@ bool PriDecMasterProbleEx2Sparse::eval_grad_rterm(size_t idx, const int& n, doub return true; }; -inline size_t PriDecMasterProbleEx2Sparse::get_num_rterms() const +inline size_type PriDecMasterProbleEx2Sparse::get_num_rterms() const { return S_; } -inline size_t PriDecMasterProbleEx2Sparse::get_num_vars() const +inline size_type PriDecMasterProbleEx2Sparse::get_num_vars() const { return nx_; } diff --git a/src/Drivers/PriDec/NlpPriDecEx2SparseRaja.hpp b/src/Drivers/PriDec/NlpPriDecEx2SparseRaja.hpp index 91e4c1da9..f2db47de0 100644 --- a/src/Drivers/PriDec/NlpPriDecEx2SparseRaja.hpp +++ b/src/Drivers/PriDec/NlpPriDecEx2SparseRaja.hpp @@ -67,7 +67,7 @@ using namespace hiop; class PriDecMasterProbleEx2Sparse : public hiop::hiopInterfacePriDecProblem { public: - PriDecMasterProbleEx2Sparse(size_t nx, size_t ny, size_t nS, size_t S, std::string mem_space); + PriDecMasterProbleEx2Sparse(size_type nx, size_type ny, size_type nS, size_type S, std::string mem_space); virtual ~PriDecMasterProbleEx2Sparse(); @@ -86,18 +86,18 @@ class PriDecMasterProbleEx2Sparse : public hiop::hiopInterfacePriDecProblem * n is the number of coupled x, not the entire dimension of x, and might be denoted as nc_ elsewhere. * rval is the return value of the recourse solution function evaluation. */ - bool eval_f_rterm(size_t idx, const int& n, const double* x, double& rval); + bool eval_f_rterm(size_type idx, const int& n, const double* x, double& rval); /** * This function computes the gradient of the recourse solution function w.r.t x. * n is the number of coupled x, not the entire dimension of x, and * grad is the output. */ - bool eval_grad_rterm(size_t idx, const int& n, double* x, hiopVector& grad); + bool eval_grad_rterm(size_type idx, const int& n, double* x, hiopVector& grad); - inline size_t get_num_rterms() const; + inline size_type get_num_rterms() const; - inline size_t get_num_vars() const; + inline size_type get_num_vars() const; void get_solution(double* x) const; @@ -105,15 +105,15 @@ class PriDecMasterProbleEx2Sparse : public hiop::hiopInterfacePriDecProblem private: /// dimension of primal variable `x` - size_t nx_; + size_type nx_; /// dimension of the coupled variable, nc_<=nx_ - size_t nc_; + size_type nc_; ///dimension of recourse problem primal variable `y` for each contingency - size_t ny_; + size_type ny_; /// dimension of uncertainty dimension entering the recourse problem - size_t nS_; + size_type nS_; ///number of sample to use, effectively the number of recourse terms - size_t S_; + size_type S_; double* y_; diff --git a/src/Drivers/PriDec/NlpPriDecEx2UserBasecase.hpp b/src/Drivers/PriDec/NlpPriDecEx2UserBasecase.hpp index affea63eb..35ac2c258 100644 --- a/src/Drivers/PriDec/NlpPriDecEx2UserBasecase.hpp +++ b/src/Drivers/PriDec/NlpPriDecEx2UserBasecase.hpp @@ -100,6 +100,7 @@ class PriDecBasecaseProbleEx2 : public SparseEx1 void get_rec_obj(const size_type& n, const double* x, double& obj_value) { bool temp = rec_evaluator_->eval_f(n, x, false, obj_value); + assert(temp); } protected: diff --git a/src/Drivers/PriDec/NlpPriDecEx2UserRecourseMds.hpp b/src/Drivers/PriDec/NlpPriDecEx2UserRecourseMds.hpp index 910a9999e..58c0d0e11 100644 --- a/src/Drivers/PriDec/NlpPriDecEx2UserRecourseMds.hpp +++ b/src/Drivers/PriDec/NlpPriDecEx2UserRecourseMds.hpp @@ -27,7 +27,12 @@ class PriDecRecourseProbleEx2 : public hiop::hiopInterfaceMDS { public: - PriDecRecourseProbleEx2(int n, int nS, int S): nx_(n), nS_(nS),S_(S),x_(nullptr),xi_(nullptr) + PriDecRecourseProbleEx2(int n, int nS, int S) + : x_(nullptr), + xi_(nullptr), + nx_(n), + nS_(nS), + S_(S) { assert(nS_>=1); assert(nx_>=nS_); // ny = nx = n diff --git a/src/Drivers/PriDec/NlpPriDecEx2UserRecourseSparse.hpp b/src/Drivers/PriDec/NlpPriDecEx2UserRecourseSparse.hpp index 822650849..586906cc6 100644 --- a/src/Drivers/PriDec/NlpPriDecEx2UserRecourseSparse.hpp +++ b/src/Drivers/PriDec/NlpPriDecEx2UserRecourseSparse.hpp @@ -29,11 +29,11 @@ class PriDecRecourseProbleEx2Sparse : public hiop::hiopInterfaceSparse { public: PriDecRecourseProbleEx2Sparse(int n, int nS, int S) - : nx_(n), + : x_(nullptr), + xi_(nullptr), + nx_(n), nS_(nS), - S_(S), - x_(nullptr), - xi_(nullptr) + S_(S) { assert(nS_>=1); assert(nx_>=nS_); // ny = nx = n diff --git a/src/Drivers/PriDec/NlpPriDecEx2UserRecourseSparseRaja.hpp b/src/Drivers/PriDec/NlpPriDecEx2UserRecourseSparseRaja.hpp index 07aecfc63..98f54c478 100644 --- a/src/Drivers/PriDec/NlpPriDecEx2UserRecourseSparseRaja.hpp +++ b/src/Drivers/PriDec/NlpPriDecEx2UserRecourseSparseRaja.hpp @@ -50,17 +50,17 @@ class PriDecRecourseProbleEx2Sparse : public hiop::hiopInterfaceSparse { public: PriDecRecourseProbleEx2Sparse(int n, int nS, int S, std::string mem_space) - : nx_(n), - nS_(nS),S_(S), - x_(nullptr), + : x_(nullptr), xi_(nullptr), + nx_(n), + nS_(nS),S_(S), mem_space_(mem_space) { // Make sure mem_space_ is uppercase transform(mem_space_.begin(), mem_space_.end(), mem_space_.begin(), ::toupper); - auto& resmgr = umpire::ResourceManager::getInstance(); - umpire::Allocator allocator = resmgr.getAllocator(mem_space_); + //auto& resmgr = umpire::ResourceManager::getInstance(); + //umpire::Allocator allocator = resmgr.getAllocator(mem_space_); // umpire::Allocator allocator // = resmgr.getAllocator(mem_space_ == "DEFAULT" ? "HOST" : mem_space_); diff --git a/src/Drivers/PriDec/NlpPriDecEx3Sparse.hpp b/src/Drivers/PriDec/NlpPriDecEx3Sparse.hpp index 495c9a8c8..a73ceb728 100644 --- a/src/Drivers/PriDec/NlpPriDecEx3Sparse.hpp +++ b/src/Drivers/PriDec/NlpPriDecEx3Sparse.hpp @@ -35,11 +35,15 @@ class SparseEx3 : public hiop::hiopInterfaceSparse { public: SparseEx3(int nx,int S) - : nx_(nx),n_vars(nx+S*nx), n_cons{2+S*nx},S_(S) //total number of variables should be nx+S*nx + : n_vars_(nx+S*nx), + n_cons_{2+S*nx}, + nx_(nx), + S_(S) //total number of variables should be nx+S*nx { assert(nx>=3); - if(nx>3) - n_cons += nx-3; + if(nx>3) { + n_cons_ += nx-3; + } nS_ = int(nx_/2); xi_ = new double[S_*nS_]; x0_ = new double[nx_]; @@ -48,11 +52,16 @@ class SparseEx3 : public hiop::hiopInterfaceSparse } SparseEx3(int nx,int S,int nS) - : nx_(nx),n_vars(nx+S*nx), n_cons{2+S*nx},S_(S),nS_(nS) //total number of variables should be nx+S*nx + : n_vars_(nx+S*nx), + n_cons_{2+S*nx}, + nx_(nx), + S_(S), + nS_(nS) //total number of variables should be nx+S*nx { assert(nx>=3); - if(nx>3) - n_cons += nx-3; + if(nx>3) { + n_cons_ += nx-3; + } xi_ = new double[nS_*S_]; x0_ = new double[nx_]; for(int i=0;i=3); //2*(n-1) for basecase @@ -374,7 +383,7 @@ class SparseEx3 : public hiop::hiopInterfaceSparse bool get_starting_point(const size_type& n, double* x0) { - assert(n==n_vars); + assert(n==n_vars_); for(auto i=0; i=3); if(n>3) - n_cons += n-3; - n_cons += rankdefic_eq_ + rankdefic_ineq_; + n_cons_ += n-3; + n_cons_ += rankdefic_eq_ + rankdefic_ineq_; } SparseEx2::~SparseEx2() @@ -47,14 +47,14 @@ SparseEx2::~SparseEx2() bool SparseEx2::get_prob_sizes(size_type& n, size_type& m) { - n=n_vars; - m=n_cons; + n=n_vars_; + m=n_cons_; return true; } bool SparseEx2::get_vars_info(const size_type& n, double *xlow, double* xupp, NonlinearityType* type) { - assert(n==n_vars); + assert(n==n_vars_); for(index_type i=0; i=3); assert(nnzJacS == 4 + 2*(n-3) + 2*rankdefic_eq_ + 2*rankdefic_ineq_); @@ -318,7 +318,7 @@ bool SparseEx2::eval_Hess_Lagr(const size_type& n, bool SparseEx2::get_starting_point(const size_type& n, double* x0) { - assert(n==n_vars); + assert(n==n_vars_); for(auto i=0; irefcppHiop); status = solver.run(); + assert(status<=hiopSolveStatus::User_Stopped); //check solver status if necessary prob->obj_value = solver.getObjective(); solver.getSolution(prob->solution); return 0; @@ -110,7 +111,6 @@ int hiop_sparse_create_problem(cHiopSparseProblem *prob) { } int hiop_sparse_solve_problem(cHiopSparseProblem *prob) { - hiopSolveStatus status; hiopAlgFilterIPMNewton solver(prob->refcppHiop_); prob->status_ = solver.run(); prob->obj_value_ = solver.getObjective(); @@ -144,7 +144,6 @@ int hiop_dense_create_problem(cHiopDenseProblem *prob) { } int hiop_dense_solve_problem(cHiopDenseProblem *prob) { - hiopSolveStatus status; hiopAlgFilterIPMQuasiNewton solver(prob->refcppHiop); prob->status = solver.run(); prob->obj_value = solver.getObjective(); diff --git a/src/Interface/hiopInterfacePrimalDecomp.hpp b/src/Interface/hiopInterfacePrimalDecomp.hpp index 6503961c2..e8d4eb102 100644 --- a/src/Interface/hiopInterfacePrimalDecomp.hpp +++ b/src/Interface/hiopInterfacePrimalDecomp.hpp @@ -89,18 +89,18 @@ class hiopInterfacePriDecProblem const double* hess = 0, const char* master_options_file=nullptr) = 0; - virtual bool eval_f_rterm(size_t idx, const int& n, const double* x, double& rval) = 0; - virtual bool eval_grad_rterm(size_t idx, const int& n, double* x, hiopVector& grad) = 0; + virtual bool eval_f_rterm(size_type idx, const int& n, const double* x, double& rval) = 0; + virtual bool eval_grad_rterm(size_type idx, const int& n, double* x, hiopVector& grad) = 0; /** * Returns the number S of recourse terms */ - virtual size_t get_num_rterms() const = 0; + virtual size_type get_num_rterms() const = 0; /** * Return the number of primal optimization variables */ - virtual size_t get_num_vars() const = 0; + virtual size_type get_num_vars() const = 0; virtual void get_solution(double* x) const = 0; virtual double get_objective() = 0; @@ -142,7 +142,7 @@ class hiopInterfacePriDecProblem const hiopVector& x0, const std::string& mem_space); - ~RecourseApproxEvaluator(); + virtual ~RecourseApproxEvaluator(); bool eval_f(const size_type& n, const double* x, bool new_x, double& obj_value); diff --git a/src/LinAlg/hiopLinSolverSparseGinkgo.cpp b/src/LinAlg/hiopLinSolverSparseGinkgo.cpp index 4af6348f2..971ef699a 100644 --- a/src/LinAlg/hiopLinSolverSparseGinkgo.cpp +++ b/src/LinAlg/hiopLinSolverSparseGinkgo.cpp @@ -172,10 +172,10 @@ std::shared_ptr> transferTripletToCSR(std::shared_ delete[] nnz_each_row_tmp; } - auto val_array = gko::Array::view(exec, nnz_, kVal_); - auto row_ptrs = gko::Array::view(exec, n_ + 1, kRowPtr_); - auto col_idxs = gko::Array::view(exec, nnz_, jCol_); - auto mtx = gko::share(gko::matrix::Csr::create(exec, gko::dim<2>{n_, n_}, val_array, col_idxs, row_ptrs)); + auto val_array = gko::array::view(exec, nnz_, kVal_); + auto row_ptrs = gko::array::view(exec, n_ + 1, kRowPtr_); + auto col_idxs = gko::array::view(exec, nnz_, jCol_); + auto mtx = gko::share(gko::matrix::Csr::create(exec, gko::dim<2>{(long unsigned int)n_, (long unsigned int)n_}, val_array, col_idxs, row_ptrs)); return mtx; } @@ -189,7 +189,6 @@ void update_matrix(hiopMatrixSparse* M_, int n_ = mtx->get_size()[0]; int nnz_= mtx->get_num_stored_elements(); auto values = host_mtx->get_values(); - int rowID_tmp{0}; for(int k=0; kM()[index_covert_CSR2Triplet_[k]]; } @@ -280,10 +279,10 @@ std::shared_ptr setup_solver_factory(std::shared_ptr setup_solver_factory(std::shared_ptr(x->new_copy()); double* dx = x->local_data(); double* drhs = rhs->local_data(); - const auto size = gko::dim<2>{n_, 1}; + const auto size = gko::dim<2>{(long unsigned int)n_, 1}; auto dense_x_host = vec::create(host, size, arr::view(host, n_, dx), 1); auto dense_x = vec::create(exec_, size); dense_x->copy_from(dense_x_host.get()); diff --git a/src/LinAlg/hiopLinSolverSymDenseLapack.hpp b/src/LinAlg/hiopLinSolverSymDenseLapack.hpp index 47c6d9416..39127e35b 100644 --- a/src/LinAlg/hiopLinSolverSymDenseLapack.hpp +++ b/src/LinAlg/hiopLinSolverSymDenseLapack.hpp @@ -96,7 +96,6 @@ class hiopLinSolverSymDenseLapack : public hiopLinSolverSymDense dwork = LinearAlgebraFactory::create_vector("DEFAULT", lwork); } - bool rank_deficient=false; // // factorization // @@ -126,7 +125,7 @@ class hiopLinSolverSymDenseLapack : public hiopLinSolverSymDense // LINPACK's dsidi Fortran routine (http://www.netlib.org/linpack/dsidi.f) // 04/08/2020 - petra: fixed the test for non-positive pivots (was only for negative pivots) int negEigVal=0; - int posEigVal=0; + [[maybe_unused]] int posEigVal=0; int nullEigVal=0; double t=0; double* MM = M_->local_data(); diff --git a/src/LinAlg/hiopLinSolverSymDenseMagma.cpp b/src/LinAlg/hiopLinSolverSymDenseMagma.cpp index c51aa7ca9..c29ec4f78 100644 --- a/src/LinAlg/hiopLinSolverSymDenseMagma.cpp +++ b/src/LinAlg/hiopLinSolverSymDenseMagma.cpp @@ -188,7 +188,6 @@ namespace hiop { int inert[3]; int info; - int retcode; magma_uplo_t uplo=MagmaLower; // M is upper in C++ so it's lower in fortran #ifdef HIOP_USE_HIP uplo = MagmaUpper; // M is upper in C++ so it's lower in fortran @@ -226,7 +225,6 @@ namespace hiop assert(M_->n() == M_->m()); assert(x.get_size() == M_->n()); int N = M_->n(); - int LDA = N; int LDB = N; int NRHS = 1; if(N == 0) { @@ -328,7 +326,6 @@ namespace hiop assert(M_->n() == M_->m()); int N=M_->n(); int LDA = N; - int LDB=N; if(N==0) { return true; } @@ -429,7 +426,6 @@ namespace hiop assert(M_->n() == M_->m()); assert(x.get_size()==M_->n()); int N=M_->n(); - int LDA = N; int LDB=N; if(N==0) { return true; diff --git a/src/LinAlg/hiopLinSolverSymSparseMA57.cpp b/src/LinAlg/hiopLinSolverSymSparseMA57.cpp index 3c1ab476e..2d2a2b206 100644 --- a/src/LinAlg/hiopLinSolverSymSparseMA57.cpp +++ b/src/LinAlg/hiopLinSolverSymSparseMA57.cpp @@ -118,7 +118,6 @@ namespace hiop bool done{false}; bool is_singular{false}; - int num_tries{0}; //get the triplet values array and copy the entries into it (different behavior for triplet and csr implementations) double* Mvals = get_triplet_values_array(); @@ -162,10 +161,11 @@ namespace hiop }; break; default: - if( info_[0] >= 0 ) done = true; + if(info_[0] >= 0) { + done = true; + } assert( "unknown error!" && 0 ); } // end switch - num_tries++; } while( !done ); nlp_->runStats.linsolv.tmFactTime.stop(); @@ -193,7 +193,6 @@ namespace hiop nlp_->runStats.linsolv.tmTriuSolves.start(); int job = 1; // full solve - int one = 1; icntl_[9-1] = 1; // do one step of iterative refinement hiopVector* x = dynamic_cast(&x_in); diff --git a/src/LinAlg/hiopLinSolverUMFPACKZ.cpp b/src/LinAlg/hiopLinSolverUMFPACKZ.cpp index 2d8c03703..8ef8c94e9 100644 --- a/src/LinAlg/hiopLinSolverUMFPACKZ.cpp +++ b/src/LinAlg/hiopLinSolverUMFPACKZ.cpp @@ -4,7 +4,11 @@ namespace hiop { hiopLinSolverUMFPACKZ::hiopLinSolverUMFPACKZ(hiopMatrixComplexSparseTriplet& sysmat, hiopNlpFormulation* nlp_/*=NULL*/) - : m_symbolic(NULL), m_numeric(NULL), m_null(NULL), sys_mat(sysmat), nlp(nlp_) + : m_symbolic(nullptr), + m_numeric(nullptr), + m_null(nullptr), + nlp(nlp_), + sys_mat(sysmat) { n = sys_mat.n(); nnz = sys_mat.numberOfNonzeros(); diff --git a/src/LinAlg/hiopMatrixDenseRajaImpl.hpp b/src/LinAlg/hiopMatrixDenseRajaImpl.hpp index 1991a57a2..def5051e5 100644 --- a/src/LinAlg/hiopMatrixDenseRajaImpl.hpp +++ b/src/LinAlg/hiopMatrixDenseRajaImpl.hpp @@ -1099,7 +1099,6 @@ void hiopMatrixDenseRaja::addSubDiagonal(const double& assert(start+dlen<=n_local_); #endif - int diag = std::min(get_local_size_m(), get_local_size_n()); double* data = data_dev_; const double* dd = d.local_data_const(); RAJA::View> Mview(data, get_local_size_m(), get_local_size_n()); // matrix @@ -1141,7 +1140,6 @@ void hiopMatrixDenseRaja::addSubDiagonal(int start_on_d assert(start_on_dest_diag>=0 && start_on_dest_diag> Mview(data, get_local_size_m(), get_local_size_n()); @@ -1174,7 +1172,6 @@ addSubDiagonal(int start_on_dest_diag, int num_elems, const double& c) assert(n_local_ == n_global_ && "method supported only for non-distributed matrices"); assert(n_local_ == m_local_ && "method supported only for symmetric matrices"); - int diag = std::min(get_local_size_m(), get_local_size_n()); double* data = data_dev_; RAJA::View> Mview(data, get_local_size_m(), get_local_size_n()); RAJA::forall(RAJA::RangeSegment(0, num_elems), diff --git a/src/LinAlg/hiopMatrixDenseRowMajor.cpp b/src/LinAlg/hiopMatrixDenseRowMajor.cpp index cf614657e..478ac897b 100644 --- a/src/LinAlg/hiopMatrixDenseRowMajor.cpp +++ b/src/LinAlg/hiopMatrixDenseRowMajor.cpp @@ -540,7 +540,6 @@ void hiopMatrixDenseRowMajor::timesMat(double beta, hiopMatrix& W_, double alpha timesMat_local(beta,W_,alpha,X_); #else auto& W = dynamic_cast(W_); - double* WM=W.local_data(); const auto& X = dynamic_cast(X_); assert(W.m()==this->m()); @@ -749,7 +748,6 @@ void hiopMatrixDenseRowMajor::addSubDiagonal(int start_on_dest_diag, num_elems = std::min(num_elems, m_local_-start_on_dest_diag); const double* dd=d.local_data_const(); - const int nend = start_on_dest_diag+num_elems; for(int i=0; i(X); - hiopMatrixDense &W_d = dynamic_cast(W); mDe->timesMatTrans(beta, W, 1.0, *X_mds.de_mat()); mSp->timesMatTrans(1.0, W, 1.0, *X_mds.sp_mat()); diff --git a/src/LinAlg/hiopMatrixRajaSparseTriplet.hpp b/src/LinAlg/hiopMatrixRajaSparseTriplet.hpp index 00bc19a08..4f2cdb6e0 100644 --- a/src/LinAlg/hiopMatrixRajaSparseTriplet.hpp +++ b/src/LinAlg/hiopMatrixRajaSparseTriplet.hpp @@ -395,8 +395,8 @@ class hiopMatrixRajaSparseTriplet : public hiopMatrixSparse std::string mem_space_; RowStartsInfo() : idx_start_(nullptr), - num_rows_(0), - register_row_st_{0} + register_row_st_{0}, + num_rows_(0) {} RowStartsInfo(size_type n_rows, std::string memspace); virtual ~RowStartsInfo(); diff --git a/src/LinAlg/hiopMatrixRajaSparseTripletImpl.hpp b/src/LinAlg/hiopMatrixRajaSparseTripletImpl.hpp index fd538740f..5cf34506d 100644 --- a/src/LinAlg/hiopMatrixRajaSparseTripletImpl.hpp +++ b/src/LinAlg/hiopMatrixRajaSparseTripletImpl.hpp @@ -79,8 +79,8 @@ hiopMatrixRajaSparseTriplet(int rows, int _nnz, std::string memspace) : hiopMatrixSparse(rows, cols, _nnz), - row_starts_(nullptr), - mem_space_(memspace) + mem_space_(memspace), + row_starts_(nullptr) { if(rows==0 || cols==0) { @@ -517,13 +517,14 @@ transAddToSymDenseMatrixUpperTriangle(int row_start, double alpha, hiopMatrixDense& W) const { - assert(row_start>=0 && row_start+ncols_<=W.m()); - assert(col_start>=0 && col_start+nrows_<=W.n()); - assert(W.n()==W.m()); - - RAJA::View> WM(W.local_data(), W.m(), W.n()); auto Wm = W.m(); auto Wn = W.n(); + + assert(row_start>=0 && row_start+ncols_<=Wm); + assert(col_start>=0 && col_start+nrows_<=Wn); + assert(Wn==Wm); + + RAJA::View> WM(W.local_data(), W.m(), W.n()); int* iRow = iRow_; int* jCol = jCol_; double* values = values_; @@ -1029,12 +1030,9 @@ copyRowsFrom(const hiopMatrix& src_gen, assert(this->n() == src.n()); assert(n_rows <= src.m()); - const int* iRow_src = src.i_row(); const int* jCol_src = src.j_col(); const double* values_src = src.M(); - size_type nnz_src = src.numberOfNonzeros(); - size_type m_src = src.m(); if(src.row_starts_ == nullptr) { src.row_starts_ = src.allocAndBuildRowStarts(); } @@ -1044,7 +1042,6 @@ copyRowsFrom(const hiopMatrix& src_gen, index_type* iRow = iRow_; index_type* jCol = jCol_; double* values = values_; - size_type nnz_dst = numberOfNonzeros(); // this function only set up sparsity in the first run. Sparsity won't change after the first run. if(row_starts_ == nullptr) { @@ -1123,17 +1120,13 @@ copyRowsBlockFrom(const hiopMatrix& src_gen, assert(n_rows + rows_src_idx_st <= src.m()); assert(n_rows + rows_dst_idx_st <= this->m()); - const index_type* iRow_src = src.i_row(); const index_type* jCol_src = src.j_col(); const double* values_src = src.M(); - size_type nnz_src = src.numberOfNonzeros(); // local copy of member variable/function, for RAJA access index_type* iRow = iRow_; index_type* jCol = jCol_; double* values = values_; - size_type nnz_dst = numberOfNonzeros(); - size_type n_rows_src = src.m(); size_type n_rows_dst = this->m(); if(src.row_starts_ == nullptr) { @@ -1285,9 +1278,9 @@ void hiopMatrixRajaSparseTriplet::copyFromDev() const template hiopMatrixRajaSparseTriplet::RowStartsInfo:: RowStartsInfo(size_type n_rows, std::string memspace) - : num_rows_(n_rows), - mem_space_(memspace), - register_row_st_{0} + : register_row_st_{0}, + num_rows_(n_rows), + mem_space_(memspace) { auto& resmgr = umpire::ResourceManager::getInstance(); umpire::Allocator alloc = resmgr.getAllocator(mem_space_); @@ -2151,7 +2144,6 @@ set_Hess_FR(const hiopMatrixSparse& Hess, assert(m_row==m2 || m2==0); int nnz1 = m_row + M2.numberOfOffDiagNonzeros(); - int nnz2 = M2.numberOfNonzeros(); assert(this->nnz_ == nnz1); @@ -2159,8 +2151,6 @@ set_Hess_FR(const hiopMatrixSparse& Hess, M2.row_starts_ = M2.allocAndBuildRowStarts(); } assert(M2.row_starts_); - const int* M2iRow_host = M2.i_row_host(); - const int* M2jCol_host = M2.j_col_host(); index_type* M1_row_start{nullptr}; index_type* M2_row_start = M2.row_starts_->idx_start_; @@ -2266,7 +2256,6 @@ set_Hess_FR(const hiopMatrixSparse& Hess, double* M1values = M1.M(); const double* M2values = M2.M(); - const auto& diag_x = dynamic_cast&>(add_diag); const double* diag_data = add_diag.local_data_const(); if(m2 > 0) { diff --git a/src/LinAlg/hiopMatrixSparseCSRSeq.cpp b/src/LinAlg/hiopMatrixSparseCSRSeq.cpp index 8a017e657..e7eceb749 100644 --- a/src/LinAlg/hiopMatrixSparseCSRSeq.cpp +++ b/src/LinAlg/hiopMatrixSparseCSRSeq.cpp @@ -317,7 +317,6 @@ void hiopMatrixSparseCSRSeq::row_max_abs_value(hiopVector &ret_vec) hiopVectorPar& yy = dynamic_cast(ret_vec); yy.setToZero(); - double* y_data = yy.local_data(); assert(false && "not yet implemented"); } @@ -326,8 +325,6 @@ void hiopMatrixSparseCSRSeq::scale_row(hiopVector &vec_scal, const bool inv_scal { assert(vec_scal.get_local_size() == nrows_); - hiopVectorPar& vscal = dynamic_cast(vec_scal); - double* vd = vscal.local_data(); assert(false && "not yet implemented"); } @@ -658,15 +655,12 @@ void hiopMatrixSparseCSRSeq::times_mat_symbolic(hiopMatrixSparseCSR& M_in, auto& Y = dynamic_cast(Y_in); const index_type* irowptrY = Y.i_row(); const index_type* jcolindY = Y.j_col(); - const double* valuesY = Y.M(); const index_type* irowptrX = irowptr_; const index_type* jcolindX = jcolind_; - const double* valuesX = values_; index_type* irowptrM = M.i_row(); index_type* jcolindM = M.j_col(); - double* valuesM = M.M(); const index_type m = this->m(); const index_type n = Y.n(); @@ -903,7 +897,6 @@ void hiopMatrixSparseCSRSeq::form_transpose_from_symbolic(const hiopMatrixSparse const index_type* Mirow = M.i_row(); const index_type* Mjcol = M.j_col(); - const double* Mvalues = M.M(); assert(nullptr == row_starts_); row_starts_ = new index_type[nrows_]; @@ -932,7 +925,7 @@ void hiopMatrixSparseCSRSeq::form_transpose_from_symbolic(const hiopMatrixSparse } //here row_starts_(==w) contains the row starts } - assert(irowptr_[nrows_] = nnz_); + assert(irowptr_[nrows_] == nnz_); //populate jcolind_ for(index_type it=0; it(ret_vec); - yy.setToZero(); - double* y_data = yy.local_data(); - assert(false && "not yet implemented"); } void hiopMatrixSparseCSRCUDA::scale_row(hiopVector &vec_scal, const bool inv_scale) { assert(vec_scal.get_local_size() == nrows_); - - hiopVectorPar& vscal = dynamic_cast(vec_scal); - double* vd = vscal.local_data(); assert(false && "not yet implemented"); } diff --git a/src/LinAlg/hiopMatrixSparseTriplet.cpp b/src/LinAlg/hiopMatrixSparseTriplet.cpp index d8653ad71..6b81c4f04 100644 --- a/src/LinAlg/hiopMatrixSparseTriplet.cpp +++ b/src/LinAlg/hiopMatrixSparseTriplet.cpp @@ -678,7 +678,6 @@ copyDiagMatrixToSubblock(const double& src_val, assert(nnz_to_copy + dest_row_st <= this->m()); assert(nnz_to_copy + col_dest_st <= this->n()); - int itnz_src=0; int itnz_dest=dest_nnz_st; for(auto ele_add=0; ele_add(Jac_c); const auto& J_d = dynamic_cast(Jac_d); - // shortcut to the original Jac - const int *irow_c = J_c.i_row(); - const int *jcol_c = J_c.j_col(); - const int *irow_d = J_d.i_row(); - const int *jcol_d = J_d.j_col(); - // assuming original Jac is sorted! int nnz_Jac_c = J_c.numberOfNonzeros(); int nnz_Jac_d = J_d.numberOfNonzeros(); @@ -906,7 +899,6 @@ void hiopMatrixSparseTriplet::set_Jac_FR(const hiopMatrixSparse& Jac_c, const double* J_d_val = J_d.M(); for(int i = 0; i < m_d; ++i) { index_type k_base = J_d.row_starts_->idx_start_[i]; - size_type nnz_in_row = J_d.row_starts_->idx_start_[i+1] - k_base; // copy from base Jac_d while(k_base < J_d.row_starts_->idx_start_[i+1]) { @@ -1199,7 +1191,6 @@ void hiopMatrixSparseTriplet::convert_to_csr_arrays(int &csr_nnz, std::unordered_map& extra_diag_nnz_map) { assert(*csr_kRowPtr_in==nullptr && *index_convert_CSR2Triplet_in==nullptr); - int m = this->m(); int n = this->n(); int nnz = numberOfNonzeros(); @@ -1213,7 +1204,6 @@ void hiopMatrixSparseTriplet::convert_to_csr_arrays(int &csr_nnz, * Note that input is in lower triangular triplet form. First part is the sparse matrix, and the 2nd part containts additional * diagonal elements. */ - int n_diag_val=0; std::unordered_map extra_diag_nnz_map_temp; int *diag_defined = new int[n]; @@ -1231,7 +1221,6 @@ void hiopMatrixSparseTriplet::convert_to_csr_arrays(int &csr_nnz, diag_defined[iRow_[k]] = k; csr_kRowPtr[iRow_[k]+1]++; csr_nnz++; - n_diag_val++; }else{ extra_diag_nnz_map_temp[iRow_[k]] = k; } @@ -1242,7 +1231,7 @@ void hiopMatrixSparseTriplet::convert_to_csr_arrays(int &csr_nnz, csr_kRowPtr[i] += csr_kRowPtr[i-1]; } assert(csr_nnz==csr_kRowPtr[n]); - assert(csr_nnz+extra_diag_nnz_map_temp.size()==nnz); + assert(static_cast(csr_nnz+extra_diag_nnz_map_temp.size())==nnz); *csr_kVal_in = new double[csr_nnz]; *csr_jCol_in = new int[csr_nnz]; @@ -1265,7 +1254,7 @@ void hiopMatrixSparseTriplet::convert_to_csr_arrays(int &csr_nnz, diag_defined[i] = -1; } - int total_nnz_tmp{0},nnz_tmp{0}, rowID_tmp, colID_tmp; + int nnz_tmp{0}, rowID_tmp, colID_tmp; for(int k=0;k(Hess); // assuming original Hess is sorted, and in upper-triangle format - int nnz_h = Hess_base.numberOfNonzeros(); int m_h = Hess.m(); int n_h = Hess.n(); diff --git a/src/LinAlg/hiopVectorCompoundPD.cpp b/src/LinAlg/hiopVectorCompoundPD.cpp index a9703d8ce..9f7d31fe5 100644 --- a/src/LinAlg/hiopVectorCompoundPD.cpp +++ b/src/LinAlg/hiopVectorCompoundPD.cpp @@ -67,8 +67,8 @@ namespace hiop { hiopVectorCompoundPD::hiopVectorCompoundPD(bool own_vectors) -: own_vectors_{own_vectors}, - n_parts_{0} +: n_parts_{0}, + own_vectors_{own_vectors} { n_ = 0; } @@ -944,16 +944,17 @@ bool hiopVectorCompoundPD::isfinite_local() const return true; } -void hiopVectorCompoundPD::print(FILE* file/*=nullptr*/, const char* msg/*=nullptr*/, int max_elems/*=-1*/, int rank/*=-1*/) const +void hiopVectorCompoundPD::print(FILE* file/*=nullptr*/, const char* msg/*=nullptr*/, int max_elems/*=-1*/, int rank/*=-1*/) const { - int myrank_=0, numranks=1; - MPI_Comm comm_ = MPI_COMM_SELF; + int myrank_=0; if(nullptr == file) { file = stdout; } #ifdef HIOP_USE_MPI + int numranks = 1; + MPI_Comm comm_ = MPI_COMM_SELF; if(rank>=0) { int err = MPI_Comm_rank(comm_, &myrank_); assert(err==MPI_SUCCESS); err = MPI_Comm_size(comm_, &numranks); assert(err==MPI_SUCCESS); diff --git a/src/LinAlg/hiopVectorCuda.cpp b/src/LinAlg/hiopVectorCuda.cpp index 3d387f5a7..4584c697f 100644 --- a/src/LinAlg/hiopVectorCuda.cpp +++ b/src/LinAlg/hiopVectorCuda.cpp @@ -71,8 +71,8 @@ namespace hiop hiopVectorCuda::hiopVectorCuda(const size_type& glob_n, index_type* col_part, MPI_Comm comm) : hiopVector(), - idx_cumsum_{nullptr}, - comm_(comm) + comm_(comm), + idx_cumsum_{nullptr} { n_ = glob_n; diff --git a/src/LinAlg/hiopVectorHip.cpp b/src/LinAlg/hiopVectorHip.cpp index 0b1917067..d55f2d421 100644 --- a/src/LinAlg/hiopVectorHip.cpp +++ b/src/LinAlg/hiopVectorHip.cpp @@ -71,8 +71,8 @@ namespace hiop hiopVectorHip::hiopVectorHip(const size_type& glob_n, index_type* col_part, MPI_Comm comm) : hiopVector(), - idx_cumsum_{nullptr}, - comm_(comm) + comm_(comm), + idx_cumsum_{nullptr} { n_ = glob_n; diff --git a/src/LinAlg/hiopVectorPar.cpp b/src/LinAlg/hiopVectorPar.cpp index ce7669d33..d3587e22f 100644 --- a/src/LinAlg/hiopVectorPar.cpp +++ b/src/LinAlg/hiopVectorPar.cpp @@ -183,7 +183,6 @@ void hiopVectorPar::copy_from_w_pattern(const hiopVector& vv, const hiopVector& const double* ix_vec = ix.data_; const double* v_vec = v.data_; - size_type nv = v.get_local_size(); for(index_type i=0; i(MEMBACKEND(mem_space))), exec_space_host_(ExecSpace(MEMBACKENDHOST::new_backend_host())), - idx_cumsum_{nullptr}, mem_space_(mem_space), - comm_(comm) + comm_(comm), + idx_cumsum_{nullptr} { n_ = glob_n; diff --git a/src/Optimization/hiopAlgFilterIPM.cpp b/src/Optimization/hiopAlgFilterIPM.cpp index df2ac3c3d..e0802cb6c 100644 --- a/src/Optimization/hiopAlgFilterIPM.cpp +++ b/src/Optimization/hiopAlgFilterIPM.cpp @@ -76,11 +76,11 @@ namespace hiop { hiopAlgFilterIPMBase::hiopAlgFilterIPMBase(hiopNlpFormulation* nlp_in, const bool within_FR) - : c_soc(nullptr), + : soc_dir(nullptr), + onenorm_pr_curr_{0.0}, + c_soc(nullptr), d_soc(nullptr), - soc_dir(nullptr), within_FR_{within_FR}, - onenorm_pr_curr_{0.0}, pd_perturb_{nullptr}, fact_acceptor_{nullptr} { @@ -335,8 +335,8 @@ int hiopAlgFilterIPMBase::startingProcedure(hiopIterate& it_ini, return false; } - bool do_nlp_scaling = nlp->apply_scaling(c, d, gradf, Jac_c, Jac_d); - + [[maybe_unused]] const bool do_nlp_scaling = nlp->apply_scaling(c, d, gradf, Jac_c, Jac_d); + nlp->runStats.tmSolverInternal.start(); nlp->runStats.tmStartingPoint.start(); @@ -558,7 +558,7 @@ bool hiopAlgFilterIPMBase::update_log_barrier_params(hiopIterate& it, const double target_mu = nlp->options->GetNumeric("tolerance"); const double bound_relax_perturb_init = nlp->options->GetNumeric("elastic_mode_bound_relax_initial"); const double bound_relax_perturb_min = nlp->options->GetNumeric("elastic_mode_bound_relax_final"); - double bound_relax_perturb; + double bound_relax_perturb = bound_relax_perturb_init; if(nlp->options->GetString("elastic_bound_strategy")=="mu_scaled") { bound_relax_perturb = 0.995*mu_new; @@ -603,7 +603,7 @@ bool hiopAlgFilterIPMBase::update_log_barrier_params(hiopIterate& it, } } //compute infeasibility theta at trial point, since slacks and/or bounds are modified - double theta_temp = resid->compute_nlp_infeasib_onenorm(*it_trial, *_c_trial, *_d_trial); + [[maybe_unused]] const double theta_temp = resid->compute_nlp_infeasib_onenorm(*it_trial, *_c_trial, *_d_trial); } // end of if elastic_mode_on return true; @@ -777,8 +777,8 @@ void hiopAlgFilterIPMBase::getDualSolutions(double* zl_a, double* zu_a, double* if(solver_status_==NlpSolve_Pending) { nlp->log->printf(hovWarning, "getSolution: HiOp has not completed yet and solution returned may not be optimal."); } - hiopVector& zl = *it_curr->get_zl(); - hiopVector& zu = *it_curr->get_zu(); + [[maybe_unused]] hiopVector& zl = *it_curr->get_zl(); + [[maybe_unused]] hiopVector& zu = *it_curr->get_zu(); nlp->get_dual_solutions(*it_curr, zl_a, zu_a, lambda_a); } @@ -1307,7 +1307,7 @@ hiopSolveStatus hiopAlgFilterIPMQuasiNewton::run() num_adjusted_slacks); nlp->adjust_bounds(*it_trial); //compute infeasibility theta at trial point, since bounds changed --- note that the returned value won't change - double theta_temp = resid->compute_nlp_infeasib_onenorm(*it_trial, *_c_trial, *_d_trial); + [[maybe_unused]] const double theta_temp = resid->compute_nlp_infeasib_onenorm(*it_trial, *_c_trial, *_d_trial); #ifndef NDEBUG if(0==use_soc) { // TODO: check why this assertion fails @@ -2278,7 +2278,7 @@ hiopSolveStatus hiopAlgFilterIPMNewton::run() num_adjusted_slacks); nlp->adjust_bounds(*it_trial); //compute infeasibility theta at trial point, since bounds changed --- note that the returned value won't change - double theta_temp = resid->compute_nlp_infeasib_onenorm(*it_trial, *_c_trial, *_d_trial); + [[maybe_unused]] const double theta_temp = resid->compute_nlp_infeasib_onenorm(*it_trial, *_c_trial, *_d_trial); #ifndef NDEBUG if(0==use_soc) { // TODO: check why this assertion fails @@ -2905,7 +2905,7 @@ bool hiopAlgFilterIPMBase::solve_soft_feasibility_restoration(hiopKKTLinSys* kkt double kkt_err_trial; double alpha_primal_soft; double alpha_dual_soft; - double infeas_nrm_soft; + double infeas_nrm_soft=0; // to avoid uninitialized use below bool bret = false; @@ -2921,7 +2921,7 @@ bool hiopAlgFilterIPMBase::solve_soft_feasibility_restoration(hiopKKTLinSys* kkt //evaluate the problem at the trial iterate (functions only) if(!this->evalNlp_funcOnly(*it_trial, _f_nlp_trial, *_c_trial, *_d_trial)) { solver_status_ = Error_In_User_Function; - return Error_In_User_Function; + return true; } // compute rhs for soft feasibility restoration. Use resid_trial since it hasn't been used resid_trial->update(*it_trial, _f_nlp_trial, *_c_trial, *_d_trial, *_grad_f,*_Jac_c,*_Jac_d, *logbar); @@ -2943,7 +2943,7 @@ bool hiopAlgFilterIPMBase::solve_soft_feasibility_restoration(hiopKKTLinSys* kkt //evaluate the problem at the trial iterate (functions only) if(!this->evalNlp_funcOnly(*it_trial, _f_nlp_trial, *_c_trial, *_d_trial)) { solver_status_ = Error_In_User_Function; - return Error_In_User_Function; + return true; } //update and adjust the duals @@ -3023,7 +3023,7 @@ bool hiopAlgFilterIPMBase::compute_search_direction_inertia_free(hiopKKTLinSys* const int iter_num) { size_type num_refact = 0; - const size_t max_refactorization = 10; + const size_t max_refactorization = 10u; while(true) { @@ -3061,9 +3061,9 @@ bool hiopAlgFilterIPMBase::compute_search_direction_inertia_free(hiopKKTLinSys* if(kkt->test_direction(dir, _Hess_Lagr)) { break; } else { - if(num_refact >= max_refactorization) { + if(static_cast(num_refact) >= max_refactorization) { nlp->log->printf(hovError, - "Reached max number (%d) of refactorization within an outer iteration.\n", + "Reached max number (%lu) of refactorization within an outer iteration.\n", max_refactorization); return false; } diff --git a/src/Optimization/hiopAlgPrimalDecomp.cpp b/src/Optimization/hiopAlgPrimalDecomp.cpp index c91ff5df3..9b3eea835 100644 --- a/src/Optimization/hiopAlgPrimalDecomp.cpp +++ b/src/Optimization/hiopAlgPrimalDecomp.cpp @@ -205,10 +205,10 @@ HessianApprox(hiopInterfacePriDecProblem* priDecProb, hiopAlgPrimalDecomposition::HessianApprox:: HessianApprox(const int& n, - hiopInterfacePriDecProblem* priDecProb, + [[maybe_unused]] hiopInterfacePriDecProblem* priDecProb, hiopOptions* options_pridec, MPI_Comm comm_world) - : priDecProb_(priDecProb), options_(options_pridec), comm_world_(comm_world) + : options_(options_pridec), comm_world_(comm_world) { n_=n; fkm1 = 1e20; @@ -561,8 +561,8 @@ set_alpha_max(const double alp_max) hiopAlgPrimalDecomposition:: hiopAlgPrimalDecomposition(hiopInterfacePriDecProblem* prob_in, MPI_Comm comm_world/*=MPI_COMM_WORLD*/) - : master_prob_(prob_in), - comm_world_(comm_world) + : comm_world_(comm_world), + master_prob_(prob_in) { S_ = master_prob_->get_num_rterms(); n_ = master_prob_->get_num_vars(); @@ -618,9 +618,9 @@ hiopAlgPrimalDecomposition(hiopInterfacePriDecProblem* prob_in, const int nc, const int* xc_index, MPI_Comm comm_world/*=MPI_COMM_WORLD*/) - : master_prob_(prob_in), - nc_(nc), - comm_world_(comm_world) + : comm_world_(comm_world), + master_prob_(prob_in), + nc_(nc) { S_ = master_prob_->get_num_rterms(); n_ = master_prob_->get_num_vars(); @@ -821,7 +821,6 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) hiopVector* hess_appx = grad_r->alloc_clone(); hess_appx->setToZero(); - double* hess_appx_vec = hess_appx->local_data(); hiopVector* x0 = grad_r->alloc_clone(); x0->setToZero(); @@ -913,11 +912,11 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) grad_r->setToZero(); std::vector cont_idx(S_); - for(int i=0; i(S_); i++) { cont_idx[i] = i; } // The number of contigencies/recourse problems should be larger than the number of processors - assert(S_>=comm_size_-1); + assert(static_cast(S_)>=comm_size_-1); // idx is the next contingency to be sent out from the master int idx = 0; // Initilize the recourse communication by sending indices to the evaluator @@ -929,12 +928,10 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) // log_->printf(hovIteration, "rank %d to get contingency index %d\n", r, cur_idx); //verbosity level 10 idx += 1; } - int mpi_test_flag; // for testing if the send/recv is completed // Posting initial receive of recourse solutions from evaluators for(int r=1; rpost_recv(2,r,comm_world_);// 2 is the tag, r is the rank source - // log_->printf(hovIteration, "receive flag for contingency value %d\n", mpi_test_flag); } // Both finish_flag and last_loop are used to deal with the final round remaining contingencies/recourse problems. // Some ranks are finished while others are not. The loop needs to continue to fetch the results. @@ -950,25 +947,25 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) log_->printf(hovFcnEval, "Elapsed time for entire iteration %d is %f\n",it, t2 - t1); - while(idx<=S_ || last_loop) { + while(idx<=static_cast(S_) || last_loop) { for(int r=1; r< comm_size_;r++) { int mpi_test_flag = rec_prob[r]->test(); if(mpi_test_flag && (finish_flag[r]==0)) {// receive completed - if(!last_loop && idx(S_)) { log_->printf(hovLinesearch, "idx %d sent to rank %d\n", idx,r); } else { log_->printf(hovLinesearch, "last loop for rank %d\n", r ); } // add to the master rank variables rval += rec_prob[r]->value(); - for(int i=0;i(nc_);i++) { grad_r_vec[i] += rec_prob[r]->grad(i); } if(last_loop) { finish_flag[r]=1; } // this is for dealing with the end of contingencies where some ranks have already finished - if(idx(S_)) { req_cont_idx[r]->wait(); // Ensure previous cont idx send has completed. req_cont_idx[r]->set_idx(cont_idx[idx]); req_cont_idx[r]->post_send(1,r,comm_world_); @@ -996,7 +993,6 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) rval /= S_; grad_r->scale(1.0/S_); // send end signal to all evaluators - int cur_idx = -1; for(int r=1; rwait(); // Ensure previous idx send has completed. req_cont_idx[r]->set_idx(-1); @@ -1034,7 +1030,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) assert(nc_==n_); x0->copyFromStarting(0, *x_); } - for(int ri=0; ri(cont_idx.size()); ri++) { aux = 0.; int idx_temp = cont_idx[ri]; @@ -1048,7 +1044,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) grad_aux->setToZero(); - for(int ri=0; ri(cont_idx.size()); ri++) { int idx_temp = cont_idx[ri]; bret = master_prob_->eval_grad_rterm(idx_temp, nc_, x0_vec, *grad_aux); if(!bret) { @@ -1070,7 +1066,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) */ if(mpi_test_flag) { // log_->printf(hovIteration, "contingency index %d, rank %d)\n", cont_idx[0],my_rank_); - for(int ri=0; ri(cont_idx.size()); ri++) { cont_idx[ri] = req_cont_idx[my_rank_]->value(); } if(cont_idx[0]==-1) { @@ -1086,7 +1082,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) assert(nc_==n_); x0->copyFromStarting(0, *x_); } - for(int ri=0; ri(cont_idx.size()); ri++) { aux = 0.; int idx_temp = cont_idx[ri]; @@ -1099,7 +1095,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) // log_->printf(hovFcnEval, "recourse value: is %18.12e)\n", rec_val); grad_aux->setToZero(); - for(int ri=0; ri(cont_idx.size()); ri++) { int idx_temp = cont_idx[ri]; bret = master_prob_->eval_grad_rterm(idx_temp, nc_, x0_vec, *grad_aux); if(!bret) { @@ -1124,7 +1120,6 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) } if(my_rank_==0) { - int mpi_test_flag = 0; for(int r=1; rwait(); req_cont_idx[r]->wait(); @@ -1143,7 +1138,6 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) recourse_val = rval; log_->printf(hovSummary, "real rval %18.12e\n", rval); - MPI_Status mpi_status; hess_appx->setToConstant(1.0); @@ -1308,7 +1302,6 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) double* grad_r_main_vec=grad_r_main->local_data(); hiopVector* hess_appx = grad_r->alloc_clone(); - double* hess_appx_vec = hess_appx->local_data(); hess_appx->setToZero(); hiopVector* x0 = grad_r->alloc_clone(); @@ -1403,11 +1396,11 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) // array for number of indices, currently the indices are in [0,S_] std::vector cont_idx(S_); - for(int i=0; i(S_); i++) { cont_idx[i] = i; } // The number of contigencies/recourse problems should be larger than the number of processors - assert(S_>=comm_size_-1); + assert(static_cast(S_)>=comm_size_-1); // idx is the next contingency to be sent out from the master int idx = 0; // Initilize the recourse communication by sending indices to the evaluator @@ -1419,12 +1412,10 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) // log_->printf(hovIteration, "rank %d to get contingency index %d\n", r, cur_idx); //verbosity level 10 idx += 1; } - int mpi_test_flag; // for testing if the send/recv is completed // Posting initial receive of recourse solutions from evaluators for(int r=1; rpost_recv(2,r,comm_world_);// 2 is the tag, r is the rank source rec_prob[r]->post_recv_end_signal(2,r,comm_world_);// 2 is the tag, r is the rank source - // log_->printf(hovIteration, "receive flag for contingency value %d\n", mpi_test_flag); } // Both finish_flag and last_loop are used to deal with the final round remaining contingencies/recourse problems. // Some ranks are finished while others are not. The loop needs to continue to fetch the results. @@ -1440,11 +1431,11 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) log_->printf(hovFcnEval, "Elapsed time for entire iteration %d is %f\n",it, t2 - t1); - while(idx<=S_ || last_loop) { + while(idx<=static_cast(S_) || last_loop) { for(int r=1; r< comm_size_; r++) { int mpi_test_flag = rec_prob[r]->test(); if(mpi_test_flag && (finish_flag[r]==0)) {// receive completed - if(!last_loop && idx(S_)) { log_->printf(hovLinesearch, "idx %d sent to rank %d\n", idx,r); } else { log_->printf(hovLinesearch, "last loop for rank %d\n", r ); @@ -1462,7 +1453,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) finish_flag[r]=1; } // this is for dealing with the end of contingencies where some ranks have already finished - if(idx(S_)) { req_cont_idx[r]->wait(); // Ensure previous send has completed. req_cont_idx[r]->set_idx(cont_idx[idx]); req_cont_idx[r]->post_send(1,r,comm_world_); @@ -1492,7 +1483,6 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) //rval /= S_; //grad_r->scale(1.0/S_); // send end signal to all evaluators - int cur_idx = -1; for(int r=1; rwait(); // Ensure previous send has completed. req_cont_idx[r]->set_idx(-1); @@ -1532,7 +1522,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) assert(nc_==n_); x0->copyFromStarting(0, *x_); } - for(int ri=0; ri(cont_idx.size()); ri++) { aux = 0.; int idx_temp = cont_idx[ri]; @@ -1547,7 +1537,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) // log_->printf(hovFcnEval, "recourse value: is %18.12e)\n", rec_val); grad_aux->setToZero(); - for(int ri=0; ri(cont_idx.size()); ri++) { int idx_temp = cont_idx[ri]; bret = master_prob_->eval_grad_rterm(idx_temp, nc_, x0_vec, *grad_aux); if(!bret) { @@ -1575,7 +1565,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) */ if(mpi_test_flag) { // log_->printf(hovIteration, "contingency index %d, rank %d)\n", cont_idx[0],my_rank_); - for(int ri=0; ri(cont_idx.size()); ri++) { cont_idx[ri] = req_cont_idx[my_rank_]->value(); } if(cont_idx[0]==-1) { @@ -1593,7 +1583,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) assert(nc_==n_); x0->copyFromStarting(0, *x_); } - for(int ri=0; ri(cont_idx.size()); ri++) { aux = 0.; int idx_temp = cont_idx[ri]; @@ -1607,7 +1597,7 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) // log_->printf(hovFcnEval, "recourse value: is %18.12e)\n", rec_val); grad_aux->setToZero(); - for(int ri=0; ri(cont_idx.size()); ri++) { int idx_temp = cont_idx[ri]; bret = master_prob_->eval_grad_rterm(idx_temp, nc_, x0_vec, *grad_aux); if(!bret) { @@ -1638,10 +1628,9 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) if(my_rank_==0) { assert(rval == 0); - for(int i=0; i(nc_); i++ ) { assert(grad_r_vec[i] == 0.); } - int mpi_test_flag = 0; for(int r=1; rwait(); req_cont_idx[r]->wait(); @@ -1673,8 +1662,6 @@ void hiopAlgPrimalDecomposition::set_local_accum(const std::string local_accum) log_->printf(hovSummary, "real rval %18.12e\n", rval); - MPI_Status mpi_status; - hess_appx->setToConstant(1.0); if(nc_setToZero(); bool bret; - int rank_master=0; //master rank is also the solver rank // Define the values and gradients as needed in the master rank double rval = 0.; // double grad_r[nc_]; hiopVector* grad_r; grad_r = LinearAlgebraFactory::create_vector(options_->GetString("mem_space"), nc_) ; - double* grad_r_vec = grad_r->local_data(); hiopVector* hess_appx; hess_appx = grad_r->alloc_clone(); - double* hess_appx_vec=hess_appx->local_data(); hiopVector* x0 = grad_r->alloc_clone(); double* x0_vec = x0->local_data(); @@ -1854,7 +1838,6 @@ hiopSolveStatus hiopAlgPrimalDecomposition::run_single() double convg_f = 1e20; double convg_g = 1e20; int accp_count = 0; - double* x_vec = x_->local_data(); std::string options_file_master_prob; @@ -1879,12 +1862,11 @@ hiopSolveStatus hiopAlgPrimalDecomposition::run_single() grad_r->setToZero(); std::vector cont_idx(S_); - for(int i=0; i(S_); i++) { cont_idx[i] = i; } // The number of contigencies should be larger than the number of processors, which is 1 // idx is the next contingency to be sent out from the master - int idx = 0; if(nc_copy_from_indexes(*x_, *xc_idx_); @@ -1892,7 +1874,7 @@ hiopSolveStatus hiopAlgPrimalDecomposition::run_single() assert(nc_==n_); x0->copyFromStarting(0, *x_); } - for(int i=0; i< S_;i++) { + for(int i=0; i< static_cast(S_);i++) { int idx_temp = cont_idx[i]; double aux=0.; bret = master_prob_->eval_f_rterm(idx_temp, nc_, x0_vec, aux); //need to add extra time here diff --git a/src/Optimization/hiopAlgPrimalDecomp.hpp b/src/Optimization/hiopAlgPrimalDecomp.hpp index 48306663c..fee5bcd13 100644 --- a/src/Optimization/hiopAlgPrimalDecomp.hpp +++ b/src/Optimization/hiopAlgPrimalDecomp.hpp @@ -379,7 +379,6 @@ class hiopAlgPrimalDecomposition hiopVector* skm1; /// xk-xkm1 hiopVector* ykm1; /// gk-gkm1 size_t ver_ = 2; //output level for HessianApprox class, being phased out. - hiopInterfacePriDecProblem* priDecProb_; hiopOptions* options_; /// options is given by on pridec options. hiopLogger* log_; MPI_Comm comm_world_; @@ -439,9 +438,6 @@ class hiopAlgPrimalDecomposition double alpha_min_ = 1e-5; double alpha_max_ = 1e6; - /// real decrease over expected decrease ratio - double rhok_ = 0.; - protected: hiopOptions* options_; hiopLogger* log_; diff --git a/src/Optimization/hiopDualsUpdater.cpp b/src/Optimization/hiopDualsUpdater.cpp index 73e2917a0..510fae0cf 100644 --- a/src/Optimization/hiopDualsUpdater.cpp +++ b/src/Optimization/hiopDualsUpdater.cpp @@ -363,8 +363,8 @@ instantiate_linear_solver(const char* linsol_opt, size_type nd=Jac_dSp.m(); size_type neq=Jac_cSp.m(); size_type nineq=Jac_dSp.m(); - size_type n = nx + nineq + neq + nineq; - size_type nnz = nx + nd + Jac_cSp.numberOfNonzeros() + Jac_dSp.numberOfNonzeros() + nd + (nx + nd + neq + nineq); + [[maybe_unused]] const size_type n = nx + nineq + neq + nineq; + [[maybe_unused]] const size_type nnz = nx + nd + Jac_cSp.numberOfNonzeros() + Jac_dSp.numberOfNonzeros() + nd + (nx + nd + neq + nineq); auto linear_solver = nlp_->options->GetString(linsol_opt); auto compute_mode = nlp_->options->GetString("compute_mode"); @@ -552,9 +552,6 @@ bool hiopDualsLsqUpdateLinsysAugSparse::do_lsq_update(hiopIterate& iter, std::stringstream ss_log; int nx = Jac_cSp.n(), nd=Jac_dSp.m(), neq=Jac_cSp.m(), nineq=Jac_dSp.m(); - int n = nx + nineq + neq + nineq; - - int nnz = nx + nd + Jac_cSp.numberOfNonzeros() + Jac_dSp.numberOfNonzeros() + nd + (nx + nd + neq + nineq); t.reset(); t.start(); diff --git a/src/Optimization/hiopFRProb.cpp b/src/Optimization/hiopFRProb.cpp index 031d555fa..d9039ccd7 100644 --- a/src/Optimization/hiopFRProb.cpp +++ b/src/Optimization/hiopFRProb.cpp @@ -591,7 +591,6 @@ bool hiopFRProbSparse::iterate_callback(int iter, if(nrmInf_feas_ori <= max_nrmInf_feas && iter>0) { // termination condition 2) (theta and logbar) are not in the original filter // check (original) filter condition - double trial_obj_ori = obj_base_; // obj_base_ has been updated in the FR loop when we evaluate obj // compute the original logbar objective from the trial point given by the FR problem // Note that this function will updates the slack and dual variables @@ -603,7 +602,7 @@ bool hiopFRProbSparse::iterate_callback(int iter, it_base_trial->get_d()->copyFrom(*wrk_d_); // compute other slacks in the base problem - size_type n_adjusted_slacks = it_base_trial->compute_safe_slacks(*it_base_curr, solver_base_.get_mu()); + [[maybe_unused]] const size_type n_adjusted_slacks = it_base_trial->compute_safe_slacks(*it_base_curr, solver_base_.get_mu()); // evaluate base problem log barr solver_base_.get_logbar()->updateWithNlpInfo_trial_funcOnly(*it_base_trial, obj_base_, *wrk_cbody_, *wrk_dbody_); @@ -1224,7 +1223,6 @@ bool hiopFRProbMDS::iterate_callback(int iter, if(nrmInf_feas_ori <= max_nrmInf_feas && iter>0) { // termination condition 2) (theta and logbar) are not in the original filter // check (original) filter condition - double trial_obj_ori = obj_base_; // obj_base_ has been updated in the FR loop when we evaluate obj // compute the original logbar objective from the trial point given by the FR problem // Note that this function will updates the slack and dual variables @@ -1236,7 +1234,7 @@ bool hiopFRProbMDS::iterate_callback(int iter, it_base_trial->get_d()->copyFrom(*wrk_d_); // compute other slacks in the base problem - size_type n_adjusted_slacks = it_base_trial->compute_safe_slacks(*it_base_curr, solver_base_.get_mu()); + [[maybe_unused]] const size_type n_adjusted_slacks = it_base_trial->compute_safe_slacks(*it_base_curr, solver_base_.get_mu()); // evaluate base problem log barr solver_base_.get_logbar()->updateWithNlpInfo_trial_funcOnly(*it_base_trial, obj_base_, *wrk_cbody_, *wrk_dbody_); @@ -1548,7 +1546,6 @@ bool hiopFRProbDense::get_vars_info(const size_type& n, double *xlow, double* xu const hiopVector& xl = nlp_base_->get_xl(); const hiopVector& xu = nlp_base_->get_xu(); - const NonlinearityType* var_type = nlp_base_->get_var_type(); // x, p and n, in the order of [x pe ne pi ni] @@ -1577,8 +1574,6 @@ bool hiopFRProbDense::get_cons_info(const size_type& m, double* clow, double* cu const hiopVector& crhs = nlp_base_->get_crhs(); const hiopVector& dl = nlp_base_->get_dl(); const hiopVector& du = nlp_base_->get_du(); - const NonlinearityType* cons_eq_type = nlp_base_->get_cons_eq_type(); - const NonlinearityType* cons_ineq_type = nlp_base_->get_cons_ineq_type(); wrk_dual_->setToConstant(0.0); @@ -1932,7 +1927,7 @@ bool hiopFRProbDense::iterate_callback(int iter, if(nrmInf_feas_ori <= max_nrmInf_feas && iter>0) { // termination condition 2) (theta and logbar) are not in the original filter // check (original) filter condition - double trial_obj_ori = obj_base_; // obj_base_ has been updated in the FR loop when we evaluate obj + [[maybe_unused]] double trial_obj_ori = obj_base_; // obj_base_ has been updated in the FR loop when we evaluate obj // compute the original logbar objective from the trial point given by the FR problem // Note that this function will updates the slack and dual variables @@ -1944,7 +1939,7 @@ bool hiopFRProbDense::iterate_callback(int iter, it_base_trial->get_d()->copyFrom(*wrk_d_); // compute other slacks in the base problem - size_type n_adjusted_slacks = it_base_trial->compute_safe_slacks(*it_base_curr, solver_base_.get_mu()); + [[maybe_unused]] size_type n_adjusted_slacks = it_base_trial->compute_safe_slacks(*it_base_curr, solver_base_.get_mu()); // evaluate base problem log barr solver_base_.get_logbar()->updateWithNlpInfo_trial_funcOnly(*it_base_trial, obj_base_, *wrk_cbody_, *wrk_dbody_); diff --git a/src/Optimization/hiopHessianLowRank.cpp b/src/Optimization/hiopHessianLowRank.cpp index 4f03fa336..a18af6d9b 100644 --- a/src/Optimization/hiopHessianLowRank.cpp +++ b/src/Optimization/hiopHessianLowRank.cpp @@ -886,9 +886,9 @@ hiopMatrixDense& hiopHessianLowRank::new_kxl_mat1(int k, int l) hiopMatrixDense& hiopHessianLowRank::new_S1(const hiopMatrixDense& X, const hiopMatrixDense& St) { //S1 is X*some_diag*S (kxl). Here St=S^T is lxn and X is kxn (l BFGS memory size, k number of constraints) - size_type k=X.m(), n=St.n(), l=St.m(); + size_type k=X.m(), l=St.m(); #ifdef HIOP_DEEPCHECKS - assert(n==X.n()); + assert(St.n()==X.n()); if(_S1!=NULL) assert(_S1->m()==k); #endif @@ -902,9 +902,9 @@ hiopMatrixDense& hiopHessianLowRank::new_S1(const hiopMatrixDense& X, const hiop hiopMatrixDense& hiopHessianLowRank::new_Y1(const hiopMatrixDense& X, const hiopMatrixDense& Yt) { //Y1 is X*somediag*Y (kxl). Here Yt=Y^T is lxn, X is kxn - size_type k=X.m(), n=Yt.n(), l=Yt.m(); + size_type k=X.m(), l=Yt.m(); #ifdef HIOP_DEEPCHECKS - assert(X.n()==n); + assert(X.n()==Yt.n()); if(_Y1!=NULL) assert(_Y1->m()==k); #endif @@ -1032,14 +1032,13 @@ symmMatTimesDiagTimesMatTrans_local(double beta, hiopMatrixDense& W, const hiopVector& d) { size_type k=W.m(); - size_type n=X.n(); - size_t n_local=X.get_local_size_n(); + size_type n_local=X.get_local_size_n(); assert(X.m()==k); #ifdef HIOP_DEEPCHECKS assert(W.n()==k); - assert(d.get_size()==n); + assert(d.get_size()==X.n()); assert(d.get_local_size()==n_local); #endif @@ -1052,12 +1051,12 @@ symmMatTimesDiagTimesMatTrans_local(double beta, hiopMatrixDense& W, for(int i=0; in()==k); @@ -1682,8 +1681,9 @@ hiopMatrixDense& hiopHessianInvLowRank_obsolette::new_S1(const hiopMatrixDense& hiopMatrixDense& hiopHessianInvLowRank_obsolette::new_Y1(const hiopMatrixDense& Yt, const hiopMatrixDense& X) { //Y1 is Yt*H0*X^T = Y^T*H0*X^T, where Y^T is lxn, H0 is diag nxn, X is kxn - size_type k=X.m(), n=Yt.n(), l=Yt.m(); + size_type k=X.m(), l=Yt.m(); #ifdef HIOP_DEEPCHECKS + const size_type n=Yt.n(); assert(X.n()==n); if(_Y1!=NULL) assert(_Y1->n()==k); #endif diff --git a/src/Optimization/hiopKKTLinSys.cpp b/src/Optimization/hiopKKTLinSys.cpp index bd2265ced..12e265003 100644 --- a/src/Optimization/hiopKKTLinSys.cpp +++ b/src/Optimization/hiopKKTLinSys.cpp @@ -557,7 +557,6 @@ bool hiopKKTLinSysCompressedXYcYd::update(const hiopIterate* iter, int nx = Hess_->m(); assert(nx==Hess_->n()); assert(nx==Jac_c_->n()); assert(nx==Jac_d_->n()); - int neq = Jac_c_->m(), nineq = Jac_d_->m(); //compute and put the barrier diagonals in //Dx=(Sxl)^{-1}Zl + (Sxu)^{-1}Zu @@ -685,10 +684,10 @@ bool hiopKKTLinSysCompressedXYcYd::computeDirections(const hiopResidual* resid, return false; } - bool bret = compute_directions_for_full_space(resid, dir); + const bool bret = compute_directions_for_full_space(resid, dir); nlp_->runStats.tmSolverInternal.stop(); - return true; + return bret; } #ifdef HIOP_DEEPCHECKS @@ -790,7 +789,6 @@ bool hiopKKTLinSysCompressedXDYcYd::update( const hiopIterate* iter, Hess_=Hess; int nx = Hess_->m(); assert(nx==Hess_->n()); assert(nx==Jac_c_->n()); assert(nx==Jac_d_->n()); - int neq = Jac_c_->m(), nineq = Jac_d_->m(); // compute barrier diagonals (these change only between outer optimiz iterations) // Dx=(Sxl)^{-1}Zl + (Sxu)^{-1}Zu @@ -903,10 +901,10 @@ bool hiopKKTLinSysCompressedXDYcYd::computeDirections(const hiopResidual* resid, return false; } - bool bret = compute_directions_for_full_space(resid, dir); + const bool bret = compute_directions_for_full_space(resid, dir); nlp_->runStats.tmSolverInternal.stop(); - return true; + return bret; } @@ -922,10 +920,10 @@ bool hiopKKTLinSys::compute_directions_w_IR(const hiopResidual* resid, hiopItera const hiopResidual &r=*resid; // in the order of rx, rd, ryc, ryd, rxl, rxu, rdl, rdu, rszl, rszu, rsvl, rsvu - const size_type nx = resid->rx->get_local_size(); - const size_type nd = resid->rd->get_local_size(); - const size_type nyc = resid->ryc->get_local_size(); - const size_type nyd = resid->ryd->get_local_size(); + const size_type nx = r.rx->get_local_size(); + const size_type nd = r.rd->get_local_size(); + const size_type nyc = r.ryc->get_local_size(); + const size_type nyd = r.ryd->get_local_size(); size_type dim_rhs = 5*nx + 5*nd + nyc + nyd; /*********************************************************************** * solve the compressed system as a preconditioner @@ -1509,7 +1507,6 @@ errorCompressedLinsys(const hiopVector& rx, const hiopVector& ryc, const hiopVec double hiopKKTLinSysLowRank::solveError(const hiopMatrixDense& M, const hiopVector& x, hiopVector& rhs) { double relError; - double rhsnorm=rhs.infnorm(); M.timesVec(1.0,rhs,-1.0,x); double resnorm=rhs.infnorm(); @@ -1905,11 +1902,11 @@ bool hiopPrecondKKTOpr::times_vec(hiopVector& y, const hiopVector& x) { res_cv_->copyFrom(x); - bool bret = kkt_->computeDirections(resid_, dir_); + const bool bret = kkt_->computeDirections(resid_, dir_); y.copyFrom(*dir_cv_); - return true; + return bret; } bool hiopPrecondKKTOpr::trans_times_vec(hiopVector& y, const hiopVector& x) @@ -1959,8 +1956,6 @@ bool hiopKKTLinSysNormalEquation::update(const hiopIterate* iter, Hess_ = Hess; size_type nx = Hess_->m(); - size_type neq = Jac_c_->m(); - size_type nineq = Jac_d_->m(); assert(nx==Hess_->n()); assert(nx==Jac_c_->n()); assert(nx==Jac_d_->n()); @@ -2100,10 +2095,10 @@ bool hiopKKTLinSysNormalEquation::computeDirections(const hiopResidual* resid, h return false; } - bool bret = compute_directions_for_full_space(resid, dir); + const bool bret = compute_directions_for_full_space(resid, dir); nlp_->runStats.tmSolverInternal.stop(); - return true; + return bret; } diff --git a/src/Optimization/hiopKKTLinSys.hpp b/src/Optimization/hiopKKTLinSys.hpp index 56e98e9a3..9fde1343e 100644 --- a/src/Optimization/hiopKKTLinSys.hpp +++ b/src/Optimization/hiopKKTLinSys.hpp @@ -250,8 +250,8 @@ class hiopKKTLinSysCompressed : public hiopKKTLinSysCurvCheck hiopKKTLinSysCompressed(hiopNlpFormulation* nlp) : hiopKKTLinSysCurvCheck(nlp), Dx_(nullptr), - rx_tilde_(nullptr), Dd_(nullptr), + rx_tilde_(nullptr), x_wrk_(nullptr), d_wrk_(nullptr) { diff --git a/src/Optimization/hiopKKTLinSysMDS.cpp b/src/Optimization/hiopKKTLinSysMDS.cpp index 6b8c15d2d..40830c13a 100644 --- a/src/Optimization/hiopKKTLinSysMDS.cpp +++ b/src/Optimization/hiopKKTLinSysMDS.cpp @@ -59,9 +59,9 @@ namespace hiop hiopKKTLinSysCompressedMDSXYcYd::hiopKKTLinSysCompressedMDSXYcYd(hiopNlpFormulation* nlp) : hiopKKTLinSysCompressedXYcYd(nlp), rhs_(NULL), _buff_xs_(NULL), - Hxs_(NULL), HessMDS_(NULL), Jac_cMDS_(NULL), Jac_dMDS_(NULL), - write_linsys_counter_(-1), csr_writer_(nlp), - Hxs_wrk_(nullptr) + Hxs_(NULL), Hxs_wrk_(nullptr), + HessMDS_(NULL), Jac_cMDS_(NULL), Jac_dMDS_(NULL), + write_linsys_counter_(-1), csr_writer_(nlp) { nlpMDS_ = dynamic_cast(nlp_); assert(nlpMDS_); @@ -77,8 +77,6 @@ namespace hiop int hiopKKTLinSysCompressedMDSXYcYd::factorizeWithCurvCheck() { - int nxs = HessMDS_->n_sp(), nxd = HessMDS_->n_de(), nx = HessMDS_->n(); - int neq = Jac_cMDS_->m(), nineq = Jac_dMDS_->m(); //factorization int n_neg_eig = hiopKKTLinSysCurvCheck::factorizeWithCurvCheck(); @@ -164,10 +162,10 @@ namespace hiop // //factorization + inertia correction if needed // - bool retval = factorize(); + const bool retval = factorize(); nlp_->runStats.tmSolverInternal.stop(); - return true; + return retval; } @@ -182,7 +180,7 @@ namespace hiop delta_cc_ = perturb_calc_->get_curr_delta_cc(); delta_cd_ = perturb_calc_->get_curr_delta_cd(); - int nxs = HessMDS_->n_sp(), nxd = HessMDS_->n_de(), nx = HessMDS_->n(); + int nxs = HessMDS_->n_sp(), nxd = HessMDS_->n_de(); int neq = Jac_cMDS_->m(), nineq = Jac_dMDS_->m(); hiopMatrixDense& Msys = linSys->sysMatrix(); @@ -406,9 +404,8 @@ namespace hiop hiopLinSolverSymDense* hiopKKTLinSysCompressedMDSXYcYd::determineAndCreateLinsys(int nxd, int neq, int nineq) { - +#ifdef HIOP_USE_MAGMA bool switched_linsolvers = false; -#ifdef HIOP_USE_MAGMA if(safe_mode_) { hiopLinSolverSymDenseMagmaBuKa* p = dynamic_cast(linSys_); if(p==NULL) { diff --git a/src/Optimization/hiopKKTLinSysSparse.cpp b/src/Optimization/hiopKKTLinSysSparse.cpp index 5ff1e20b7..c41a8579a 100644 --- a/src/Optimization/hiopKKTLinSysSparse.cpp +++ b/src/Optimization/hiopKKTLinSysSparse.cpp @@ -890,7 +890,6 @@ namespace hiop size_type nxu = nlp_->n_upp(); // note that hess may be saved as a triangular matrix - int n1st = 0; int n2st = nx + neq + nineq; int n3st = n2st + nd; int n4st = n3st + ndl + ndu + nxl + nxu; // shortcut for each subbloock diff --git a/src/Optimization/hiopKKTLinSysSparseCondensed.cpp b/src/Optimization/hiopKKTLinSysSparseCondensed.cpp index 7578f8443..67b1d26d4 100644 --- a/src/Optimization/hiopKKTLinSysSparseCondensed.cpp +++ b/src/Optimization/hiopKKTLinSysSparseCondensed.cpp @@ -72,15 +72,15 @@ hiopKKTLinSysCondensedSparse::hiopKKTLinSysCondensedSparse(hiopNlpFormulation* n : hiopKKTLinSysCompressedSparseXDYcYd(nlp), JacD_(nullptr), JacDt_(nullptr), - JtDiagJ_(nullptr), Hess_lower_csr_(nullptr), Hess_upper_csr_(nullptr), Hess_csr_(nullptr), + JtDiagJ_(nullptr), M_condensed_(nullptr), Hess_upper_plus_diag_(nullptr), - deltawx_(nullptr), - Dx_plus_deltawx_(nullptr), Diag_Dx_deltawx_(nullptr), + Dx_plus_deltawx_(nullptr), + deltawx_(nullptr), Hd_copy_(nullptr) { } @@ -110,8 +110,6 @@ bool hiopKKTLinSysCondensedSparse::build_kkt_matrix(const hiopPDPerturbation& pd const hiopVector& delta_wx_in = *delta_wx_; const hiopVector& delta_wd_in = *delta_wd_; - const hiopVector& dcc = *delta_cc_; - const hiopVector& dcd = *delta_cd_; nlp_->runStats.kkt.tmUpdateInit.start(); @@ -300,7 +298,6 @@ bool hiopKKTLinSysCondensedSparse::build_kkt_matrix(const hiopPDPerturbation& pd //t.stop(); printf("ADD-symb took %.5f\n", t.getElapsedTime()); } else { - auto* lins_sys_sparse = dynamic_cast(linSys_); assert(linSys_); assert(M_condensed_); //todo assert(M_condensed_ == linSys_->sys_matrix()); @@ -360,8 +357,6 @@ bool hiopKKTLinSysCondensedSparse::solve_compressed_direct(hiopVector& rx, assert(0 == ryc.get_size() && "this KKT does not support equality constraints"); size_type nx = rx.get_size(); - size_type nd = rd.get_size(); - size_type nyd = ryd.get_size(); assert(rhs_); assert(rhs_->get_size() == nx); @@ -420,8 +415,6 @@ bool hiopKKTLinSysCondensedSparse::solveCompressed(hiopVector& rx, nlp_->runStats.kkt.tmSolveInner.start(); size_type nx = rx.get_size(); - size_type nd = rd.get_size(); - size_type nyd = ryd.get_size(); // this is rhs used by the direct "condensed" solve if(rhs_ == NULL) { diff --git a/src/Optimization/hiopKKTLinSysSparseNormalEqn.cpp b/src/Optimization/hiopKKTLinSysSparseNormalEqn.cpp index e7bffbc0e..a56553659 100644 --- a/src/Optimization/hiopKKTLinSysSparseNormalEqn.cpp +++ b/src/Optimization/hiopKKTLinSysSparseNormalEqn.cpp @@ -68,10 +68,6 @@ namespace hiop { hiopKKTLinSysSparseNormalEqn::hiopKKTLinSysSparseNormalEqn(hiopNlpFormulation* nlp) : hiopKKTLinSysNormalEquation(nlp), - nlpSp_{nullptr}, - HessSp_{nullptr}, - Jac_cSp_{nullptr}, - Jac_dSp_{nullptr}, rhs_{nullptr}, Hess_diag_{nullptr}, deltawx_{nullptr}, @@ -83,13 +79,17 @@ hiopKKTLinSysSparseNormalEqn::hiopKKTLinSysSparseNormalEqn(hiopNlpFormulation* n Hx_copy_{nullptr}, Hd_copy_{nullptr}, Hxd_inv_copy_{nullptr}, + write_linsys_counter_(-1), + csr_writer_(nlp), + nlpSp_{nullptr}, + HessSp_{nullptr}, + Jac_cSp_{nullptr}, + Jac_dSp_{nullptr}, JacD_{nullptr}, JacDt_{nullptr}, JDiagJt_{nullptr}, Diag_dualreg_{nullptr}, - M_normaleqn_{nullptr}, - write_linsys_counter_(-1), - csr_writer_(nlp) + M_normaleqn_{nullptr} { nlpSp_ = dynamic_cast(nlp_); assert(nlpSp_); @@ -151,8 +151,6 @@ bool hiopKKTLinSysSparseNormalEqn::build_kkt_matrix(const hiopPDPerturbation& pd assert(HessSp_->is_diagonal()); hiopMatrixSymSparseTriplet* Hess_triplet = dynamic_cast(Hess_); - const hiopMatrixSparseTriplet* Jac_c_triplet = dynamic_cast(Jac_c_); - const hiopMatrixSparseTriplet* Jac_d_triplet = dynamic_cast(Jac_d_); assert(HessSp_ && Jac_cSp_ && Jac_dSp_); if(nullptr==Jac_dSp_ || nullptr==HessSp_) { diff --git a/src/Optimization/hiopNlpFormulation.cpp b/src/Optimization/hiopNlpFormulation.cpp index 09d9a48c7..8de42371e 100644 --- a/src/Optimization/hiopNlpFormulation.cpp +++ b/src/Optimization/hiopNlpFormulation.cpp @@ -70,18 +70,14 @@ namespace hiop { hiopNlpFormulation::hiopNlpFormulation(hiopInterfaceBase& interface_, const char* option_file) + : #ifdef HIOP_USE_MPI - : mpi_init_called(false), - interface_base(interface_), - nlp_transformations_(this), + mpi_init_called(false), +#endif prob_type_(hiopInterfaceBase::hiopNonlinear), - nlp_evaluated_(false) -#else - : interface_base(interface_), + nlp_evaluated_(false), nlp_transformations_(this), - prob_type_(hiopInterfaceBase::hiopNonlinear), - nlp_evaluated_(false) -#endif + interface_base(interface_) { strFixedVars_ = ""; //uninitialized dFixedVarsTol_ = -1.; //uninitialized @@ -807,8 +803,6 @@ bool hiopNlpFormulation::get_starting_point(hiopVector& x0_for_hiop, slacks_avail, d_for_user); if(duals_avail) { - double* yc0d = yc0_for_hiop.local_data(); - double* yd0d = yd0_for_hiop.local_data(); assert(n_cons_eq_ == yc0_for_hiop.get_size() && "when did the cons change?"); assert(n_cons_ineq_ == yd0_for_hiop.get_size() && "when did the cons change?"); @@ -862,9 +856,6 @@ bool hiopNlpFormulation::get_warmstart_point(hiopVector& x0_for_hiop, vl_for_user, vu_for_user); { - double* yc0d = yc0_for_hiop.local_data(); - double* yd0d = yd0_for_hiop.local_data(); - assert(n_cons_eq_ == yc0_for_hiop.get_size() && "when did the cons change?"); assert(n_cons_ineq_ == yd0_for_hiop.get_size() && "when did the cons change?"); assert(n_cons_eq_+n_cons_ineq_ == n_cons_); @@ -1988,10 +1979,6 @@ bool hiopNlpSparse::eval_Hess_Lagr(const hiopVector& x, } assert(buf_lambda_); - const double* lambda_eq_arr = lambda_eq.local_data_const(); - const double* lambda_ineq_arr = lambda_ineq.local_data_const(); - double* buf_lambda_arr = buf_lambda_->local_data(); - buf_lambda_-> copy_from_two_vec_w_pattern(lambda_eq, *cons_eq_mapping_, lambda_ineq, *cons_ineq_mapping_); @@ -2001,7 +1988,7 @@ bool hiopNlpSparse::eval_Hess_Lagr(const hiopVector& x, double obj_factor_with_scale = obj_factor*get_obj_scale(); - int nnzHSS = pHessL->numberOfNonzeros(), nnzHSD = 0; + int nnzHSS = pHessL->numberOfNonzeros(); if(0==num_hess_eval_) { diff --git a/src/Optimization/hiopNlpFormulation.hpp b/src/Optimization/hiopNlpFormulation.hpp index 57a50adee..460f47906 100644 --- a/src/Optimization/hiopNlpFormulation.hpp +++ b/src/Optimization/hiopNlpFormulation.hpp @@ -405,8 +405,8 @@ class hiopNlpFormulation private: hiopNlpFormulation(const hiopNlpFormulation& s) - : interface_base(s.interface_base), - nlp_transformations_(this) + : nlp_transformations_(this), interface_base(s.interface_base) + {}; }; diff --git a/src/Optimization/hiopNlpTransforms.cpp b/src/Optimization/hiopNlpTransforms.cpp index 4d2577461..d97696b56 100644 --- a/src/Optimization/hiopNlpTransforms.cpp +++ b/src/Optimization/hiopNlpTransforms.cpp @@ -70,9 +70,10 @@ hiopFixedVarsRemover(hiopNlpFormulation* nlp, const size_type& numFixedVars_local) : hiopNlpTransformation(nlp), n_fixed_vars_local(numFixedVars_local), fixedVarTol(fixedVarTol_), - Jacc_fs(NULL), Jacd_fs(NULL), + Jacc_fs(nullptr), Jacd_fs(nullptr), + Jacc_rs_ref(nullptr), Jacd_rs_ref(nullptr), fs2rs_idx_map(xl.get_local_size()), - x_rs_ref_(nullptr), Jacc_rs_ref(NULL), Jacd_rs_ref(NULL) + x_rs_ref_(nullptr) { xl_fs = xl.new_copy(); xu_fs = xu.new_copy(); @@ -104,7 +105,7 @@ void hiopFixedVarsRemover::setFSVectorDistrib(index_type* vec_distrib_in, int nu /* allocates and returns the reduced-space column partitioning to be used internally by HiOp */ index_type* hiopFixedVarsRemover::allocRSVectorDistrib() { - size_t nlen = fs_vec_distrib.size(); //nlen==nranks+1 + size_type nlen = fs_vec_distrib.size(); //nlen==nranks+1 assert(nlen>=1); index_type* rsVecDistrib = new index_type[nlen]; rsVecDistrib[0]=0; @@ -133,12 +134,13 @@ index_type* hiopFixedVarsRemover::allocRSVectorDistrib() assert(nlen==1); #endif assert(rsVecDistrib[0]==0); + const int intNLEN(static_cast(nlen)); //then accumulate these - for(int r=1; r(fs2rs_idx_map.size())); apply_to_vector(&fsVec, &rsVec); } @@ -205,7 +207,8 @@ void hiopFixedVarsRemover:: copyFsToRs(const hiopInterfaceBase::NonlinearityType* fs, hiopInterfaceBase::NonlinearityType* rs) { int rs_idx; - for(int i=0; i(fs2rs_idx_map.size())); + for(int i=0; i=0) { rs[rs_idx] = fs[i]; @@ -220,7 +223,8 @@ void hiopFixedVarsRemover::apply_inv_to_vector(const hiopVector* vec_rs, hiopVec const double* vec_rs_arr = vec_rs->local_data_const(); double* vec_fs_arr = vec_fs->local_data(); int rs_idx; - for(int i=0; i(fs2rs_idx_map.size())); + for(int i=0; ilocal_data(); const double* vec_fs_arr = vec_fs->local_data_const(); int rs_idx; - for(int i=0; i=0) { vec_rs_arr[rs_idx]=vec_fs_arr[i]; @@ -248,7 +253,7 @@ void hiopFixedVarsRemover::apply_to_vector(const hiopVector* vec_fs, hiopVector* void hiopFixedVarsRemover::applyToMatrix(const double* M_rs, const int& m_in, double* M_fs) { int rs_idx; - const size_t nfs = fs2rs_idx_map.size(); + const int nfs = static_cast(fs2rs_idx_map.size()); assert(nfs == fs_n_local()); const int nrs = rs_n_local(); @@ -270,12 +275,12 @@ void hiopFixedVarsRemover::applyToMatrix(const double* M_rs, const int& m_in, do void hiopFixedVarsRemover::applyInvToMatrix(const double* M_fs, const int& m_in, double* M_rs) { int rs_idx; - const size_t nfs = fs2rs_idx_map.size(); + const int nfs = static_cast(fs2rs_idx_map.size()); assert(nfs == fs_n_local()); const int nrs = rs_n_local(); for(int i=0; i=0) { M_rs[i*nrs+rs_idx] = M_fs[i*nfs+j]; @@ -306,7 +311,7 @@ hiopFixedVarsRelaxer::~hiopFixedVarsRelaxer() void hiopFixedVarsRelaxer:: relax(const double& fixed_var_tol, const double& fixed_var_perturb, hiopVector& xl, hiopVector& xu) { - double *xla=xl.local_data(), *xua=xu.local_data(), *v; + double *xla=xl.local_data(), *xua=xu.local_data(); size_type n=xl.get_local_size(); double xuabs; for(index_type i=0; ioptions->GetNumeric("scaling_max_grad"); const double min_grad = nlp_->options->GetNumeric("scaling_min_grad"); @@ -463,10 +468,6 @@ hiopNLPObjGradScaling::hiopNLPObjGradScaling(hiopNlpFormulation* nlp, scale_factor_d->component_max(1.0); scale_factor_d->invert(); - const double* eq_arr = scale_factor_c->local_data_const(); - const double* ineq_arr = scale_factor_d->local_data_const(); - double* scale_factor_cd_arr = scale_factor_cd->local_data(); - scale_factor_cd->copy_from_two_vec_w_pattern(*scale_factor_c, cons_eq_mapping, *scale_factor_d, cons_ineq_mapping); Jac_c.row_max_abs_value(*scale_factor_c); diff --git a/src/Optimization/hiopPDPerturbation.hpp b/src/Optimization/hiopPDPerturbation.hpp index 9b17b938c..d9a108a1b 100644 --- a/src/Optimization/hiopPDPerturbation.hpp +++ b/src/Optimization/hiopPDPerturbation.hpp @@ -26,23 +26,7 @@ class hiopPDPerturbation * this class based on HiOp option file or HiOp user-supplied runtime options. */ hiopPDPerturbation() - : delta_w_min_bar_(1e-20), - delta_w_max_bar_(1e+40), - delta_w_0_bar_(1e-4), - kappa_w_minus_(1./3), - kappa_w_plus_bar_(100.), - kappa_w_plus_(8.), - delta_c_bar_(1e-8), - kappa_c_(0.25), - hess_degenerate_(dtNotEstablished), - jac_degenerate_(dtNotEstablished), - num_degen_iters_(0), - num_degen_max_iters_(3), - deltas_test_type_(dttNoTest), - mu_(1e-8), - max_uniform_ratio_{1.0}, - min_uniform_ratio_{0.9}, - delta_wx_curr_(nullptr), + : delta_wx_curr_(nullptr), delta_wd_curr_(nullptr), delta_cc_curr_(nullptr), delta_cd_curr_(nullptr), @@ -50,7 +34,6 @@ class hiopPDPerturbation delta_wd_last_(nullptr), delta_cc_last_(nullptr), delta_cd_last_(nullptr), - nlp_(nullptr), delta_wx_curr_db_{0.}, delta_wd_curr_db_{0.}, delta_cc_curr_db_{0.}, @@ -58,7 +41,24 @@ class hiopPDPerturbation delta_wx_last_db_{0.}, delta_wd_last_db_{0.}, delta_cc_last_db_{0.}, - delta_cd_last_db_{0.} + delta_cd_last_db_{0.}, + delta_w_min_bar_(1e-20), + delta_w_max_bar_(1e+40), + delta_w_0_bar_(1e-4), + kappa_w_minus_(1./3), + kappa_w_plus_bar_(100.), + kappa_w_plus_(8.), + delta_c_bar_(1e-8), + kappa_c_(0.25), + min_uniform_ratio_{0.9}, + max_uniform_ratio_{1.0}, + hess_degenerate_(dtNotEstablished), + jac_degenerate_(dtNotEstablished), + num_degen_iters_(0), + num_degen_max_iters_(3), + deltas_test_type_(dttNoTest), + mu_(1e-8), + nlp_(nullptr) { } diff --git a/src/Utils/hiopCSR_IO.hpp b/src/Utils/hiopCSR_IO.hpp index 0ef974764..c28d32c48 100644 --- a/src/Utils/hiopCSR_IO.hpp +++ b/src/Utils/hiopCSR_IO.hpp @@ -22,7 +22,12 @@ namespace hiop public: // masterrank=-1 means all ranks save hiopCSR_IO(hiopNlpFormulation* nlp, int masterrank=0) - : _nlp(nlp), _master_rank(masterrank), _f(NULL), m(-1), last_counter(-1) + : _nlp(nlp), +#ifdef HIOP_USE_MPI + _master_rank(masterrank), +#endif + m(-1), + last_counter(-1) { } @@ -179,9 +184,6 @@ namespace hiop return; } - //count nnz - int nnz=Msys.numberOfNonzeros(); - int csr_nnz; int *csr_kRowPtr{nullptr}, *csr_jCol{nullptr}, *index_covert_CSR2Triplet{nullptr}, *index_covert_extra_Diag2CSR{nullptr}; double *csr_kVal{nullptr}; @@ -189,8 +191,14 @@ namespace hiop Msys.convert_to_csr_arrays(csr_nnz, &csr_kRowPtr, &csr_jCol, &csr_kVal, &index_covert_CSR2Triplet, &index_covert_extra_Diag2CSR, extra_diag_nnz_map); - if(index_covert_CSR2Triplet) delete [] index_covert_CSR2Triplet; index_covert_CSR2Triplet = nullptr; - if(index_covert_extra_Diag2CSR) delete [] index_covert_extra_Diag2CSR; index_covert_extra_Diag2CSR = nullptr; + if(index_covert_CSR2Triplet) { + delete [] index_covert_CSR2Triplet; + index_covert_CSR2Triplet = nullptr; + } + if(index_covert_extra_Diag2CSR) { + delete [] index_covert_extra_Diag2CSR; + index_covert_extra_Diag2CSR = nullptr; + } //start writing -> indexes are starting at 1 fprintf(f, "%d\n%d\n%d\n%d\n%d\n", m, nx, meq, mineq, csr_nnz); @@ -216,17 +224,19 @@ namespace hiop fclose(f); - if(csr_kRowPtr) delete [] csr_kRowPtr; csr_kRowPtr = nullptr; - if(csr_jCol) delete [] csr_jCol; csr_jCol = nullptr; - if(csr_kVal) delete [] csr_kVal; csr_kVal = nullptr; + if(csr_kRowPtr) { delete [] csr_kRowPtr; csr_kRowPtr = nullptr; } + if(csr_jCol) { delete [] csr_jCol; csr_jCol = nullptr; } + if(csr_kVal) { delete [] csr_kVal; csr_kVal = nullptr; } } private: - FILE* _f; hiopNlpFormulation* _nlp; +#ifdef HIOP_USE_MPI int _master_rank; - int m, last_counter; //used only for consistency (such as order of calls) checks +#endif + int m; + int last_counter; //used only for consistency (such as order of calls) checks }; } // end namespace diff --git a/src/Utils/hiopKronReduction.cpp b/src/Utils/hiopKronReduction.cpp index 392c22353..05e6a4678 100644 --- a/src/Utils/hiopKronReduction.cpp +++ b/src/Utils/hiopKronReduction.cpp @@ -102,8 +102,8 @@ namespace hiop assert(map_nonaux_to_aux_); if(NULL==map_nonaux_to_aux_) return false; - assert(v_nonaux_in.size() == map_nonaux_to_aux_->n()); - assert(v_aux_out.size() == map_nonaux_to_aux_->m()); + assert((size_type) v_nonaux_in.size() == map_nonaux_to_aux_->n()); + assert((size_type) v_aux_out.size() == map_nonaux_to_aux_->m()); map_nonaux_to_aux_->timesVec(std::complex(0.,0.), v_aux_out.data(), diff --git a/src/Utils/hiopOptions.cpp b/src/Utils/hiopOptions.cpp index 2a132af67..350ceea7f 100644 --- a/src/Utils/hiopOptions.cpp +++ b/src/Utils/hiopOptions.cpp @@ -397,7 +397,7 @@ bool hiopOptions::set_val(const char* name, const char* value_in) transform(value.begin(), value.end(), value.begin(), ::tolower); //see if it is in the range (of supported values) bool inrange=false; - for(int it=0; itrange.size() && !inrange; it++) { + for(int it=0; it(option->range.size()) && !inrange; it++) { inrange = (option->range[it]==value); } @@ -442,14 +442,14 @@ bool hiopOptions::SetStringValue (const char* name, const char* value, const bo transform(strValue.begin(), strValue.end(), strValue.begin(), ::tolower); //see if it is in the range (of supported values) bool inrange=false; - for(int it=0; itrange.size() && !inrange; it++) { + for(int it=0; it(option->range.size()) && !inrange; it++) { inrange = (option->range[it]==strValue); } //empty range means the option can take any value and no range check is needed if(!inrange && !option->range.empty()) { stringstream ssRange; ssRange << " "; - for(int it=0; itrange.size(); it++) { + for(int it=0; it(option->range.size()); it++) { ssRange << option->range[it] << " "; } @@ -536,7 +536,7 @@ void hiopOptions::OptionStr::print(FILE* f, bool short_ver) const } else { if(!short_ver) { stringstream ssRange; ssRange << " "; - for(int i=0; i(range.size()); i++) { ssRange << range[i] << " "; } fprintf(f, "%s \t# (string) one of [%s] [%s]", val.c_str(), ssRange.str().c_str(), descr.c_str()); diff --git a/src/Utils/hiopRunStats.hpp b/src/Utils/hiopRunStats.hpp index bbecacf6f..9d02b64cc 100644 --- a/src/Utils/hiopRunStats.hpp +++ b/src/Utils/hiopRunStats.hpp @@ -305,7 +305,9 @@ class hiopRunStats { public: hiopRunStats(MPI_Comm comm_=MPI_COMM_WORLD) +#ifdef HIOP_USE_MPI : comm(comm_) +#endif { initialize(); }; @@ -388,9 +390,11 @@ class hiopRunStats return ss.str(); } + +#ifdef HIOP_USE_MPI private: MPI_Comm comm; - +#endif }; } diff --git a/tests/LinAlg/matrixTestsDense.hpp b/tests/LinAlg/matrixTestsDense.hpp index d220d0a3c..582afb52b 100644 --- a/tests/LinAlg/matrixTestsDense.hpp +++ b/tests/LinAlg/matrixTestsDense.hpp @@ -134,7 +134,6 @@ class MatrixTestsDense : public TestBase int fail = verifyAnswer(&dst, src_val); // test copying src a raw buffer - const size_t buf_len = getNumLocRows(&src) * getNumLocCols(&src); const real_type* src_buf = getLocalDataConst(&src); dst.setToZero(); @@ -158,7 +157,6 @@ class MatrixTestsDense : public TestBase dst.setToZero(); // test copying src a raw buffer - const size_t buf_len = getNumLocRows(&dst) * getNumLocCols(&dst); real_type* dst_buf = getLocalData(&dst); dst.setToZero(); @@ -944,10 +942,6 @@ class MatrixTestsDense : public TestBase assert(src.n() == dst.n() && "Src mat must be equal to dst mat"); assert(src.m() == dst.m() && "Src mat must be equal to dst mat"); assert(src.m() == diag.get_size() && "Wrong vec size"); - const local_ordinal_type dst_m = getNumLocRows(&dst); - const local_ordinal_type dst_n = getNumLocCols(&dst); - const local_ordinal_type src_m = getNumLocRows(&src); - const local_ordinal_type src_n = getNumLocCols(&src); const real_type src_val = one; const real_type diag_val = two; @@ -1175,7 +1169,6 @@ class MatrixTestsDense : public TestBase int matrixOverwriteUpperTriangleWithLower(hiop::hiopMatrixDense& A, const int rank=0) { const local_ordinal_type M = getNumLocRows(&A); - const local_ordinal_type N = getNumLocCols(&A); for (int i = 0; i < M; i++) { @@ -1196,7 +1189,6 @@ class MatrixTestsDense : public TestBase int matrixOverwriteLowerTriangleWithUpper(hiop::hiopMatrixDense& A, const int rank=0) { const local_ordinal_type M = getNumLocRows(&A); - const local_ordinal_type N = getNumLocCols(&A); for (int i = 0; i < M; i++) { diff --git a/tests/LinAlg/matrixTestsDenseRowMajor.cpp b/tests/LinAlg/matrixTestsDenseRowMajor.cpp index f356c12d3..bff4e2bca 100644 --- a/tests/LinAlg/matrixTestsDenseRowMajor.cpp +++ b/tests/LinAlg/matrixTestsDenseRowMajor.cpp @@ -255,8 +255,9 @@ void MatrixTestsDenseRowMajor::setLocalElement( const real_type val) { auto* xvec = dynamic_cast(x); - if(xvec == nullptr) + if(xvec == nullptr) { THROW_NULL_DEREF; + } real_type* data = x->local_data(); data[i] = val; diff --git a/tests/LinAlg/matrixTestsSparse.hpp b/tests/LinAlg/matrixTestsSparse.hpp index 995a0ef84..f6f74d161 100644 --- a/tests/LinAlg/matrixTestsSparse.hpp +++ b/tests/LinAlg/matrixTestsSparse.hpp @@ -226,8 +226,6 @@ class MatrixTestsSparse : public TestBase const int rank=0) { const local_ordinal_type nnz = A.numberOfNonzeros(); - const local_ordinal_type* iRow = getRowIndices(&A); - const local_ordinal_type* jCol = getColumnIndices(&A); auto val = getMatrixData(&A); const local_ordinal_type last_row_idx = A.m()-1; @@ -259,11 +257,6 @@ class MatrixTestsSparse : public TestBase hiop::hiopVector& x, const int rank=0) { - const local_ordinal_type nnz = A.numberOfNonzeros(); - const local_ordinal_type* iRow = getRowIndices(&A); - const local_ordinal_type* jCol = getColumnIndices(&A); - auto val = getMatrixData(&A); - const real_type A_val = two; const real_type x_val = three; int fail = 0; @@ -906,7 +899,6 @@ class MatrixTestsSparse : public TestBase hiop::hiopMatrixSparse& A, const int rank=0) { - const local_ordinal_type N_loc = W.get_local_size_n(); const local_ordinal_type A_M = A.m(); const local_ordinal_type A_N = A.n(); assert(W.m() == W.n()); @@ -946,14 +938,6 @@ class MatrixTestsSparse : public TestBase /// @brief Copies rows from another sparse matrix into this one, according to the patten `select`. ith row of A = select[i]_th row of B int matrix_copy_rows_from( hiop::hiopMatrixSparse& A, hiop::hiopMatrixSparse& B, hiop::hiopVectorInt& select) { - const local_ordinal_type* A_iRow = getRowIndices(&A); - const local_ordinal_type* A_jCol = getColumnIndices(&A); - const local_ordinal_type A_nnz = A.numberOfNonzeros(); - - const local_ordinal_type* B_iRow = getRowIndices(&B); - const local_ordinal_type* B_jCol = getColumnIndices(&B); - const local_ordinal_type B_nnz = B.numberOfNonzeros(); - int n_A_rows = A.m(); int n_B_rows = B.m(); assert(A.n() == B.n()); @@ -1030,11 +1014,8 @@ class MatrixTestsSparse : public TestBase local_ordinal_type B_nnz_st) { const local_ordinal_type* A_iRow = getRowIndices(&A); - const local_ordinal_type* A_jCol = getColumnIndices(&A); const local_ordinal_type A_nnz = A.numberOfNonzeros(); - const local_ordinal_type* B_iRow = getRowIndices(&B); - const local_ordinal_type* B_jCol = getColumnIndices(&B); const local_ordinal_type B_nnz = B.numberOfNonzeros(); local_ordinal_type nnz_A_need_to_copy{0}; @@ -1066,8 +1047,6 @@ class MatrixTestsSparse : public TestBase B.copyRowsBlockFrom(A, A_rows_st, n_rows, B_rows_st, B_nnz_st); - auto val = getMatrixData(&B); - fail += verifyAnswer(&B,0,B_nnz_st,B_val); fail += verifyAnswer(&B,B_nnz_st,B_nnz_st+nnz_A_need_to_copy,A_val); fail += verifyAnswer(&B,B_nnz_st+nnz_A_need_to_copy,B_nnz,B_val); @@ -1124,8 +1103,6 @@ class MatrixTestsSparse : public TestBase const auto* B_iRow = getRowIndices(&B); const auto* B_jCol = getColumnIndices(&B); auto B_nnz = B.numberOfNonzeros(); - const auto B_m = B.m(); - const auto B_n = B.n(); fail += verifyAnswer(&W, [=] (local_ordinal_type i, local_ordinal_type j) -> real_type @@ -1203,8 +1180,6 @@ class MatrixTestsSparse : public TestBase const auto* B_iRow = getRowIndices(&B); const auto* B_jCol = getColumnIndices(&B); auto B_nnz = B.numberOfNonzeros(); - const auto B_m = B.m(); - const auto B_n = B.n(); fail += verifyAnswer(&W, [=] (local_ordinal_type i, local_ordinal_type j) -> real_type @@ -1625,10 +1600,6 @@ class MatrixTestsSparse : public TestBase // copy to a dense matrix A.copy_to(W); - const local_ordinal_type* iRow = getRowIndices(&A); - const local_ordinal_type* jCol = getColumnIndices(&A); - const local_ordinal_type nnz = A.numberOfNonzeros(); - fail += verifyAnswer(&W, [=] (local_ordinal_type i, local_ordinal_type j) -> real_type { @@ -1708,7 +1679,7 @@ class MatrixTestsSparse : public TestBase // linearly scans an unsorted array static bool find_unsorted_pair(int valA, int valB, const int* arrA, const int* arrB, size_t arrslen) { - for (int i = 0; i < arrslen; i++) + for (int i = 0; i < static_cast(arrslen); i++) { if (arrA[i] == valA && arrB[i] == valB) { @@ -1721,7 +1692,7 @@ class MatrixTestsSparse : public TestBase // linearly scans an unsorted array within range [nnz_st, nnz_ed) static bool find_unsorted_pair(int valA, int valB, const int* arrA, const int* arrB, size_t idx_st, size_t idx_ed) { - for (int i = idx_st; i < idx_ed; i++) + for (int i = idx_st; i < static_cast(idx_ed); i++) { if (arrA[i] == valA && arrB[i] == valB) { diff --git a/tests/LinAlg/matrixTestsSparseTriplet.cpp b/tests/LinAlg/matrixTestsSparseTriplet.cpp index dd8bad672..774c7699b 100644 --- a/tests/LinAlg/matrixTestsSparseTriplet.cpp +++ b/tests/LinAlg/matrixTestsSparseTriplet.cpp @@ -193,7 +193,6 @@ int MatrixTestsSparseTriplet::verifyAnswer(hiop::hiopMatrix* A, local_ordinal_ty if(A == nullptr) return 1; auto mat = dynamic_cast(A); - const local_ordinal_type nnz = mat->numberOfNonzeros(); const real_type* values = mat->M(); int fail = 0; for (local_ordinal_type i=nnz_st; i(arrslen); i++) { if (arrA[i] == valA && arrB[i] == valB) { diff --git a/tests/LinAlg/vectorTests.hpp b/tests/LinAlg/vectorTests.hpp index e46d8fca2..dfe0ed29f 100644 --- a/tests/LinAlg/vectorTests.hpp +++ b/tests/LinAlg/vectorTests.hpp @@ -2037,7 +2037,6 @@ class VectorTests : public TestBase */ bool vector_is_equal(hiop::hiopVector& x, hiop::hiopVector& y, const int rank) { - const local_ordinal_type Nx = getLocalSize(&x); int fail = 0; x.setToConstant(one); y.setToConstant(one); diff --git a/tests/LinAlg/vectorTestsInt.hpp b/tests/LinAlg/vectorTestsInt.hpp index e64a5b93b..00850abaa 100644 --- a/tests/LinAlg/vectorTestsInt.hpp +++ b/tests/LinAlg/vectorTestsInt.hpp @@ -142,7 +142,6 @@ class VectorTestsInt : public TestBase virtual bool vector_copy_from(hiop::hiopVectorInt& x, hiop::hiopVectorInt& y) const { int fail = 0; - const int idx = x.get_local_size()/2; const int x_val = 1; const int y_val = 1; diff --git a/tests/test_bicgstab.cpp b/tests/test_bicgstab.cpp index f7c27c726..6f6b7c55d 100644 --- a/tests/test_bicgstab.cpp +++ b/tests/test_bicgstab.cpp @@ -21,7 +21,6 @@ void initializeSymSparseMat(hiop::hiopMatrixSparse* mat, bool is_diag_pred) int nonZerosUsed = 0; size_type m = A->m(); - size_type n = A->n(); for (auto i = 0; i < m; i++) { @@ -86,7 +85,6 @@ void initializeRajaSymSparseMat(hiop::hiopMatrixSparse* mat, bool is_diag_pred) int nonZerosUsed = 0; size_type m = A->m(); - size_type n = A->n(); for (auto i = 0; i < m; i++) { @@ -122,8 +120,10 @@ void initializeRajaSymSparseMat(hiop::hiopMatrixSparse* mat, bool is_diag_pred) int main(int argc, char **argv) { - int rank=0, numRanks=1; + #ifdef HIOP_USE_MPI + int rank = 0; + int numRanks = 1; int err; err = MPI_Init(&argc, &argv); assert(MPI_SUCCESS==err); err = MPI_Comm_rank(MPI_COMM_WORLD,&rank); assert(MPI_SUCCESS==err); @@ -170,7 +170,7 @@ int main(int argc, char **argv) hiopBiCGStabSolver bicgstab_solver(N_local, A_opr, Minv_opr, nullptr, nullptr); - bool is_solved = bicgstab_solver.solve(rhs); + [[maybe_unused]] bool is_solved = bicgstab_solver.solve(rhs); std::cout << mem_space << ": " << bicgstab_solver.get_convergence_info() << std::endl; @@ -212,7 +212,11 @@ int main(int argc, char **argv) bool is_solved = bicgstab_solver.solve(rhs); - std::cout << mem_space << ": " << bicgstab_solver.get_convergence_info() << std::endl; + if(is_solved) { + std::cout << mem_space << ": " << bicgstab_solver.get_convergence_info() << std::endl; + } else { + std::cout << "Failed! " << mem_space << ": " << bicgstab_solver.get_convergence_info() << std::endl; + } // Destroy testing objects delete A_opr; diff --git a/tests/test_pcg.cpp b/tests/test_pcg.cpp index 899e90d08..732ebf27d 100644 --- a/tests/test_pcg.cpp +++ b/tests/test_pcg.cpp @@ -21,7 +21,6 @@ void initializeSymSparseMat(hiop::hiopMatrixSparse* mat, bool is_diag_pred) int nonZerosUsed = 0; size_type m = A->m(); - size_type n = A->n(); for (auto i = 0; i < m; i++) { @@ -85,7 +84,6 @@ void initializeRajaSymSparseMat(hiop::hiopMatrixSparse* mat, bool is_diag_pred) int nonZerosUsed = 0; size_type m = A->m(); - size_type n = A->n(); for (auto i = 0; i < m; i++) { @@ -122,8 +120,9 @@ void initializeRajaSymSparseMat(hiop::hiopMatrixSparse* mat, bool is_diag_pred) int main(int argc, char **argv) { - int rank=0, numRanks=1; #ifdef HIOP_USE_MPI + int rank = 0; + int numRanks = 1; int err; err = MPI_Init(&argc, &argv); assert(MPI_SUCCESS==err); err = MPI_Comm_rank(MPI_COMM_WORLD,&rank); assert(MPI_SUCCESS==err); @@ -170,7 +169,7 @@ int main(int argc, char **argv) hiopPCGSolver pcg_solver(N_local, A_opr, Minv_opr, nullptr, nullptr); - bool is_solved = pcg_solver.solve(rhs); + [[maybe_unused]] bool is_solved = pcg_solver.solve(rhs); std::cout << mem_space << ": " << pcg_solver.get_convergence_info() << std::endl; @@ -212,9 +211,13 @@ int main(int argc, char **argv) hiopPCGSolver pcg_solver(N_local, A_opr, Minv_opr, nullptr, nullptr); bool is_solved = pcg_solver.solve(rhs); - - std::cout << mem_space << ": " << pcg_solver.get_convergence_info() << std::endl; - + + if(is_solved) { + std::cout << mem_space << ": " << pcg_solver.get_convergence_info() << std::endl; + } else { + std::cout << "Failed! " << mem_space << ": " << pcg_solver.get_convergence_info() << std::endl; + } + // Destroy testing objects delete A_opr; delete Minv_opr;