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