Scippy

UG

Ubiquity Generator framework

bbParaNodeTh.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 paraNodeTh.cpp
27  * @brief BbParaNode 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 #include "bbParaComm.h"
37 #include "bbParaNodeTh.h"
38 
39 using namespace UG;
40 
43  ParaComm *comm
44  )
45 {
46  return clone(comm);
47 }
48 
49 int
51  ParaComm *comm,
52  int root
53  )
54 {
55  DEF_PARA_COMM( commTh, comm);
56 
57  if( commTh->getRank() == root )
58  {
59  for( int i = 0; i < commTh->getSize(); i++ )
60  {
61  if( i != root )
62  {
63  BbParaNodeTh *sent;
64  sent = createDatatype(comm);
65  assert(!(sent->mergeNodeInfo));
66  sent->mergeNodeInfo = 0;
68  commTh->uTypeSend((void *)sent, ParaTaskType, i, TagTask)
69  );
70  }
71  }
72  }
73  else
74  {
75  BbParaNodeTh *received;
77  commTh->uTypeReceive((void **)&received, ParaTaskType, root, TagTask)
78  );
79  taskId = received->taskId;
80  generatorTaskId = received->generatorTaskId;
81  depth = received->depth;
82  dualBoundValue = received->dualBoundValue;
83  initialDualBoundValue = received->initialDualBoundValue;
84  estimatedValue = received->estimatedValue;
85  diffSubproblemInfo = received->diffSubproblemInfo;
86  if( diffSubproblemInfo )
87  {
88  diffSubproblem = received->diffSubproblem->clone(commTh);
89  }
90  basisInfo = received->basisInfo;
91  mergingStatus = received->mergingStatus;
92  delete received;
93  }
94  return 0;
95 }
96 
97 int
99  ParaComm *comm,
100  int destination
101  )
102 {
103  DEF_PARA_COMM( commTh, comm);
104 
105  BbParaNodeTh *sent;
106  sent = createDatatype(comm);
107  assert(!(sent->mergeNodeInfo));
108  sent->mergeNodeInfo = 0;
110  commTh->uTypeSend((void *)sent, ParaTaskType, destination, TagTask)
111  );
112 
113  return 0;
114 }
115 
116 int
118  ParaComm *comm,
119  int destination
120  )
121 {
122 
123  assert( !this->isRootTask() );
124  DEF_PARA_COMM( commTh, comm);
125 
126  BbParaNodeTh *sent;
127  sent = createDatatype(comm);
128  assert(!(sent->mergeNodeInfo));
129  sent->mergeNodeInfo = 0;
131  commTh->uTypeSend((void *)sent, ParaTaskType, destination, TagNewSubtreeRootNode)
132  );
133 
134  return 0;
135 }
136 
137 int
139  ParaComm *comm,
140  int destination, ///< destination rank
141  int tag
142  )
143 {
144  DEF_PARA_COMM( commTh, comm);
145 
146  BbParaNodeTh *sent;
147  sent = createDatatype(comm);
148  assert(!(sent->mergeNodeInfo));
149  sent->mergeNodeInfo = 0;
151  commTh->uTypeSend((void *)sent, ParaTaskType, destination, tag)
152  );
153 
154  return 0;
155 }
156 
157 //int
158 //BbParaNodeTh::sendReassignSelfSplitSubtreeRoot(
159 // ParaComm *comm,
160 // int destination ///< destination rank
161 // )
162 //{
163 // DEF_PARA_COMM( commTh, comm);
164 //
165 // BbParaNodeTh *sent;
166 // sent = createDatatype(comm);
167 // assert(!(sent->mergeNodeInfo));
168 // sent->mergeNodeInfo = 0;
169 // PARA_COMM_CALL(
170 // commTh->uTypeSend((void *)sent, ParaTaskType, destination, TagReassignSelfSplitSubtreeRootNode)
171 // );
172 //
173 // return 0;
174 //}
175 
176 
177 int
179  ParaComm *comm,
180  int source
181  )
182 {
183  DEF_PARA_COMM( commTh, comm);
184 
185  BbParaNodeTh *received;
187  commTh->uTypeReceive((void **)&received, ParaTaskType, source, TagTask)
188  );
189  taskId = received->taskId;
190  generatorTaskId = received->generatorTaskId;
191  depth = received->depth;
192  dualBoundValue = received->dualBoundValue;
193  initialDualBoundValue = received->initialDualBoundValue;
194  estimatedValue = received->estimatedValue;
195  diffSubproblemInfo = received->diffSubproblemInfo;
196  if( diffSubproblemInfo )
197  {
198  diffSubproblem = received->diffSubproblem->clone(commTh);
199  }
200  basisInfo = received->basisInfo;
201  mergingStatus = received->mergingStatus;
202  delete received;
203 
204  return 0;
205 }
206 
207 int
209  ParaComm *comm,
210  int source
211  )
212 {
213  DEF_PARA_COMM( commTh, comm);
214 
215  BbParaNodeTh *received;
217  commTh->uTypeReceive((void **)&received, ParaTaskType, source, TagNewSubtreeRootNode)
218  );
219  taskId = received->taskId;
220  generatorTaskId = received->generatorTaskId;
221  depth = received->depth;
222  dualBoundValue = received->dualBoundValue;
223  initialDualBoundValue = received->initialDualBoundValue;
224  estimatedValue = received->estimatedValue;
225  diffSubproblemInfo = received->diffSubproblemInfo;
226  if( diffSubproblemInfo )
227  {
228  diffSubproblem = received->diffSubproblem->clone(commTh);
229  }
230  basisInfo = received->basisInfo;
231  mergingStatus = received->mergingStatus;
232  delete received;
233 
234  return 0;
235 }
236 
237 int
239  ParaComm *comm,
240  int source,
241  int tag
242  )
243 {
244  DEF_PARA_COMM( commTh, comm);
245 
246  BbParaNodeTh *received;
248  commTh->uTypeReceive((void **)&received, ParaTaskType, source, tag)
249  );
250  taskId = received->taskId;
251  generatorTaskId = received->generatorTaskId;
252  delete received;
253 
254  return 0;
255 }
256 
257 //int
258 //BbParaNodeTh::receiveReassignSelfSplitSubtreeRoot(
259 // ParaComm *comm,
260 // int source
261 // )
262 //{
263 // DEF_PARA_COMM( commTh, comm);
264 //
265 // BbParaNodeTh *received;
266 // PARA_COMM_CALL(
267 // commTh->uTypeReceive((void **)&received, ParaTaskType, source, TagReassignSelfSplitSubtreeRootNode)
268 // );
269 // taskId = received->taskId;
270 // generatorTaskId = received->generatorTaskId;
271 // delete received;
272 //
273 // return 0;
274 //}
double estimatedValue
estimate value
Definition: paraTask.h:556
double dualBoundValue
dual bound value
Definition: bbParaNode.h:67
int basisInfo
indicate if basis information is including or not
Definition: bbParaNode.h:70
static const int TagNewSubtreeRootNode
Definition: bbParaTagDef.h:72
static ScipParaCommTh * comm
Definition: fscip.cpp:73
BbParaNodeTh * clone(ParaComm *comm)
clone this BbParaNodeTh
Definition: bbParaNodeTh.h:99
int sendSubtreeRootNodeId(ParaComm *comm, int destination, int tag)
send subtree root to be removed
int bcast(ParaComm *comm, int root)
broadcast this object
bool isRootTask()
check if root task or not
Definition: paraTask.h:624
int receiveNewSubtreeRoot(ParaComm *comm, int source)
receive this object
int diffSubproblemInfo
1: with diffSubproblem, 0: no diffSubproblem
Definition: paraTask.h:557
double initialDualBoundValue
dual bound value when this node is created This value is updated to precise one when there is guarant...
Definition: bbParaNode.h:68
#define PARA_COMM_CALL(paracommcall)
Definition: paraComm.h:47
TaskId generatorTaskId
subtree root task id of generator
Definition: paraTask.h:550
ParaDiffSubproblem * diffSubproblem
difference between solving instance data and subproblem data
Definition: paraTask.h:558
int mergingStatus
merging status: -1 - no merging node, 0 - checking, 1 - merged (representative) 2 - merged to the oth...
Definition: bbParaNode.h:71
BbParaMergeNodeInfo * mergeNodeInfo
pointer to mergeNodeInfo. Not zero means merging
Definition: bbParaNode.h:78
BbParaNodeTh * createDatatype(ParaComm *comm)
create BbParaNode datatype
#define DEF_PARA_COMM(para_comm, comm)
virtual ParaDiffSubproblem * clone(ParaComm *comm)=0
create clone of this object
class BbParaNodeTh
Definition: bbParaNodeTh.h:51
int receive(ParaComm *comm, int source)
receive this object
int sendNewSubtreeRoot(ParaComm *comm, int destination)
send new subtree root node
static const int TagTask
Definition: paraTagDef.h:47
static const int ParaTaskType
int depth
depth from the root node of original tree
Definition: bbParaNode.h:66
int receiveSubtreeRootNodeId(ParaComm *comm, int source, int tag)
receive this object node Id
TaskId taskId
solving task information
Definition: paraTask.h:549
int send(ParaComm *comm, int destination)
send this object
Base class of communicator object.
Definition: paraComm.h:101