Skip to content

Commit cab209f

Browse files
committed
addressed MPI issues
1 parent e4edea2 commit cab209f

6 files changed

+152
-136
lines changed

src/Drivers/Dense/NlpDenseConsEx1.hpp

+35
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,41 @@ class DenseConsEx1 : public hiop::hiopInterfaceDenseConstraints
257257
double alpha_du,
258258
double alpha_pr,
259259
int ls_trials);
260+
261+
bool applyM(const size_type& n, const double* x_in, double* y_out)
262+
{
263+
x->copyFrom(x_in);
264+
x->copyTo(y_out);
265+
return true;
266+
}
267+
268+
/**
269+
* Computes action y of the inner product weight matrix H on a vector x, namely y=H*x
270+
*/
271+
virtual bool applyH(const size_type& n, const double* x_in, double* y_out)
272+
{
273+
x->copyFrom(x_in);
274+
x->copyTo(y_out);
275+
return true;
276+
}
277+
278+
/**
279+
* Computes action y of the inverse of H on a vector x, namely y=H^{-1}*x
280+
*/
281+
virtual bool applyHinv(const size_type& n, const double* x_in, double* y_out)
282+
{
283+
x->copyFrom(x_in);
284+
x->copyTo(y_out);
285+
return true;
286+
}
287+
288+
/**
289+
* Enables the use of weighted inner products via @applyM, @applyH, and @applyHinv
290+
*/
291+
virtual bool useWeightedInnerProducts()
292+
{
293+
return false;
294+
}
260295

261296
private:
262297
int n_vars;

src/Optimization/InnerProduct.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ namespace hiop
6262
InnerProduct::InnerProduct(hiopNlpFormulation* nlp)
6363
: nlp_(nlp)
6464
{
65+
printf("InnerProduct::InnerProduct begin\n"); fflush(stdout);
66+
assert(nlp);
6567
if(nlp->useWeightedInnerProd()) {
6668
vec_n_ = nlp_->alloc_primal_vec();
6769
vec_n2_ = nlp_->alloc_primal_vec();
6870
} else {
6971
vec_n_ = nullptr;
7072
vec_n2_ = nullptr;
7173
}
74+
printf("InnerProduct::InnerProduct end\n"); fflush(stdout);
7275
}
7376

7477
InnerProduct::~InnerProduct()

src/Optimization/hiopAlgFilterIPM.cpp

+96-97
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,8 @@ bool hiopAlgFilterIPMBase::evalNlpAndLogErrors(const hiopIterate& it,
686686
}
687687

688688
// scaling factors
689-
//double sd = fmax(p_smax, (nrmDualBou + nrmDualEqu) / (n + m)) / p_smax;
690-
//double sc = n == 0 ? 0 : fmax(p_smax, nrmDualBou / n) / p_smax;
691-
689+
//c double sd = fmax(p_smax, (nrmDualBou + nrmDualEqu) / (n + m)) / p_smax;
690+
//c double sc = n == 0 ? 0 : fmax(p_smax, nrmDualBou / n) / p_smax;
692691
sd = fmax(p_smax, sd) / p_smax;
693692
sc = n == 0 ? 0 : fmax(p_smax, sc) / p_smax;
694693

@@ -720,98 +719,98 @@ bool hiopAlgFilterIPMBase::evalNlpAndLogErrors(const hiopIterate& it,
720719
return true;
721720
}
722721

