27 #ifdef MANGO_HOPSPACK_AVAILABLE
28 #include "HOPSPACK_GenProcComm.hpp"
29 #include "HOPSPACK_ParameterList.hpp"
30 #include "HOPSPACK_Vector.hpp"
31 #include "HOPSPACK_ExecutorSerial.hpp"
32 #include "HOPSPACK_Hopspack.hpp"
33 #include "HOPSPACK_MangoEvaluator.hpp"
35 int HOPSPACK_startProcComm(HOPSPACK::GenProcComm &, MPI_Comm);
36 int HOPSPACK_behaveAsMaster(HOPSPACK::GenProcComm &, HOPSPACK::ParameterList*,
mango::Solver*);
37 int HOPSPACK_behaveAsWorker(
const int, HOPSPACK::GenProcComm &,
mango::Solver*);
42 #ifdef MANGO_HOPSPACK_AVAILABLE
47 bool proc0 = (mpi_rank_group_leaders == 0);
50 if (solver->
verbose > 0) std::cout <<
"Entering optimize_hopspack" << std::endl;
55 using HOPSPACK::GenProcComm;
56 GenProcComm & cGPC = GenProcComm::getTheInstance();
58 if (nProcRank == -1)
throw std::runtime_error(
"Error starting MPI in HOPSPACK");
60 if (solver->
verbose > 0) std::cout <<
"Done initializing HOPSPACK MPI variables." << std::endl;
64 using HOPSPACK::ParameterList;
65 ParameterList hopspack_parameters;
67 HOPSPACK::ParameterList* cProblemParams = &(hopspack_parameters.getOrSetSublist (
"Problem Definition"));
68 cProblemParams->setParameter(
"Objective Type",
"Minimize");
69 cProblemParams->setParameter(
"Number Unknowns", N_parameters);
73 HOPSPACK::Vector scaling(N_parameters, 1.0);
74 cProblemParams->setParameter(
"Scaling",scaling);
78 HOPSPACK::Vector x0(N_parameters, 0.0);
79 for (
int j=0; j<N_parameters; j++) x0[j] = solver->
state_vector[j];
80 cProblemParams->setParameter(
"Initial X",x0);
84 HOPSPACK::Vector hopspack_lower_bounds(N_parameters, 0.0);
85 HOPSPACK::Vector hopspack_upper_bounds(N_parameters, 0.0);
87 for (
int j=0; j<N_parameters; j++) hopspack_lower_bounds[j] = solver->
lower_bounds[j];
88 for (
int j=0; j<N_parameters; j++) hopspack_upper_bounds[j] = solver->
upper_bounds[j];
89 cProblemParams->setParameter(
"Lower Bounds",hopspack_lower_bounds);
90 cProblemParams->setParameter(
"Upper Bounds",hopspack_upper_bounds);
93 HOPSPACK::ParameterList* cMedParams = &(hopspack_parameters.getOrSetSublist (
"Mediator"));
96 cMedParams->setParameter(
"Citizen Count",1);
99 HOPSPACK::ParameterList* cCitizenParams = &(hopspack_parameters.getOrSetSublist (
"Citizen 1"));
100 cCitizenParams->setParameter(
"Type",
"GSS");
101 cCitizenParams->setParameter(
"Step Tolerance",1e-5);
104 cProblemParams->setParameter(
"Display",2);
105 cMedParams->setParameter(
"Display",2);
106 cCitizenParams->setParameter(
"Display",1);
108 cProblemParams->setParameter(
"Display",0);
109 cMedParams->setParameter(
"Display",0);
110 cCitizenParams->setParameter(
"Display",0);
113 if (solver->
verbose > 0) std::cout <<
"Done setting HOPSPACK parameters." << std::endl;
121 if (solver->
verbose > 0) std::cout <<
"Beginning serial version of HOPSPACK." << std::endl;
123 HOPSPACK::MangoEvaluator* pEvaluator =
new HOPSPACK::MangoEvaluator (hopspack_parameters, solver);
124 if (pEvaluator == NULL)
throw std::runtime_error(
"Error constructing MangoEvaluator for serial HOPSPACK!");
125 HOPSPACK::ExecutorSerial* pExecutor =
new HOPSPACK::ExecutorSerial (pEvaluator);
126 HOPSPACK::Hopspack optimizer (pExecutor);
127 if (optimizer.setInputParameters (hopspack_parameters, solver) ==
true) optimizer.solve();
135 if (solver->
verbose > 0) std::cout <<
"Beginning MPI version of HOPSPACK." << std::endl;
136 nReturnValue = HOPSPACK_behaveAsMaster(cGPC, &hopspack_parameters, solver);
138 nReturnValue = HOPSPACK_behaveAsWorker(nProcRank, cGPC, solver);
142 if (nReturnValue != 0)
throw std::runtime_error(
"Error! HOPSPACK returned an error code.");
195 throw std::runtime_error(
"Error! The HOPSPACK algorithm was requested, but Mango was compiled without HOPSPACK support.");
237 throw std::runtime_error(
"Error! mango somehow got to Package_hopspack::optimize_least_squares. This should never happen.");