Scippy

UG

Ubiquity Generator framework

scipParaCommMpi.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and software framework */
4 /* UG --- Ubquity Generator Framework */
5 /* */
6 /* Copyright Written by Yuji Shinano <shinano@zib.de>, */
7 /* Copyright (C) 2021 by Zuse Institute Berlin, */
8 /* licensed under LGPL version 3 or later. */
9 /* Commercial licenses are available through <licenses@zib.de> */
10 /* */
11 /* This code is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public License */
13 /* as published by the Free Software Foundation; either version 3 */
14 /* of the License, or (at your option) any later version. */
15 /* */
16 /* This program is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19 /* GNU Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* */
24 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25 
26 /**@file scipParaCommMpi.h
27  * @brief SCIP ParaComm extension for MPI communication.
28  * @author Yuji Shinano
29  *
30  *
31  *
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 
37 #ifndef __SCIP_PARA_COMM_MPI_H__
38 #define __SCIP_PARA_COMM_MPI_H__
39 #include "ug_bb/bbParaCommMpi.h"
40 #include "scipParaInstance.h"
41 #include "scipDiffParamSet.h"
42 #include "scipParaInstanceMpi.h"
43 #include "scipParaSolutionMpi.h"
45 #include "scipParaInitialStatMpi.h"
47 #include "scip/scip.h"
48 #ifdef UG_WITH_UGS
49 #include "ugs/ugsParaCommMpi.h"
50 #endif
51 
52 namespace ParaSCIP
53 {
54 
55 class ScipParaSolver;
56 
58 {
59 
60  std::mutex interruptMsgMonitorLockMutex; ///< mutex for interrupt message monitor
61 
62 protected:
63 
64  static const char *tagStringTable[]; ///< tag name string table
65 
66  ///
67  /// check if tag string table (for debugging) set up correctly
68  /// @return true if tag string table is set up correctly, false otherwise
69  ///
71  );
72 
73  ///
74  /// get Tag string for debugging
75  /// @return string which shows Tag
76  ///
77  const char *getTagString(
78  int tag /// tag to be converted to string
79  );
80 
81 public:
82 #ifdef UG_WITH_UGS
83  ScipParaCommMpi(){}
84  ScipParaCommMpi( MPI_Comm inComm) : ParaCommMpi(inComm)
85  {
86  MPI_CALL(
87  MPI_Comm_rank(myComm, &myRank)
88  );
89  MPI_CALL(
90  MPI_Comm_size(myComm, &myCommSize)
91  );
92  }
93  void setUgsComm( UGS::UgsParaCommMpi *inCommUgs )
94  {
95  commUgs = inCommUgs;
96  }
97 #else
99 #endif
101  void init(int argc, char **argv)
102  {
103  UG::ParaCommMpi::init(argc,argv);
104 #ifdef UG_WITH_UGS
105  if( !commUgs )
106  {
107  myComm = MPI_COMM_WORLD;
108  MPI_CALL(
109  MPI_Comm_rank(myComm, &myRank)
110  );
111  MPI_CALL(
112  MPI_Comm_size(myComm, &myCommSize)
113  );
114  }
115 #else
116  myComm = MPI_COMM_WORLD;
117  MPI_CALL(
118  MPI_Comm_rank(myComm, &myRank)
119  );
120  MPI_CALL(
121  MPI_Comm_size(myComm, &myCommSize)
122  );
123 #endif
124  }
125 
126  ///
127  /// lock interrupt message monitor to synchronize with the monitor thread
128  ///
130  )
131  {
132  interruptMsgMonitorLockMutex.lock();
133  }
134 
135  ///
136  /// unlock interrupt message monitor to synchronize with the monitor thread
137  ///
139  )
140  {
141  interruptMsgMonitorLockMutex.unlock();
142  }
143 
144  /*******************************************************************************
145  * transfer object factory
146  *******************************************************************************/
153 
154  ScipParaInstance *createScipParaInstance(SCIP *scip, int method);
155  ScipParaSolution *createScipParaSolution(ScipParaSolver *solver, SCIP_Real objval, int inNvars, SCIP_VAR ** vars, SCIP_Real *vals);
156  ScipParaSolution *createScipParaSolution(SCIP_Real objval, int inNvars, int *inIndicesAmongSolvers, SCIP_Real *vals);
158  SCIP *scip,
159  ScipParaSolver *scipParaSolver,
160  int nNewBranchVars,
161  SCIP_VAR **newBranchVars,
162  SCIP_Real *newBranchBounds,
163  SCIP_BOUNDTYPE *newBoundTypes,
164  int nAddedConss,
165  SCIP_CONS **addedConss
166  );
169  int inMaxDepth,
170  int inMaxTotalDepth,
171  int inNVarBranchStatsDown,
172  int inNVarBranchStatsUp,
173  int *inIdxLBranchStatsVarsDown,
174  int *inNVarBranchingDown,
175  int *inIdxLBranchStatsVarsUp,
176  int *inNVarBranchingUp,
177  SCIP_Real *inDownpscost,
178  SCIP_Real *inDownvsids,
179  SCIP_Real *inDownconflen,
180  SCIP_Real *inDowninfer,
181  SCIP_Real *inDowncutoff,
182  SCIP_Real *inUppscost,
183  SCIP_Real *inUpvsids,
184  SCIP_Real *inUpconflen,
185  SCIP_Real *inUpinfer,
186  SCIP_Real *inUpcutoff
187  );
189  int inTerminationCriteria,
190  int inNNodesLeft,
191  double inTimeLimit,
192  int inScipRacingParamSeed,
193  int inPermuteProbSeed,
194  int inGenerateBranchOrderSeed,
195  ScipDiffParamSet *inScipDiffParamSet
196  );
199 };
200 
201 #define DEF_SCIP_PARA_COMM( scip_para_comm, comm ) ScipParaCommMpi *scip_para_comm = dynamic_cast< ScipParaCommMpi* >(comm)
202 
203 }
204 #endif // __SCIP_PARA_COMM_MPI_H__
ScipParaInstance extension for MPI communication.
UG::ParaInstance * createParaInstance()
static const char * tagStringTable[]
tag name string table
UG::ParaDiffSubproblem * createParaDiffSubproblem()
ParaInstance extenstion for SCIP solver.
ScipParaInitialStat * createScipParaInitialStat(SCIP *scip)
virtual void init(int argc, char **argv)
initializer of this communicator
ParaCommMpi()
default constructor of ParaCommMpi
Definition: paraCommMpi.h:138
const char * getTagString(int tag)
get Tag string for debugging
int myCommSize
communicator size : number of processes joined in this system
Definition: paraCommMpi.h:97
void init(int argc, char **argv)
ScipParaInstance * createScipParaInstance(SCIP *scip, int method)
void unlockInterruptMsg()
unlock interrupt message monitor to synchronize with the monitor thread
ScipParaSolution extension for MPI communication.
ScipParaRacingRampUpParamSet * createScipParaRacingRampUpParamSet(int inTerminationCriteria, int inNNodesLeft, double inTimeLimit, int inScipRacingParamSeed, int inPermuteProbSeed, int inGenerateBranchOrderSeed, ScipDiffParamSet *inScipDiffParamSet)
Communicator object for MPI communications.
Definition: bbParaCommMpi.h:76
ScipParaRacingRampUpParamSet extension for MPI communication.
ScipParaSolution * createScipParaSolution(ScipParaSolver *solver, SCIP_Real objval, int inNvars, SCIP_VAR **vars, SCIP_Real *vals)
bool tagStringTableIsSetUpCoorectly()
check if tag string table (for debugging) set up correctly
ScipDiffParamSet * createScipDiffParamSet()
UG::ParaRacingRampUpParamSet * createParaRacingRampUpParamSet()
class ParaParamSet
Definition: paraParamSet.h:850
SCIP parameter set to be transferred ( Only keep difference between default settings )...
MPI_Comm myComm
MPI communicator.
Definition: paraCommMpi.h:96
class for instance data
Definition: paraInstance.h:50
Class for the difference between instance and subproblem.
std::mutex interruptMsgMonitorLockMutex
mutex for interrupt message monitor
ScipParaDiffSubproblem extension for MPI communication.
UG::ParaParamSet * createParaParamSet()
ScipParaInitialStat extension for MPI communication.
ScipParaDiffSubproblem * createScipParaDiffSubproblem(SCIP *scip, ScipParaSolver *scipParaSolver, int nNewBranchVars, SCIP_VAR **newBranchVars, SCIP_Real *newBranchBounds, SCIP_BOUNDTYPE *newBoundTypes, int nAddedConss, SCIP_CONS **addedConss)
class for initial statistics collecting after racing
UG::ParaSolution * createParaSolution()
UG::ParaInitialStat * createParaInitialStat()
void lockInterruptMsg()
lock interrupt message monitor to synchronize with the monitor thread
class ParaRacingRampUpParamSet (parameter set for racing ramp-up)
#define MPI_CALL(mpicall)
Definition: paraCommMpi.h:68
int myRank
rank of this process
Definition: paraCommMpi.h:98
class for solution
Definition: paraSolution.h:53