723-
bool hiopAlgFilterIPMBase::evalNlpAndLogErrors2(const hiopIterate& it,
724-
const hiopResidual& resid,
725-
const double& mu,
726-
double& nlpoptim,
727-
double& nlpfeas,
728-
double& nlpcomplem,
729-
double& nlpoverall,
730-
double& logoptim,
731-
double& logfeas,
732-
double& logcomplem,
733-
double& logoverall,
734-
double& cons_violation)
735-
{
736-
nlp->runStats.tmSolverInternal.start();
737-
738-
size_type n = nlp->n_complem();
739-
double sc;
740-
double sd;
741-
double nrmDualBou;
742-
double nrmDualEqu;
743-
if(!it.compute_sc_sd(sc, sd, nrmDualEqu, nrmDualBou)) {
744-
return false;
745-
}
746-
747-
nlp->log->printf(hovWarning, "nrmOneDualEqu %g nrmOneDualBo %g\n", nrmDualEqu, nrmDualBou);
748-
if(nrmDualBou > 1e+10) {
749-
nlp->log->printf(hovWarning,
750-
"Unusually large bound dual variables (norm1=%g) occured, "
751-
"which may cause numerical instabilities if it persists. Convergence "
752-
" issues or inacurate optimal solutions may be experienced. Possible causes: "
753-
" tight bounds or bad scaling of the optimization variables.\n",
754-
nrmDualBou);
755-
if(nlp->options->GetString("fixed_var") == "remove") {
756-
nlp->log->printf(hovWarning,
757-
"For example, increase 'fixed_var_tolerance' to remove "
758-
"additional variables.\n");
759-
} else if(nlp->options->GetString("fixed_var") == "relax") {
760-
nlp->log->printf(hovWarning,
761-
"For example, increase 'fixed_var_tolerance' to relax "
762-
"aditional (tight) variables and/or increase 'fixed_var_perturb' "
763-
"to decrease the tightness.\n");
764-
} else {
765-
nlp->log->printf(hovWarning,
766-
"Potential fixes: fix or relax variables with tight bounds "
767-
"(see 'fixed_var' option) or rescale variables.\n");
768-
}
769-
}
770-
771-
// scaling factors
772-
//sd = max { p_smax, ||zl||_M + ||zu||_M + (||vl||_1 + ||vu||_1)/m } /p_smax
773-
//sc = max { p_smax, ||zl||_M + ||zu||_M } /p_smax
774-
//nlpoptim = ||gradf + Jc'*yc + Jd'*Jd - M*zl - M*zu||_Hinv
775-
// ||yd+vl-vu||_inf
776-
//nlpfeas = ||crhs- c||_inf
777-
// ||drs- d||_inf
778-
// ||x-sxl-xl||_inf
779-
// ||x-sxu+xu||_inf
780-
// ||d-sdl-dl||
781-
//
782-
//double sd = fmax(p_smax, (nrmDualBou + nrmDualEqu) / (n + m)) / p_smax;
783-
//double sc = n == 0 ? 0 : fmax(p_smax, nrmDualBou / n) / p_smax;
784-
785-
sd = fmax(p_smax, sd) / p_smax;
786-
sc = n == 0 ? 0 : fmax(p_smax, sc) / p_smax;
787-
788-
sd = fmin(sd, 1e+8);
789-
sc = fmin(sc, 1e+8);
790-
791-
// actual nlp errors
792-
resid.getNlpErrors(nlpoptim, nlpfeas, nlpcomplem, cons_violation);
793-
794-
// finally, the scaled nlp error
795-
nlpoverall = fmax(nlpoptim / sd, fmax(cons_violation, nlpcomplem / sc));
796-
797-
nlp->log->printf(hovWarning,
798-
"nlpoverall %g nloptim %g sd %g nlpfeas %g nlpcomplem %g sc %g cons_violation %g\n",
799-
nlpoverall,
800-
nlpoptim,
801-
sd,
802-
nlpfeas,
803-
nlpcomplem,
804-
cons_violation,
805-
sc);
806-
807-
// actual log errors
808-
resid.getBarrierErrors(logoptim, logfeas, logcomplem);
809-
810-
// finally, the scaled barrier error
811-
logoverall = fmax(logoptim / sd, fmax(cons_violation, logcomplem / sc));
812-
nlp->runStats.tmSolverInternal.stop();
813-
return true;
814-
}
722+
// bool hiopAlgFilterIPMBase::evalNlpAndLogErrors2(const hiopIterate& it,
723+
// const hiopResidual& resid,
724+
// const double& mu,
725+
// double& nlpoptim,
726+
// double& nlpfeas,
727+
// double& nlpcomplem,
728+
// double& nlpoverall,
729+
// double& logoptim,
730+
// double& logfeas,
731+
// double& logcomplem,
732+
// double& logoverall,
733+
// double& cons_violation)
734+
// {
735+
// nlp->runStats.tmSolverInternal.start();
736+
737+
// size_type n = nlp->n_complem();
738+
// double sc;
739+
// double sd;
740+
// double nrmDualBou;
741+
// double nrmDualEqu;
742+
// if(!it.compute_sc_sd(sc, sd, nrmDualEqu, nrmDualBou)) {
743+
// return false;
744+
// }
745+
746+
// nlp->log->printf(hovWarning, "nrmOneDualEqu %g nrmOneDualBo %g\n", nrmDualEqu, nrmDualBou);
747+
// if(nrmDualBou > 1e+10) {
748+
// nlp->log->printf(hovWarning,
749+
// "Unusually large bound dual variables (norm1=%g) occured, "
750+
// "which may cause numerical instabilities if it persists. Convergence "
751+
// " issues or inacurate optimal solutions may be experienced. Possible causes: "
752+
// " tight bounds or bad scaling of the optimization variables.\n",
753+
// nrmDualBou);
754+
// if(nlp->options->GetString("fixed_var") == "remove") {
755+
// nlp->log->printf(hovWarning,
756+
// "For example, increase 'fixed_var_tolerance' to remove "
757+
// "additional variables.\n");
758+
// } else if(nlp->options->GetString("fixed_var") == "relax") {
759+
// nlp->log->printf(hovWarning,
760+
// "For example, increase 'fixed_var_tolerance' to relax "
761+
// "aditional (tight) variables and/or increase 'fixed_var_perturb' "
762+
// "to decrease the tightness.\n");
763+
// } else {
764+
// nlp->log->printf(hovWarning,
765+
// "Potential fixes: fix or relax variables with tight bounds "
766+
// "(see 'fixed_var' option) or rescale variables.\n");
767+
// }
768+
// }
769+
770+
// // scaling factors
771+
// //sd = max { p_smax, ||zl||_M + ||zu||_M + (||vl||_1 + ||vu||_1)/m } /p_smax
772+
// //sc = max { p_smax, ||zl||_M + ||zu||_M } /p_smax
773+
// //nlpoptim = ||gradf + Jc'*yc + Jd'*Jd - M*zl - M*zu||_Hinv
774+
// // ||yd+vl-vu||_inf
775+
// //nlpfeas = ||crhs- c||_inf
776+
// // ||drs- d||_inf
777+
// // ||x-sxl-xl||_inf
778+
// // ||x-sxu+xu||_inf
779+
// // ||d-sdl-dl||
780+
// //
781+
// //double sd = fmax(p_smax, (nrmDualBou + nrmDualEqu) / (n + m)) / p_smax;
782+
// //double sc = n == 0 ? 0 : fmax(p_smax, nrmDualBou / n) / p_smax;
783+
784+
// sd = fmax(p_smax, sd) / p_smax;
785+
// sc = n == 0 ? 0 : fmax(p_smax, sc) / p_smax;
786+
787+
// sd = fmin(sd, 1e+8);
788+
// sc = fmin(sc, 1e+8);
789+
790+
// // actual nlp errors
791+
// resid.getNlpErrors(nlpoptim, nlpfeas, nlpcomplem, cons_violation);
792+
793+
// // finally, the scaled nlp error
794+
// nlpoverall = fmax(nlpoptim / sd, fmax(cons_violation, nlpcomplem / sc));
795+
796+
// nlp->log->printf(hovWarning,
797+
// "nlpoverall %g nloptim %g sd %g nlpfeas %g nlpcomplem %g sc %g cons_violation %g\n",
798+
// nlpoverall,
799+
// nlpoptim,
800+
// sd,
801+
// nlpfeas,
802+
// nlpcomplem,
803+
// cons_violation,
804+
// sc);
805+
806+
// // actual log errors
807+
// resid.getBarrierErrors(logoptim, logfeas, logcomplem);
808+
809+
// // finally, the scaled barrier error
810+
// logoverall = fmax(logoptim / sd, fmax(cons_violation, logcomplem / sc));
811+
// nlp->runStats.tmSolverInternal.stop();
812+
// return true;
813+
// }
815814

