Scippy

UG

Ubiquity Generator framework

scipDiffParamSetTh.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-2024 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 scipDiffParamSetTh.cpp
27 * @brief ScipDiffParamSet 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 <cstring>
38#include <cassert>
39#include "scip/scip.h"
40#include "scipDiffParamSetTh.h"
41
42using namespace UG;
43using namespace ParaSCIP;
44
45/** create scipDiffParamSetPreType */
47ScipDiffParamSetTh::createDatatype(
48 )
49{
50 return clone();
51}
52
53/** create clone */
56 )
57{
58 ScipDiffParamSetTh *newParam = new ScipDiffParamSetTh();
59
60 newParam->numBoolParams = numBoolParams;
62 newParam->numIntParams = numIntParams;
66 newParam->numRealParams = numRealParams;
68 newParam->numCharParams = numCharParams;
73
74 newParam->allocateMemoty();
75
76 char *cloneParamName;
77 char *paramName;
78
79 /** copy boolean parameter values */
80 cloneParamName = newParam->boolParamNames;
81 paramName = boolParamNames;
82 for(int i = 0; i < newParam->numBoolParams; i++ )
83 {
84 newParam->boolParamValues[i] = boolParamValues[i];
85 strcpy(cloneParamName, paramName);
86 cloneParamName += strlen(cloneParamName) + 1;
87 paramName += strlen(paramName) + 1;
88 }
89
90 /** copy int parameter values */
91 cloneParamName = newParam->intParamNames;
92 paramName = intParamNames;
93 for(int i = 0; i < newParam->numIntParams; i++ )
94 {
95 newParam->intParamValues[i] = intParamValues[i];
96 strcpy(cloneParamName, paramName);
97 cloneParamName += strlen(cloneParamName) + 1;
98 paramName += strlen(paramName) + 1;
99 }
100
101 /** copy longint parameter values */
102 cloneParamName = newParam->longintParamNames;
103 paramName = longintParamNames;
104 for(int i = 0; i < newParam->numLongintParams; i++ )
105 {
106 newParam->longintParamValues[i] = longintParamValues[i];
107 strcpy(cloneParamName, paramName);
108 cloneParamName += strlen(cloneParamName) + 1;
109 paramName += strlen(paramName) + 1;
110 }
111
112 /** copy real parameter values */
113 cloneParamName = newParam->realParamNames;
114 paramName = realParamNames;
115 for(int i = 0; i < newParam->numRealParams; i++ )
116 {
117 newParam->realParamValues[i] = realParamValues[i];
118 strcpy(cloneParamName, paramName);
119 cloneParamName += strlen(cloneParamName) + 1;
120 paramName += strlen(paramName) + 1;
121 }
122
123 /** copy char parameter values */
124 cloneParamName = newParam->charParamNames;
125 paramName = charParamNames;
126 for(int i = 0; i < newParam->numCharParams; i++ )
127 {
128 newParam->charParamValues[i] = charParamValues[i];
129 strcpy(cloneParamName, paramName);
130 cloneParamName += strlen(cloneParamName) + 1;
131 paramName += strlen(paramName) + 1;
132 }
133
134 /** copy string parameter values */
135 char *cloneParamValue = newParam->stringParamValues;
136 char *paramValue = stringParamValues;
137 cloneParamName = newParam->stringParamNames;
138 paramName = stringParamNames;
139 for(int i = 0; i < newParam->numStringParams; i++ )
140 {
141 strcpy(cloneParamValue, paramValue);
142 cloneParamValue += strlen(cloneParamValue) + 1;
143 paramValue += strlen(paramValue) + 1;
144 strcpy(cloneParamName, paramName);
145 cloneParamName += strlen(cloneParamName) + 1;
146 paramName += strlen(paramName) + 1;
147 }
148
149 return newParam;
150}
151
152void
155 )
156{
157
171
173
174 char *paramName;
175 char *fromParamName;
176
177 /** copy boolean parameter values */
178 paramName = boolParamNames;
179 fromParamName = from->boolParamNames;
180 for(int i = -0; i < from->numBoolParams; i++ )
181 {
182 boolParamValues[i] = from->boolParamValues[i];
183 strcpy(paramName, fromParamName);
184 fromParamName += strlen(fromParamName) + 1;
185 paramName += strlen(paramName) + 1;
186 }
187
188 /** copy int parameter values */
189 paramName = intParamNames;
190 fromParamName = from->intParamNames;
191 for(int i = -0; i < from->numIntParams; i++ )
192 {
193 intParamValues[i] = from->intParamValues[i];
194 strcpy(paramName, fromParamName);
195 fromParamName += strlen(fromParamName) + 1;
196 paramName += strlen(paramName) + 1;
197 }
198
199 /** copy longint parameter values */
200 paramName = longintParamNames;
201 fromParamName = from->longintParamNames;
202 for(int i = -0; i < from->numLongintParams; i++ )
203 {
205 strcpy(paramName, fromParamName);
206 fromParamName += strlen(fromParamName) + 1;
207 paramName += strlen(paramName) + 1;
208 }
209
210 /** copy real parameter values */
211 paramName = realParamNames;
212 fromParamName = from->realParamNames;
213 for(int i = -0; i < from->numRealParams; i++ )
214 {
215 realParamValues[i] = from->realParamValues[i];
216 strcpy(paramName, fromParamName);
217 fromParamName += strlen(fromParamName) + 1;
218 paramName += strlen(paramName) + 1;
219 }
220
221 /** copy char parameter values */
222 paramName = charParamNames;
223 fromParamName = from->charParamNames;
224 for(int i = -0; i < from->numCharParams; i++ )
225 {
226 charParamValues[i] = from->charParamValues[i];
227 strcpy(paramName, fromParamName);
228 fromParamName += strlen(fromParamName) + 1;
229 paramName += strlen(paramName) + 1;
230 }
231
232 /** copy string parameter values */
233 char *paramValue = stringParamValues;
234 char *fromParamValue = from->stringParamValues;
235 paramName = stringParamNames;
236 fromParamName = from->stringParamNames;
237 for(int i = -0; i < from->numStringParams; i++ )
238 {
239 strcpy(paramValue, fromParamValue);
240 fromParamValue += strlen(fromParamValue) + 1;
241 paramValue += strlen(paramValue) + 1;
242 strcpy(paramName, fromParamName);
243 fromParamName += strlen(fromParamName) + 1;
244 paramName += strlen(paramName) + 1;
245 }
246}
247
248/** send solution data to the rank */
249int
251 ParaComm *comm,
252 int root
253 )
254{
255 DEF_PARA_COMM( commTh, comm);
256
257 if( commTh->getRank() == root )
258 {
259 for( int i = 0; i < commTh->getSize(); i++ )
260 {
261 if( i != root )
262 {
263 ScipDiffParamSetTh *sent;
264 sent = createDatatype();
266 commTh->uTypeSend((void *)sent, UG::ParaSolverDiffParamType, i, UG::TagSolverDiffParamSet)
267 );
268 }
269 }
270 }
271 else
272 {
273 ScipDiffParamSetTh *received;
275 commTh->uTypeReceive((void **)&received, UG::ParaSolverDiffParamType, root, UG::TagSolverDiffParamSet)
276 );
277 setValues(received);
278 delete received;
279 }
280
281 return 0;
282}
283
284/** send solution data to the rank */
285int
287 ParaComm *comm,
288 int dest
289 )
290{
291 DEF_PARA_COMM( commTh, comm);
292
294 commTh->uTypeSend((void *)createDatatype(), UG::ParaSolverDiffParamType, dest, UG::TagSolverDiffParamSet)
295 );
296
297 return 0;
298}
299
300 /** receive solution data from the source rank */
301int
303 ParaComm *comm,
304 int source
305 )
306 {
307 DEF_PARA_COMM( commTh, comm);
308
309 ScipDiffParamSetTh *received;
311 commTh->uTypeReceive((void **)&received, UG::ParaSolverDiffParamType, source, UG::TagSolverDiffParamSet)
312 );
313 setValues(received);
314 delete received;
315
316 return 0;
317 }
int receive(UG::ParaComm *comm, int source)
int bcast(UG::ParaComm *comm, int root)
ScipDiffParamSetTh * createDatatype()
int send(UG::ParaComm *comm, int destination)
void setValues(ScipDiffParamSetTh *from)
ScipDiffParamSetTh * clone()
Base class of communicator object.
Definition: paraComm.h:102
static ScipParaCommTh * comm
Definition: fscip.cpp:73
static const int ParaSolverDiffParamType
static const int TagSolverDiffParamSet
Definition: bbParaTagDef.h:68
#define DEF_PARA_COMM(para_comm, comm)
#define PARA_COMM_CALL(paracommcall)
Definition: paraComm.h:47
ScipDiffParamSet extension for threads communication.