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 (C) 2002-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_concurrent.c
17  * @ingroup OTHER_CFILES
18  * @brief public methods for concurrent solving mode
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  * @author Gerald Gamrath
22  * @author Leona Gottwald
23  * @author Stefan Heinz
24  * @author Gregor Hendel
25  * @author Thorsten Koch
26  * @author Alexander Martin
27  * @author Marc Pfetsch
28  * @author Michael Winkler
29  * @author Kati Wolter
30  *
31  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include "scip/concsolver.h"
37 #include "scip/debug.h"
38 #include "scip/pub_message.h"
39 #include "scip/scip_concurrent.h"
40 #include "scip/set.h"
41 #include "scip/struct_mem.h"
42 #include "scip/struct_scip.h"
43 #include "scip/struct_set.h"
44 #include "scip/syncstore.h"
45 
46 /** creates a concurrent solver type and includes it in SCIP.
47  *
48  * @return \ref SCIP_OKAY is returned if everything worked. otherwise a suitable error code is passed. see \ref
49  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
50  *
51  * @pre This method can be called if @p scip is in one of the following stages:
52  * - \ref SCIP_STAGE_INIT
53  * - \ref SCIP_STAGE_PROBLEM
54  */
56  SCIP* scip, /**< SCIP data structure */
57  const char* name, /**< name of concurrent_solver */
58  SCIP_Real prefpriodefault, /**< the default preferred priority of this concurrent solver type */
59  SCIP_DECL_CONCSOLVERCREATEINST ((*concsolvercreateinst)), /**< data copy method of concurrent solver */
60  SCIP_DECL_CONCSOLVERDESTROYINST ((*concsolverdestroyinst)), /**< data copy method of concurrent solver */
61  SCIP_DECL_CONCSOLVERINITSEEDS ((*concsolverinitseeds)), /**< initialize random seeds of concurrent solver */
62  SCIP_DECL_CONCSOLVEREXEC ((*concsolverexec)), /**< execution method of concurrent solver */
63  SCIP_DECL_CONCSOLVERCOPYSOLVINGDATA ((*concsolvercopysolvdata)),/**< method to copy solving data */
64  SCIP_DECL_CONCSOLVERSTOP ((*concsolverstop)), /**< terminate solving in concurrent solver */
65  SCIP_DECL_CONCSOLVERSYNCWRITE ((*concsolversyncwrite)), /**< synchronization method of concurrent solver */
66  SCIP_DECL_CONCSOLVERSYNCREAD ((*concsolversyncread)), /**< synchronization method of concurrent solver */
67  SCIP_DECL_CONCSOLVERTYPEFREEDATA ((*concsolvertypefreedata)),/**< method to free data of concurrent solver type */
68  SCIP_CONCSOLVERTYPEDATA* data /**< the concurent solver type's data */
69  )
70 {
71  SCIP_CONCSOLVERTYPE* concsolvertype;
72 
73  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeConcsolverType", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
74 
75  /* check whether concurrent solver type is already present */
76  if( SCIPfindConcsolverType(scip, name) != NULL )
77  {
78  SCIPerrorMessage("concurrent solver type <%s> already included.\n", name);
79  return SCIP_INVALIDDATA;
80  }
81 
82  SCIP_CALL( SCIPconcsolverTypeCreate(&concsolvertype, scip->set, scip->messagehdlr, scip->mem->setmem,
83  name, prefpriodefault, concsolvercreateinst, concsolverdestroyinst,
84  concsolverinitseeds, concsolverexec, concsolvercopysolvdata,
85  concsolverstop, concsolversyncwrite, concsolversyncread,
86  concsolvertypefreedata, data) );
87 
88  SCIP_CALL( SCIPsetIncludeConcsolverType(scip->set, concsolvertype) );
89 
90  return SCIP_OKAY;
91 }
92 
93 /** returns the concurrent solver type with the given name, or NULL if not existing */
95  SCIP* scip, /**< SCIP data structure */
96  const char* name /**< name of concurrent_solver */
97  )
98 {
99  assert(scip != NULL);
100  assert(scip->set != NULL);
101  assert(name != NULL);
102 
103  return SCIPsetFindConcsolverType(scip->set, name);
104 }
105 
106 /** returns the array of included concurrent solver types */
108  SCIP* scip /**< SCIP data structure */
109  )
110 {
111  assert(scip != NULL);
112  assert(scip->set != NULL);
113 
114  return scip->set->concsolvertypes;
115 }
116 
117 /** returns the number of included concurrent solver types */
119  SCIP* scip /**< SCIP data structure */
120  )
121 {
122  assert(scip != NULL);
123  assert(scip->set != NULL);
124 
125  return scip->set->nconcsolvertypes;
126 }
127 
128 /** Constructs the parallel interface to execute processes concurrently.
129  *
130  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
131  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
132  *
133  * @pre This method can be called if @p scip is in one of the following stages:
134  * - \ref SCIP_STAGE_PROBLEM
135  * - \ref SCIP_STAGE_TRANSFORMING
136  * - \ref SCIP_STAGE_TRANSFORMED
137  * - \ref SCIP_STAGE_INITPRESOLVE
138  * - \ref SCIP_STAGE_PRESOLVING
139  * - \ref SCIP_STAGE_EXITPRESOLVE
140  * - \ref SCIP_STAGE_PRESOLVED
141  * - \ref SCIP_STAGE_INITSOLVE
142  * - \ref SCIP_STAGE_SOLVING
143  * - \ref SCIP_STAGE_SOLVED
144  * - \ref SCIP_STAGE_EXITSOLVE
145  * - \ref SCIP_STAGE_FREETRANS
146  *
147  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
148  */
150  SCIP* scip /**< SCIP data structure */
151  )
152 {
153  SCIP_CALL( SCIPcheckStage(scip, "SCIPconstructSyncstore", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
154 
156 
157  return SCIP_OKAY;
158 }
159 
160 /** releases the current parallel interface
161  *
162  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
163  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
164  *
165  * @pre This method can be called if @p scip is in one of the following stages:
166  * - \ref SCIP_STAGE_PROBLEM
167  * - \ref SCIP_STAGE_TRANSFORMING
168  * - \ref SCIP_STAGE_TRANSFORMED
169  * - \ref SCIP_STAGE_INITPRESOLVE
170  * - \ref SCIP_STAGE_PRESOLVING
171  * - \ref SCIP_STAGE_EXITPRESOLVE
172  * - \ref SCIP_STAGE_PRESOLVED
173  * - \ref SCIP_STAGE_INITSOLVE
174  * - \ref SCIP_STAGE_SOLVING
175  * - \ref SCIP_STAGE_SOLVED
176  * - \ref SCIP_STAGE_EXITSOLVE
177  * - \ref SCIP_STAGE_FREETRANS
178  * - \ref SCIP_STAGE_FREE
179  *
180  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
181  */
183  SCIP* scip /**< SCIP data structure */
184  )
185 {
186  SCIP_CALL( SCIPcheckStage(scip, "SCIPfreeSyncstore", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE) );
187 
189 
190  return SCIP_OKAY;
191 }
192 
193 /** Gets the parallel interface to execute processes concurrently.
194  *
195  * @return the \ref SCIP_SYNCSTORE parallel interface pointer to submit jobs for concurrent processing.
196  *
197  * @pre This method can be called if @p scip is in one of the following stages:
198  * - \ref SCIP_STAGE_INIT
199  * - \ref SCIP_STAGE_PROBLEM
200  * - \ref SCIP_STAGE_TRANSFORMING
201  * - \ref SCIP_STAGE_TRANSFORMED
202  * - \ref SCIP_STAGE_INITPRESOLVE
203  * - \ref SCIP_STAGE_PRESOLVING
204  * - \ref SCIP_STAGE_EXITPRESOLVE
205  * - \ref SCIP_STAGE_PRESOLVED
206  * - \ref SCIP_STAGE_INITSOLVE
207  * - \ref SCIP_STAGE_SOLVING
208  * - \ref SCIP_STAGE_SOLVED
209  * - \ref SCIP_STAGE_EXITSOLVE
210  * - \ref SCIP_STAGE_FREETRANS
211  *
212  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
213  */
215  SCIP* scip /**< SCIP data structure */
216  )
217 {
218  SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetSyncstore", TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
219 
220  return scip->syncstore;
221 }
int nconcsolvertypes
Definition: struct_set.h:145
struct SCIP_ConcSolverTypeData SCIP_CONCSOLVERTYPEDATA
SCIP_RETCODE SCIPsyncstoreRelease(SCIP_SYNCSTORE **syncstore)
Definition: syncstore.c:78
#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:104
#define SCIP_DECL_CONCSOLVEREXEC(x)
#define FALSE
Definition: def.h:87
#define TRUE
Definition: def.h:86
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
datastructures for concurrent solvers
SCIP_RETCODE SCIPsetIncludeConcsolverType(SCIP_SET *set, SCIP_CONCSOLVERTYPE *concsolvertype)
Definition: set.c:4508
#define SCIP_DECL_CONCSOLVERDESTROYINST(x)
SCIP_RETCODE SCIPconstructSyncstore(SCIP *scip)
#define SCIP_DECL_CONCSOLVERSTOP(x)
SCIP_MEM * mem
Definition: struct_scip.h:62
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:55
SCIP_SYNCSTORE * syncstore
Definition: struct_scip.h:100
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:2177
#define NULL
Definition: lpi_spx1.cpp:155
SCIP_CONCSOLVERTYPE ** concsolvertypes
Definition: struct_set.h:99
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:384
SCIP main data structure.
#define SCIP_DECL_CONCSOLVERINITSEEDS(x)
BMS_BLKMEM * setmem
Definition: struct_mem.h:39
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:57
SCIP_SET * set
Definition: struct_scip.h:63
public methods for message output
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:66
#define SCIP_Real
Definition: def.h:177
#define SCIP_CALL_ABORT(x)
Definition: def.h:363
#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:4530