Scippy

UG

Ubiquity Generator framework

scipParaCommTh.cpp
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 scipParaCommTh.cpp
27  * @brief SCIP ParaComm extension for threads 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 #include "scipParaCommTh.h"
38 #include "scipParaInstanceTh.h"
40 #include "scipParaSolutionTh.h"
41 #include "scipParaInitialStatTh.h"
43 #include "scipDiffParamSetTh.h"
44 #include "scipParaParamSet.h"
45 #include "scipParaInitialStat.h"
46 
47 using namespace ParaSCIP;
48 
49 const char *
52 };
53 
54 bool
56  )
57 {
58 #ifdef _COMM_CPP11
60 #else
62 #endif
63  // std::cout << "size = " << sizeof(tagStringTable)/sizeof(char*)
64  // << ", (N_SCIP_TH_TAGS - UG::N_BB_TH_TAGS) = " << (N_SCIP_TH_TAGS - UG::N_BB_TH_TAGS) << std::endl;
65  return ( sizeof(tagStringTable)/sizeof(char*) == (N_SCIP_TH_TAGS - UG::N_BB_TH_TAGS) );
66 }
67 
68 const char *
70  int tag /// tag to be converted to string
71  )
72 {
73  assert( tag >= 0 && tag < N_SCIP_TH_TAGS );
74  if( tag >= 0 && tag < TAG_SCIP_FIRST )
75  {
76 #ifdef _COMM_CPP11
78 #else
79  return BbParaCommPth::getTagString(tag);
80 #endif
81  }
82  else
83  {
84  return tagStringTable[(tag - TAG_SCIP_FIRST)];
85  }
86 }
87 
89  )
90 {
91 #ifdef _COMM_CPP11
92  std::lock_guard<std::mutex> lock(rankLockMutex);
93 #else
94  UG::LOCK_RAII(&rankLock);
95 #endif
96  for(int i = 0; i < (comSize + 1); i++)
97  {
98  UG::MessageQueueElement *elem = messageQueueTable[i]->extarctElement(&sentMessage[i]);
99  while( elem )
100  {
101  if( elem->getData() )
102  {
103  if( !freeStandardTypes(elem) )
104  {
105  switch( elem->getDataTypeId())
106  {
108  {
109  delete reinterpret_cast<ScipDiffParamSet *>(elem->getData());
110  break;
111  }
112  case ParaInitialStatType:
113  {
114  delete reinterpret_cast<ScipParaInitialStat *>(elem->getData());
115  break;
116  }
117  default:
118  {
119  ABORT_LOGICAL_ERROR2("Requested type is not implemented. Type = ", elem->getDataTypeId() );
120  }
121  }
122  }
123  }
124  delete elem;
125  elem = messageQueueTable[i]->extarctElement(&sentMessage[i]);
126  }
127  }
128 }
129 
130 /*******************************************************************************
131 * transfer object factory
132 *******************************************************************************/
135  )
136 {
137  return new ScipParaDiffSubproblemTh();
138 }
139 
142  )
143 {
144  return new ScipParaInitialStatTh();
145 }
146 
149  )
150 {
151  return new ScipParaRacingRampUpParamSetTh();
152 }
153 
156  )
157 {
158  return new ScipParaInstanceTh();
159 }
160 
163  )
164 {
165  return new ScipParaSolutionTh();
166 }
167 
170  )
171 {
172  return new ScipParaParamSet();
173 }
174 
175 
178  SCIP *scip,
179  int method
180  )
181 {
182  return new ScipParaInstanceTh(scip, method);
183 }
184 
187  ScipParaSolver *solver,
188  SCIP_Real objval,
189  int inNvars,
190  SCIP_VAR ** vars,
191  SCIP_Real *vals
192  )
193 {
194  return new ScipParaSolutionTh(solver, objval, inNvars, vars, vals);
195 }
196 
199  SCIP_Real objval,
200  int inNvars,
201  int *inIndicesAmongSolvers,
202  SCIP_Real *vals
203  )
204 {
205  return new ScipParaSolutionTh(objval, inNvars, inIndicesAmongSolvers, vals);
206 }
207 
210  SCIP *scip,
211  ScipParaSolver *scipParaSolver,
212  int nNewBranchVars,
213  SCIP_VAR **newBranchVars,
214  SCIP_Real *newBranchBounds,
215  SCIP_BOUNDTYPE *newBoundTypes,
216  int nAddedConss,
217  SCIP_CONS **addedConss
218  )
219 {
220  return new ScipParaDiffSubproblemTh(
221  scip,
222  scipParaSolver,
223  nNewBranchVars,
224  newBranchVars,
225  newBranchBounds,
226  newBoundTypes,
227  nAddedConss,
228  addedConss
229  );
230 }
231 
234  SCIP *scip
235  )
236 {
237  return new ScipParaInitialStatTh(
238  scip
239  );
240 }
241 
244  int inMaxDepth,
245  int inMaxTotalDepth,
246  int inNVarBranchStatsDown,
247  int inNVarBranchStatsUp,
248  int *inIdxLBranchStatsVarsDown,
249  int *inNVarBranchingDown,
250  int *inIdxLBranchStatsVarsUp,
251  int *inNVarBranchingUp,
252  SCIP_Real *inDownpscost,
253  SCIP_Real *inDownvsids,
254  SCIP_Real *inDownconflen,
255  SCIP_Real *inDowninfer,
256  SCIP_Real *inDowncutoff,
257  SCIP_Real *inUppscost,
258  SCIP_Real *inUpvsids,
259  SCIP_Real *inUpconflen,
260  SCIP_Real *inUpinfer,
261  SCIP_Real *inUpcutoff
262  )
263 {
264  return new ScipParaInitialStatTh(
265  inMaxDepth,
266  inMaxTotalDepth,
267  inNVarBranchStatsDown,
268  inNVarBranchStatsUp,
269  inIdxLBranchStatsVarsDown,
270  inNVarBranchingDown,
271  inIdxLBranchStatsVarsUp,
272  inNVarBranchingUp,
273  inDownpscost,
274  inDownvsids,
275  inDownconflen,
276  inDowninfer,
277  inDowncutoff,
278  inUppscost,
279  inUpvsids,
280  inUpconflen,
281  inUpinfer,
282  inUpcutoff
283  );
284 }
285 
288  int inTerminationCriteria,
289  int inNNodesLeft,
290  double inTimeLimit,
291  int inScipRacingParamSeed,
292  int inPermuteProbSeed,
293  int inGenerateBranchOrderSeed,
294  ScipDiffParamSet *inScipDiffParamSet
295  )
296 {
298  inTerminationCriteria,
299  inNNodesLeft,
300  inTimeLimit,
301  inScipRacingParamSeed,
302  inPermuteProbSeed,
303  inGenerateBranchOrderSeed,
304  inScipDiffParamSet
305  );
306 }
307 
310 {
311  return new ScipDiffParamSetTh();
312 }
313 
316  SCIP *scip
317  )
318 {
319  return new ScipDiffParamSetTh(scip);
320 }
virtual bool tagStringTableIsSetUpCoorectly()
check if tag string table (for debugging) set up correctly
static const char * tagStringTable[]
mutex for interrupt message monitor
int getDataTypeId()
getter of the data type id
UG::ParaParamSet * createParaParamSet()
ScipParaDiffSubproblem * createScipParaDiffSubproblem(SCIP *scip, ScipParaSolver *scipParaSolver, int nNewBranchVars, SCIP_VAR **newBranchVars, SCIP_Real *newBranchBounds, SCIP_BOUNDTYPE *newBoundTypes, int nAddedConss, SCIP_CONS **addedConss)
ScipParaSolution extension for threads communication.
ScipParaSolution * createScipParaSolution(ScipParaSolver *solver, SCIP_Real objval, int inNvars, SCIP_VAR **vars, SCIP_Real *vals)
class BbParaParamSet
const char * getTagString(int tag)
get Tag string for debugging
UG::ParaInstance * createParaInstance()
Class for message queue element.
ScipParaDiffSubproblem extension for threads communication.
UG::ParaDiffSubproblem * createParaDiffSubproblem()
UG::ParaSolution * createParaSolution()
ScipParaInitialStat * createScipParaInitialStat(SCIP *scip)
UG::ParaRacingRampUpParamSet * createParaRacingRampUpParamSet()
ScipDiffParamSet extension for threads communication.
static const int ParaSolverDiffParamType
ScipParaInitialStat extension for threads communication.
SCIP ParaComm extension for threads communication.
class ParaParamSet
Definition: paraParamSet.h:850
class for instance data
Definition: paraInstance.h:50
UG::ParaInitialStat * createParaInitialStat()
Class for the difference between instance and subproblem.
std::mutex rankLockMutex
virtual bool tagStringTableIsSetUpCoorectly()
check if tag string table (for debugging) set up correctly
ScipParaRacingRampUpParamSet extension for threads communication.
ScipParaInstance extension for threads communication.
void * getData()
getter of data
#define LOCK_RAII(lck)
Definition: paraPthLock.h:295
class for initial statistics collecting after racing
#define TAG_STR(tag)
Definition: paraTagDef.h:40
static const int TAG_SCIP_FIRST
static const int TagInitialStat
bool tagStringTableIsSetUpCoorectly()
check if tag string table (for debugging) set up correctly
ScipParaRacingRampUpParamSet * createScipParaRacingRampUpParamSet(int inTerminationCriteria, int inNNodesLeft, double inTimeLimit, int inScipRacingParamSeed, int inPermuteProbSeed, int inGenerateBranchOrderSeed, ScipDiffParamSet *inScipDiffParamSet)
ScipParaInstance * createScipParaInstance(SCIP *scip, int method)
ScipDiffParamSet * createScipDiffParamSet()
static const int ParaInitialStatType
class ParaRacingRampUpParamSet (parameter set for racing ramp-up)
#define ABORT_LOGICAL_ERROR2(msg1, msg2)
Definition: paraDef.h:78
ParaInitialStat extension for SCIP solver.
class for solution
Definition: paraSolution.h:53