1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2021 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 */
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)55 SCIP_RETCODE SCIPincludeConcsolverType(
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 */
SCIPfindConcsolverType(SCIP * scip,const char * name)94 SCIP_CONCSOLVERTYPE* SCIPfindConcsolverType(
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 */
SCIPgetConcsolverTypes(SCIP * scip)107 SCIP_CONCSOLVERTYPE** SCIPgetConcsolverTypes(
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 */
SCIPgetNConcsolverTypes(SCIP * scip)118 int SCIPgetNConcsolverTypes(
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 */
SCIPconstructSyncstore(SCIP * scip)149 SCIP_RETCODE SCIPconstructSyncstore(
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
155 SCIP_CALL( SCIPsyncstoreCreate(&scip->syncstore) );
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 */
SCIPfreeSyncstore(SCIP * scip)182 SCIP_RETCODE SCIPfreeSyncstore(
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
188 SCIP_CALL( SCIPsyncstoreRelease(&(scip->syncstore)) );
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 */
SCIPgetSyncstore(SCIP * scip)214 SCIP_SYNCSTORE* SCIPgetSyncstore(
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 }
222