Scippy

SCIP

Solving Constraint Integer Programs

scip_concurrent.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright 2002-2022 Zuse Institute Berlin */
7 /* */
8 /* Licensed under the Apache License, Version 2.0 (the "License"); */
9 /* you may not use this file except in compliance with the License. */
10 /* You may obtain a copy of the License at */
11 /* */
12 /* http://www.apache.org/licenses/LICENSE-2.0 */
13 /* */
14 /* Unless required by applicable law or agreed to in writing, software */
15 /* distributed under the License is distributed on an "AS IS" BASIS, */
16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17 /* See the License for the specific language governing permissions and */
18 /* limitations under the License. */
19 /* */
20 /* You should have received a copy of the Apache-2.0 license */
21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22 /* */
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 
25 /**@file scip_concurrent.c
26  * @ingroup OTHER_CFILES
27  * @brief public methods for concurrent solving mode
28  * @author Tobias Achterberg
29  * @author Timo Berthold
30  * @author Gerald Gamrath
31  * @author Leona Gottwald
32  * @author Stefan Heinz
33  * @author Gregor Hendel
34  * @author Thorsten Koch
35  * @author Alexander Martin
36  * @author Marc Pfetsch
37  * @author Michael Winkler
38  * @author Kati Wolter
39  *
40  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
41  */
42 
43 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
44 
45 #include "scip/concsolver.h"
46 #include "scip/debug.h"
47 #include "scip/pub_message.h"
48 #include "scip/scip_concurrent.h"
49 #include "scip/set.h"
50 #include "scip/struct_mem.h"
51 #include "scip/struct_scip.h"
52 #include "scip/struct_set.h"
53 #include "scip/syncstore.h"
54 
55 /** creates a concurrent solver type and includes it in SCIP.
56  *
57  * @return \ref SCIP_OKAY is returned if everything worked. otherwise a suitable error code is passed. see \ref
58  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
59  *
60  * @pre This method can be called if @p scip is in one of the following stages:
61  * - \ref SCIP_STAGE_INIT
62  * - \ref SCIP_STAGE_PROBLEM
63  */
65  SCIP* scip, /**< SCIP data structure */
66  const char* name, /**< name of concurrent_solver */
67  SCIP_Real prefpriodefault, /**< the default preferred priority of this concurrent solver type */
68  SCIP_DECL_CONCSOLVERCREATEINST ((*concsolvercreateinst)), /**< data copy method of concurrent solver */
69  SCIP_DECL_CONCSOLVERDESTROYINST ((*concsolverdestroyinst)), /**< data copy method of concurrent solver */
70  SCIP_DECL_CONCSOLVERINITSEEDS ((*concsolverinitseeds)), /**< initialize random seeds of concurrent solver */
71  SCIP_DECL_CONCSOLVEREXEC ((*concsolverexec)), /**< execution method of concurrent solver */
72  SCIP_DECL_CONCSOLVERCOPYSOLVINGDATA ((*concsolvercopysolvdata)),/**< method to copy solving data */
73  SCIP_DECL_CONCSOLVERSTOP ((*concsolverstop)), /**< terminate solving in concurrent solver */
74  SCIP_DECL_CONCSOLVERSYNCWRITE ((*concsolversyncwrite)), /**< synchronization method of concurrent solver */
75  SCIP_DECL_CONCSOLVERSYNCREAD ((*concsolversyncread)), /**< synchronization method of concurrent solver */
76  SCIP_DECL_CONCSOLVERTYPEFREEDATA ((*concsolvertypefreedata)),/**< method to free data of concurrent solver type */
77  SCIP_CONCSOLVERTYPEDATA* data /**< the concurent solver type's data */
78  )
79 {
80  SCIP_CONCSOLVERTYPE* concsolvertype;
81 
82  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeConcsolverType", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
83 
84  /* check whether concurrent solver type is already present */
85  if( SCIPfindConcsolverType(scip, name) != NULL )
86  {
87  SCIPerrorMessage("concurrent solver type <%s> already included.\n", name);
88  return SCIP_INVALIDDATA;
89  }
90 
91  SCIP_CALL( SCIPconcsolverTypeCreate(&concsolvertype, scip->set, scip->messagehdlr, scip->mem->setmem,
92  name, prefpriodefault, concsolvercreateinst, concsolverdestroyinst,
93  concsolverinitseeds, concsolverexec, concsolvercopysolvdata,
94  concsolverstop, concsolversyncwrite, concsolversyncread,
95  concsolvertypefreedata, data) );
96 
97  SCIP_CALL( SCIPsetIncludeConcsolverType(scip->set, concsolvertype) );
98 
99  return SCIP_OKAY;
100 }
101 
102 /** returns the concurrent solver type with the given name, or NULL if not existing */
104  SCIP* scip, /**< SCIP data structure */
105  const char* name /**< name of concurrent_solver */
106  )
107 {
108  assert(scip != NULL);
109  assert(scip->set != NULL);
110  assert(name != NULL);
111 
112  return SCIPsetFindConcsolverType(scip->set, name);
113 }
114 
115 /** returns the array of included concurrent solver types */
117  SCIP* scip /**< SCIP data structure */
118  )
119 {
120  assert(scip != NULL);
121  assert(scip->set != NULL);
122 
123  return scip->set->concsolvertypes;
124 }
125 
126 /** returns the number of included concurrent solver types */
128  SCIP* scip /**< SCIP data structure */
129  )
130 {
131  assert(scip != NULL);
132  assert(scip->set != NULL);
133 
134  return scip->set->nconcsolvertypes;
135 }
136 
137 /** Constructs the parallel interface to execute processes concurrently.
138  *
139  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
140  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
141  *
142  * @pre This method can be called if @p scip is in one of the following stages:
143  * - \ref SCIP_STAGE_PROBLEM
144  * - \ref SCIP_STAGE_TRANSFORMING
145  * - \ref SCIP_STAGE_TRANSFORMED
146  * - \ref SCIP_STAGE_INITPRESOLVE
147  * - \ref SCIP_STAGE_PRESOLVING
148  * - \ref SCIP_STAGE_EXITPRESOLVE
149  * - \ref SCIP_STAGE_PRESOLVED
150  * - \ref SCIP_STAGE_INITSOLVE
151  * - \ref SCIP_STAGE_SOLVING
152  * - \ref SCIP_STAGE_SOLVED
153  * - \ref SCIP_STAGE_EXITSOLVE
154  * - \ref SCIP_STAGE_FREETRANS
155  *
156  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
157  */
159  SCIP* scip /**< SCIP data structure */
160  )
161 {
162  SCIP_CALL( SCIPcheckStage(scip, "SCIPconstructSyncstore", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
163 
165 
166  return SCIP_OKAY;
167 }
168 
169 /** releases the current parallel interface
170  *
171  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
172  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
173  *
174  * @pre This method can be called if @p scip is in one of the following stages:
175  * - \ref SCIP_STAGE_PROBLEM
176  * - \ref SCIP_STAGE_TRANSFORMING
177  * - \ref SCIP_STAGE_TRANSFORMED
178  * - \ref SCIP_STAGE_INITPRESOLVE
179  * - \ref SCIP_STAGE_PRESOLVING
180  * - \ref SCIP_STAGE_EXITPRESOLVE
181  * - \ref SCIP_STAGE_PRESOLVED
182  * - \ref SCIP_STAGE_INITSOLVE
183  * - \ref SCIP_STAGE_SOLVING
184  * - \ref SCIP_STAGE_SOLVED
185  * - \ref SCIP_STAGE_EXITSOLVE
186  * - \ref SCIP_STAGE_FREETRANS
187  * - \ref SCIP_STAGE_FREE
188  *
189  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
190  */
192  SCIP* scip /**< SCIP data structure */
193  )
194 {
195  SCIP_CALL( SCIPcheckStage(scip, "SCIPfreeSyncstore", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE) );
196 
198 
199  return SCIP_OKAY;
200 }
201 
202 /** Gets the parallel interface to execute processes concurrently.
203  *
204  * @return the \ref SCIP_SYNCSTORE parallel interface pointer to submit jobs for concurrent processing.
205  *
206  * @pre This method can be called if @p scip is in one of the following stages:
207  * - \ref SCIP_STAGE_INIT
208  * - \ref SCIP_STAGE_PROBLEM
209  * - \ref SCIP_STAGE_TRANSFORMING
210  * - \ref SCIP_STAGE_TRANSFORMED
211  * - \ref SCIP_STAGE_INITPRESOLVE
212  * - \ref SCIP_STAGE_PRESOLVING
213  * - \ref SCIP_STAGE_EXITPRESOLVE
214  * - \ref SCIP_STAGE_PRESOLVED
215  * - \ref SCIP_STAGE_INITSOLVE
216  * - \ref SCIP_STAGE_SOLVING
217  * - \ref SCIP_STAGE_SOLVED
218  * - \ref SCIP_STAGE_EXITSOLVE
219  * - \ref SCIP_STAGE_FREETRANS
220  *
221  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
222  */
224  SCIP* scip /**< SCIP data structure */
225  )
226 {
227  SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetSyncstore", TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
228 
229  return scip->syncstore;
230 }
int nconcsolvertypes
Definition: struct_set.h:154
struct SCIP_ConcSolverTypeData SCIP_CONCSOLVERTYPEDATA
SCIP_RETCODE SCIPsyncstoreRelease(SCIP_SYNCSTORE **syncstore)
Definition: syncstore.c:87
#define SCIP_DECL_CONCSOLVERSYNCREAD(x)
SCIP_RETCODE SCIPconcsolverTypeCreate(SCIP_CONCSOLVERTYPE **concsolvertype, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, SCIP_Real prefpriodefault, SCIP_DECL_CONCSOLVERCREATEINST((*concsolvercreateinst)), SCIP_DECL_CONCSOLVERDESTROYINST((*concsolverdestroyinst)), SCIP_DECL_CONCSOLVERINITSEEDS((*concsolverinitseeds)), SCIP_DECL_CONCSOLVEREXEC((*concsolverexec)), SCIP_DECL_CONCSOLVERCOPYSOLVINGDATA((*concsolvercopysolvdata)), SCIP_DECL_CONCSOLVERSTOP((*concsolverstop)), SCIP_DECL_CONCSOLVERSYNCWRITE((*concsolversyncwrite)), SCIP_DECL_CONCSOLVERSYNCREAD((*concsolversyncread)), SCIP_DECL_CONCSOLVERTYPEFREEDATA((*concsolvertypefreedata)), SCIP_CONCSOLVERTYPEDATA *data)
Definition: concsolver.c:113
#define SCIP_DECL_CONCSOLVEREXEC(x)
#define FALSE
Definition: def.h:96
#define TRUE
Definition: def.h:95
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
datastructures for concurrent solvers
SCIP_RETCODE SCIPsetIncludeConcsolverType(SCIP_SET *set, SCIP_CONCSOLVERTYPE *concsolvertype)
Definition: set.c:4523
#define SCIP_DECL_CONCSOLVERDESTROYINST(x)
SCIP_RETCODE SCIPconstructSyncstore(SCIP *scip)
#define SCIP_DECL_CONCSOLVERSTOP(x)
SCIP_MEM * mem
Definition: struct_scip.h:71
SCIP_RETCODE SCIPincludeConcsolverType(SCIP *scip, const char *name, SCIP_Real prefpriodefault, SCIP_DECL_CONCSOLVERCREATEINST((*concsolvercreateinst)), SCIP_DECL_CONCSOLVERDESTROYINST((*concsolverdestroyinst)), SCIP_DECL_CONCSOLVERINITSEEDS((*concsolverinitseeds)), SCIP_DECL_CONCSOLVEREXEC((*concsolverexec)), SCIP_DECL_CONCSOLVERCOPYSOLVINGDATA((*concsolvercopysolvdata)), SCIP_DECL_CONCSOLVERSTOP((*concsolverstop)), SCIP_DECL_CONCSOLVERSYNCWRITE((*concsolversyncwrite)), SCIP_DECL_CONCSOLVERSYNCREAD((*concsolversyncread)), SCIP_DECL_CONCSOLVERTYPEFREEDATA((*concsolvertypefreedata)), SCIP_CONCSOLVERTYPEDATA *data)
#define SCIPerrorMessage
Definition: pub_message.h:64
SCIP_SYNCSTORE * syncstore
Definition: struct_scip.h:109
SCIP_RETCODE SCIPcheckStage(SCIP *scip, const char *method, SCIP_Bool init, SCIP_Bool problem, SCIP_Bool transforming, SCIP_Bool transformed, SCIP_Bool initpresolve, SCIP_Bool presolving, SCIP_Bool exitpresolve, SCIP_Bool presolved, SCIP_Bool initsolve, SCIP_Bool solving, SCIP_Bool solved, SCIP_Bool exitsolve, SCIP_Bool freetrans, SCIP_Bool freescip)
Definition: debug.c:2186
#define NULL
Definition: lpi_spx1.cpp:164
SCIP_CONCSOLVERTYPE ** concsolvertypes
Definition: struct_set.h:108
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:393
SCIP main data structure.
#define SCIP_DECL_CONCSOLVERINITSEEDS(x)
BMS_BLKMEM * setmem
Definition: struct_mem.h:48
the function declarations for the synchronization store
SCIP_RETCODE SCIPfreeSyncstore(SCIP *scip)
SCIP_SYNCSTORE * SCIPgetSyncstore(SCIP *scip)
public methods for concurrent solving mode
methods for debugging
datastructures for block memory pools and memory buffers
#define SCIP_DECL_CONCSOLVERCOPYSOLVINGDATA(x)
#define SCIP_DECL_CONCSOLVERTYPEFREEDATA(x)
int SCIPgetNConcsolverTypes(SCIP *scip)
SCIP_CONCSOLVERTYPE ** SCIPgetConcsolverTypes(SCIP *scip)
SCIP_RETCODE SCIPsyncstoreCreate(SCIP_SYNCSTORE **syncstore)
Definition: syncstore.c:66
SCIP_SET * set
Definition: struct_scip.h:72
public methods for message output
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:75
#define SCIP_Real
Definition: def.h:186
#define SCIP_CALL_ABORT(x)
Definition: def.h:372
#define SCIP_DECL_CONCSOLVERSYNCWRITE(x)
#define SCIP_DECL_CONCSOLVERCREATEINST(x)
datastructures for global SCIP settings
SCIP_CONCSOLVERTYPE * SCIPfindConcsolverType(SCIP *scip, const char *name)
SCIP_CONCSOLVERTYPE * SCIPsetFindConcsolverType(SCIP_SET *set, const char *name)
Definition: set.c:4545