Scippy

UG

Ubiquity Generator framework

scipParaRacingRampUpParamSetMpi.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 scipParaRacingRampUpParamSetMpi.cpp
27  * @brief ScipParaRacingRampUpParamSet 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 #include "scipParaCommMpi.h"
38 #include "scipDiffParamSetMpi.h"
40 #include <cstring>
41 
42 using namespace UG;
43 using namespace ParaSCIP;
44 
45 /** create Datatype */
46 MPI_Datatype
47 ScipParaRacingRampUpParamSetMpi::createDatatype(
48  )
49 {
50  const int nBlocks = 7;
51 
52  MPI_Datatype datatype;
53 
54  int blockLengths[nBlocks];
55  MPI_Aint displacements[nBlocks];
56  MPI_Datatype types[nBlocks];
57 
58  MPI_Aint startAddress = 0;
59  MPI_Aint address = 0;
60 
61  for( int i = 0; i < nBlocks; i++ )
62  {
63  blockLengths[i] = 1;
64  types[i] = MPI_INT;
65  }
66  MPI_CALL(
67  MPI_Get_address( &terminationCriteria, &startAddress )
68  );
69  displacements[0] = 0;
70  MPI_CALL(
71  MPI_Get_address( &nNodesLeft, &address )
72  );
73  displacements[1] = address - startAddress;
74  MPI_CALL(
75  MPI_Get_address( &timeLimit, &address )
76  );
77  displacements[2] = address - startAddress;
78  MPI_CALL(
79  MPI_Get_address( &scipRacingParamSeed, &address )
80  );
81  displacements[3] = address - startAddress;
82  MPI_CALL(
83  MPI_Get_address( &permuteProbSeed, &address )
84  );
85  displacements[4] = address - startAddress;
86  MPI_CALL(
87  MPI_Get_address( &generateBranchOrderSeed, &address )
88  );
89  displacements[5] = address - startAddress;
90  MPI_CALL(
91  MPI_Get_address( &scipDiffParamSetInfo, &address )
92  );
93  displacements[6] = address - startAddress;
94 
95  types[2] = MPI_DOUBLE;
96 
97  MPI_CALL(
98  MPI_Type_create_struct(nBlocks, blockLengths, displacements, types, &datatype)
99  );
100 
101  return datatype;
102 
103 }
104 
105 int
106 ScipParaRacingRampUpParamSetMpi::send(
107  ParaComm *comm,
108  int dest)
109 {
110 
111  DEF_PARA_COMM( commMpi, comm);
112 
113  MPI_Datatype datatype;
114  datatype = createDatatype();
115  MPI_CALL(
116  MPI_Type_commit( &datatype )
117  );
119  commMpi->usend(&terminationCriteria, 1, datatype, dest, TagRacingRampUpParamSet)
120  );
121  MPI_CALL(
122  MPI_Type_free( &datatype )
123  );
124 
125  if( scipDiffParamSetInfo )
126  {
127  scipDiffParamSet->send(commMpi, dest);
128  }
129 
130  return 0;
131 
132 }
133 
134 int
135 ScipParaRacingRampUpParamSetMpi::receive(
136  ParaComm *comm,
137  int source)
138 {
139 
140  DEF_PARA_COMM( commMpi, comm);
141 
142  MPI_Datatype datatype;
143  datatype = createDatatype();
144  MPI_CALL(
145  MPI_Type_commit( &datatype )
146  );
148  commMpi->ureceive(&terminationCriteria, 1, datatype, source, TagRacingRampUpParamSet)
149  );
150  MPI_CALL(
151  MPI_Type_free( &datatype )
152  );
153 
154  if( scipDiffParamSetInfo )
155  {
156  DEF_SCIP_PARA_COMM( scipParaComm, comm );
157  scipDiffParamSet = scipParaComm->createScipDiffParamSet();
158  scipDiffParamSet->receive(commMpi, source);
159  }
160 
161  return 0;
162 
163 }
static ScipParaCommTh * comm
Definition: fscip.cpp:73
SCIP ParaComm extension for MPI communication.
ScipParaRacingRampUpParamSet extension for MPI communication.
#define PARA_COMM_CALL(paracommcall)
Definition: paraComm.h:47
#define DEF_PARA_COMM(para_comm, comm)
static const int TagRacingRampUpParamSet
Definition: paraTagDef.h:59
#define MPI_CALL(mpicall)
Definition: paraCommMpi.h:68
Base class of communicator object.
Definition: paraComm.h:101
ScipDiffParamSet extension for MPI communication.
#define DEF_SCIP_PARA_COMM(scip_para_comm, comm)