816815
bool hiopAlgFilterIPMBase::evalNlp_funcOnly(hiopIterate& iter, double& f, hiopVector& c, hiopVector& d)
817816
{
@@ -1169,7 +1168,7 @@ hiopSolveStatus hiopAlgFilterIPMQuasiNewton::run()
11691168
solver_status_ = NlpSolve_Pending;
11701169

11711170
while(true) {
1172-
bret = evalNlpAndLogErrors2(*it_curr,
1171+
bret = evalNlpAndLogErrors(*it_curr,
11731172
*resid,
11741173
_mu,
11751174
_err_nlp_optim,
@@ -1262,7 +1261,7 @@ hiopSolveStatus hiopAlgFilterIPMQuasiNewton::run()
12621261

12631262
//! should perform only a partial update since NLP didn't change
12641263
resid->update(*it_curr, _f_nlp, *_c, *_d, *_grad_f, *_Jac_c, *_Jac_d, *logbar);
1265-
bret = evalNlpAndLogErrors2(*it_curr,
1264+
bret = evalNlpAndLogErrors(*it_curr,
12661265
*resid,
12671266
_mu,
12681267
_err_nlp_optim,

src/Optimization/hiopAlgFilterIPM.hpp

-14
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,6 @@ class hiopAlgFilterIPMBase
182182
double& logcomplem,
183183
double& logoverall,
184184
double& cons_violation);
185-
186-
virtual bool evalNlpAndLogErrors2(const hiopIterate& it,
187-
const hiopResidual& resid,
188-
const double& mu,
189-
double& nlpoptim,
190-
double& nlpfeas,
191-
double& nlpcomplem,
192-
double& nlpoverall,
193-
double& logoptim,
194-
double& logfeas,
195-
double& logcomplem,
196-
double& logoverall,
197-
double& cons_violation);
198-
199185

200186
virtual double thetaLogBarrier(const hiopIterate& it, const hiopResidual& resid, const double& mu);
201187

src/Optimization/hiopNlpFormulation.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ hiopNlpFormulation::hiopNlpFormulation(hiopInterfaceBase& interface_, const char
7878
prob_type_(hiopInterfaceBase::hiopNonlinear),
7979
nlp_evaluated_(false),
8080
nlp_transformations_(this),
81-
interface_base(interface_)
81+
interface_base(interface_),
82+
inner_prod_(nullptr)
8283
{
8384
strFixedVars_ = ""; // uninitialized
8485
dFixedVarsTol_ = -1.; // uninitialized
@@ -144,8 +145,6 @@ hiopNlpFormulation::hiopNlpFormulation(hiopInterfaceBase& interface_, const char
144145
temp_x_ = nullptr;
145146
nlp_scaling_ = nullptr;
146147
relax_bounds_ = nullptr;
147-
148-
inner_prod_ = new InnerProduct(this);
149148
}
150149

151150
hiopNlpFormulation::~hiopNlpFormulation()
@@ -259,6 +258,10 @@ bool hiopNlpFormulation::finalizeInitialization()
259258
ixl_ = xu_->alloc_clone();
260259
ixu_ = xu_->alloc_clone();
261260

261+
// create NLP space (H-weighted or Euclidean)
262+
delete inner_prod_;
263+
inner_prod_ = new InnerProduct(this);
264+
262265
//
263266
// preprocess variables bounds - this is curently done on the CPU
264267
//

0 commit comments

Comments
 (0)