26 #define gsMPIInfo(rank) gsInfo<<"[MPI process "<<rank<<"]: "
27 #define gsMPIDebug(rank) gsDebug<<"[MPI process "<<rank<<"]: "
43 typedef typename std::pair<gsVector<T>,T> solution_t;
59 gsAPALM( gsALMBase<T> * ALM,
60 const gsAPALMData<T,solution_t> & Data,
61 const gsMpiComm & comm );
63 gsAPALM( gsALMBase<T> * ALM,
64 const gsAPALMData<T,solution_t> & Data,
65 const gsSerialComm & comm );
73 gsAPALM( gsALMBase<T> * ALM,
74 const gsAPALMData<T,solution_t> & Data);
82 m_comm_dummy(new gsMpiComm()),
84 m_comm_dummy(new gsSerialComm()),
94 virtual void _defaultOptions();
96 virtual void _getOptions();
98 void _initStart(
const gsVector<T> & Ustart,
const T & Lstart,
const T & dL);
99 void _initStart(
const std::vector<gsVector<T>> & Ustart,
const std::vector<T> & Lstart,
const std::vector<T> & dLs);
105 virtual void initialize();
112 virtual void solve(
index_t Nsteps = 10);
118 virtual void serialSolve(
index_t Nsteps = 10);
122 virtual void parallelSolve();
131 virtual void serialStepOutput(
const std::pair<gsVector<T>,T> & pair,
const T & time,
index_t step) {};
139 virtual void parallelStepOutput(
const std::pair<gsVector<T>,T> & pair,
const T & time,
index_t step) {};
148 virtual void parallelIntervalOutput(
const std::vector<std::pair<gsVector<T>,T>> & stepSolutions,
const std::vector<T> & stepTimes,
index_t level,
index_t ID) {};
155 gsOptionList & options() {
return m_options; }
162 const gsAPALMDataContainer<T,solution_t> & getHierarchy()
const {
return m_data; }
163 gsAPALMDataContainer<T,solution_t> getHierarchy() {
return m_data; }
172 const std::vector<solution_t> & getFlatSolutions(
index_t branch = 0)
const {
return m_solutions[branch]; }
173 std::vector<solution_t> getFlatSolutions(
index_t branch = 0) {
return m_solutions[branch]; }
182 const std::vector<T> & getFlatTimes(
index_t branch = 0)
const {
return m_times[branch]; }
183 std::vector<T> getFlatTimes(
index_t branch = 0) {
return m_times[branch]; }
192 const std::vector<index_t> & getFlatLevels(
index_t branch = 0)
const {
return m_levels[branch]; }
193 std::vector<index_t> getFlatLevels(
index_t branch = 0) {
return m_levels[branch]; }
203 const std::vector<solution_t *> & getSolutions(
index_t level,
index_t branch = 0)
const {
return m_lvlSolutions[branch][level]; }
204 std::vector<solution_t> getSolutions(
index_t level,
index_t branch = 0)
206 std::vector<solution_t> result;
207 for (
typename std::vector<solution_t *>::iterator it=m_lvlSolutions[branch][level].begin(); it!=m_lvlSolutions[branch][level].end(); it++)
208 result.push_back(**it);
219 std::vector<std::vector<solution_t>> getSolutionsPerLevel(
index_t branch = 0)
221 std::vector<std::vector<solution_t>> result(m_lvlSolutions[branch].size());
222 for (
size_t l=0; l!=m_lvlSolutions[branch].size(); l++)
223 for (
typename std::vector<solution_t *>::iterator it=m_lvlSolutions[branch][l].begin(); it!=m_lvlSolutions[branch][l].end(); it++)
224 result[l].push_back(**it);
237 const std::vector<T *> & getTimes(
index_t level,
index_t branch = 0)
const {
return m_lvlTimes[branch][level]; }
240 std::vector<T> result;
241 for (
typename std::vector<T *>::iterator it=m_lvlTimes[branch][level].begin(); it!=m_lvlTimes[branch][level].end(); it++)
242 result.push_back(**it);
253 std::vector<std::vector<T>> getTimesPerLevel(
index_t branch = 0)
255 std::vector<std::vector<T>> result(m_lvlTimes[branch].size());
256 for (
size_t l=0; l!=m_lvlSolutions[branch].size(); l++)
257 for (
typename std::vector<T *>::iterator it=m_lvlTimes[branch][l].begin(); it!=m_lvlTimes[branch][l].end(); it++)
258 result[l].push_back(**it);
262 #ifdef GISMO_WITH_MPI
269 bool isMain() {
return (m_rank==0); }
276 index_t rank() {
return (m_rank); }
283 index_t size() {
return m_proc_count; };
286 bool isMain() {
return true; }
293 #ifdef GISMO_WITH_MPI
295 void _sendMainToWorker(
const index_t & workerID,
301 void _sendMainToWorker(
const index_t & workerID,
302 const std::tuple<index_t, T , solution_t, solution_t> & dataEntry,
303 const std::pair<T,T> & dataInterval,
304 const solution_t & dataReference );
306 void _sendMainToWorker(
const index_t & workerID,
307 const std::tuple<index_t, T , solution_t, solution_t> & dataEntry,
308 const T & startTime);
310 void _sendMainToWorker(
const index_t & workerID,
312 void _sendMainToAll(
const bool & stop );
315 void _recvMainToWorker(
const index_t & sourceID,
321 void _recvMainToWorker(
const index_t & sourceID,
322 std::tuple<index_t, T , solution_t, solution_t> & dataEntry,
323 std::pair<T,T> & dataInterval,
324 solution_t & dataReference);
326 void _recvMainToWorker(
const index_t & sourceID,
327 std::tuple<index_t, T , solution_t, solution_t> & dataEntry,
331 void _recvMainToWorker(
const index_t & sourceID,
334 void _sendWorkerToMain(
const index_t & mainID,
339 void _recvWorkerToMain(
index_t & sourceID,
343 void _sendWorkerToMain(
const index_t & mainID,
344 const std::vector<T> & distances,
345 const std::vector<solution_t> & stepSolutions,
346 const T & upperDistance,
347 const T & lowerDistance );
349 void _sendWorkerToMain(
const index_t & mainID,
351 const std::vector<solution_t> & solutions,
352 const bool & bifurcation);
355 void _recvWorkerToMain(
index_t & sourceID,
356 std::vector<T> & distances,
357 std::vector<solution_t>& stepSolutions,
361 void _recvWorkerToMain(
index_t & sourceID,
363 std::vector<solution_t> & stepSolutions,
368 #ifdef GISMO_WITH_MPI
369 const gsMpiComm & comm() {
return m_comm; }
371 const gsSerialComm & comm() {
return m_comm; }
374 template <
bool _hasWorkers>
375 typename std::enable_if< _hasWorkers, void>::type
378 template <
bool _hasWorkers>
379 typename std::enable_if<!_hasWorkers, void>::type
382 template <
bool _hasWorkers>
383 typename std::enable_if< _hasWorkers, void>::type
384 parallelSolve_impl();
386 template <
bool _hasWorkers>
387 typename std::enable_if<!_hasWorkers, void>::type
388 parallelSolve_impl();
390 void _initiation(
const std::tuple<index_t, T , solution_t, solution_t> & dataEntry,
393 std::vector<solution_t>&solutions,
394 bool & bifurcation );
396 void _correction(
const std::tuple<index_t, T , solution_t, solution_t> & dataEntry,
397 const std::pair<T,T> & dataInterval,
399 const solution_t & dataReference,
400 std::vector<T> & distances,
401 std::vector<solution_t>&stepSolutions,
409 std::vector<std::vector<solution_t>> m_solutions;
410 std::vector<std::vector<T>> m_times;
411 std::vector<std::vector<index_t>> m_levels;
413 std::queue<std::tuple<solution_t,T,bool>> m_starts;
415 std::vector<std::vector<std::vector<solution_t * > > > m_lvlSolutions;
416 std::vector<std::vector<std::vector<T * > > > m_lvlTimes;
418 gsALMBase<T> * m_ALM;
419 gsAPALMData<T,solution_t> m_dataEmpty;
420 gsAPALMDataContainer<T,solution_t> m_data;
425 gsOptionList m_options;
427 bool m_singularPoint;
428 T m_branchLengthMult;
434 #ifdef GISMO_WITH_MPI
435 const gsMpiComm * m_comm_dummy =
nullptr;
436 const gsMpiComm & m_comm;
437 std::queue<index_t> m_workers;
439 const gsSerialComm * m_comm_dummy =
nullptr;
440 const gsSerialComm & m_comm;
449 #ifndef GISMO_BUILD_LIB
450 #include GISMO_HPP_HEADER(gsAPALM.hpp)
Helpers for dealing with MPI codes.
T distance(gsMatrix< T > const &A, gsMatrix< T > const &B, index_t i=0, index_t j=0, bool cols=false)
compute a distance between the point number in the set and the point number <j> in the set ; by def...
#define index_t
Definition: gsConfig.h:32
Provides a list of labeled parameters/options that can be set and accessed easily.
Performs the arc length method to solve a nonlinear equation system.
Base class to perform the arc length method to solve a nonlinear equation system. ...
This is the main header file that collects wrappers of Eigen for linear algebra.