Scippy

UG

Ubiquity Generator framework

scipParaSolutionTh.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 scipParaSolutionTh.cpp
27  * @brief ScipParaSolution 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 "scipParaSolutionTh.h"
38 
39 using namespace UG;
40 using namespace ParaSCIP;
41 
42 /** create clone of this object */
44 ScipParaSolutionTh::clone(UG::ParaComm *comm)
45 {
46  return( new ScipParaSolutionTh(objectiveFunctionValue, nVars, indicesAmongSolvers, values));
47 }
48 
49 /** create ScipDiffSubproblemPreDatatype */
51 ScipParaSolutionTh::createDatatype(
53  )
54 {
55  return clone(comm);
56 }
57 
58 /** send solution data to the rank */
59 void
60 ScipParaSolutionTh::bcast(ParaComm *comm, int root)
61 {
62  DEF_PARA_COMM( commTh, comm);
63 
64  if( commTh->getRank() == root )
65  {
66  for( int i = 0; i < commTh->getSize(); i++ )
67  {
68  if( i != root )
69  {
71  commTh->uTypeSend((void *)createDatatype(comm), ParaSolutionType, i, TagSolution)
72  );
73  }
74  }
75  }
76  else
77  {
78  ScipParaSolutionTh *received;
80  commTh->uTypeReceive((void **)&received, ParaSolutionType, root, TagSolution)
81  );
82 
83  objectiveFunctionValue = received->objectiveFunctionValue;
84  nVars = received->nVars;
85  indicesAmongSolvers = new int[nVars];
86  values = new SCIP_Real[nVars];
87  for( int i = 0; i < nVars; i++ )
88  {
89  indicesAmongSolvers[i] = received->indicesAmongSolvers[i];
90  values[i] = received->values[i];
91  }
92  delete received;
93  }
94 }
95 
96 /** send solution data to the rank */
97 void
98 ScipParaSolutionTh::send(ParaComm *comm, int destination)
99 {
100  DEF_PARA_COMM( commTh, comm);
102  commTh->uTypeSend((void *)createDatatype(comm), ParaSolutionType, destination, TagSolution)
103  );
104 }
105 
106 /** receive solution data from the source rank */
107 void
108 ScipParaSolutionTh::receive(ParaComm *comm, int source)
109 {
110  DEF_PARA_COMM( commTh, comm);
111 
112  ScipParaSolutionTh *received;
114  commTh->uTypeReceive((void **)&received, ParaSolutionType, source, TagSolution)
115  );
116 
117  objectiveFunctionValue = received->objectiveFunctionValue;
118  nVars = received->nVars;
119  indicesAmongSolvers = new int[nVars];
120  values = new SCIP_Real[nVars];
121  for( int i = 0; i < nVars; i++ )
122  {
123  indicesAmongSolvers[i] = received->indicesAmongSolvers[i];
124  values[i] = received->values[i];
125  }
126  delete received;
127 
128 }
ScipParaSolution extension for threads communication.
static ScipParaCommTh * comm
Definition: fscip.cpp:73
#define PARA_COMM_CALL(paracommcall)
Definition: paraComm.h:47
static const int TagSolution
Definition: paraTagDef.h:51
#define DEF_PARA_COMM(para_comm, comm)
static const int ParaSolutionType
Definition: paraCommCPP11.h:99
Base class of communicator object.
Definition: paraComm.h:101