Skip to content

Commit 9f144a2

Browse files
committed
Merge branch 'add-tpi-identification-functions' into 'v9-minor'
add API functions to check whether a TPI is available and get library name and description See merge request integer/scip!3463
2 parents 12ed15c + 7ad21be commit 9f144a2

File tree

8 files changed

+134
-15
lines changed

8 files changed

+134
-15
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Interface changes
1919
-----------------
2020
### New callbacks
2121
### New API functions
22+
23+
- added SCIPtpiIsAvailable() to check whether a working task processing interface is available (TPI != none)
24+
- added SCIPtpiGetLibraryName() and SCIPtpiGetLibraryDesc()
25+
2226
### Command line interface
2327
### Interfaces to external software
2428
### New parameters

src/scip/scip_general.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "scip/struct_stat.h"
7474
#include "scip/syncstore.h"
7575
#include "scip/lapack_calls.h"
76+
#include "tpi/tpi.h"
7677

7778
#include <string.h>
7879
#if defined(_WIN32) || defined(_WIN64)
@@ -288,6 +289,15 @@ SCIP_RETCODE doScipCreate(
288289
}
289290
#endif
290291

292+
if( SCIPtpiIsAvailable() )
293+
{
294+
char name[20];
295+
char desc[80];
296+
SCIPtpiGetLibraryName(name, (int)sizeof(name));
297+
SCIPtpiGetLibraryDesc(desc, (int)sizeof(desc));
298+
SCIP_CALL( SCIPsetIncludeExternalCode((*scip)->set, name, desc) );
299+
}
300+
291301
return SCIP_OKAY;
292302
}
293303

src/scip/scip_solve.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
#include "scip/tree.h"
113113
#include "scip/var.h"
114114
#include "scip/visual.h"
115+
#include "tpi/tpi.h"
115116

116117
/** calculates number of nonzeros in problem */
117118
static
@@ -2861,10 +2862,6 @@ SCIP_RETCODE SCIPsolveConcurrent(
28612862
SCIP* scip /**< SCIP data structure */
28622863
)
28632864
{
2864-
#ifdef TPI_NONE
2865-
SCIPerrorMessage("SCIP was compiled without task processing interface. Concurrent solve not possible\n");
2866-
return SCIP_PLUGINNOTFOUND;
2867-
#else
28682865
SCIP_RETCODE retcode;
28692866
int i;
28702867
SCIP_RANDNUMGEN* rndgen;
@@ -2873,7 +2870,13 @@ SCIP_RETCODE SCIPsolveConcurrent(
28732870

28742871
SCIP_CALL( SCIPcheckStage(scip, "SCIPsolveConcurrent", FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE) );
28752872

2876-
SCIP_CALL( SCIPsetIntParam(scip, "timing/clocktype", SCIP_CLOCKTYPE_WALL) );
2873+
if( !SCIPtpiIsAvailable() )
2874+
{
2875+
SCIPerrorMessage("SCIP was compiled without task processing interface. Concurrent solve not possible\n");
2876+
return SCIP_PLUGINNOTFOUND;
2877+
}
2878+
2879+
SCIP_CALL( SCIPsetIntParam(scip, "timing/clocktype", (int)SCIP_CLOCKTYPE_WALL) );
28772880

28782881
minnthreads = scip->set->parallel_minnthreads;
28792882
maxnthreads = scip->set->parallel_maxnthreads;
@@ -2887,7 +2890,7 @@ SCIP_RETCODE SCIPsolveConcurrent(
28872890
{
28882891
int nconcsolvertypes;
28892892
SCIP_CONCSOLVERTYPE** concsolvertypes;
2890-
SCIP_Longint nthreads;
2893+
int nthreads;
28912894
SCIP_Real memorylimit;
28922895
int* solvertypes;
28932896
SCIP_Longint* weights;
@@ -2933,8 +2936,8 @@ SCIP_RETCODE SCIPsolveConcurrent(
29332936
/* estimate maximum number of copies that be created based on memory limit */
29342937
if( !scip->set->misc_avoidmemout )
29352938
{
2936-
nthreads = MAX(1, memorylimit / (4.0*SCIPgetMemExternEstim(scip)/1048576.0));
2937-
SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "estimated a maximum of %lli threads based on memory limit\n", nthreads);
2939+
nthreads = MAX(1, memorylimit / (4.0*SCIPgetMemExternEstim(scip)/1048576.0)); /*lint !e666 !e524*/
2940+
SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "estimated a maximum of %d threads based on memory limit\n", nthreads);
29382941
}
29392942
else
29402943
{
@@ -2962,14 +2965,15 @@ SCIP_RETCODE SCIPsolveConcurrent(
29622965
return SCIPsolve(scip);
29632966
}
29642967
nthreads = MIN(nthreads, maxnthreads);
2965-
SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "using %lli threads for concurrent solve\n", nthreads);
2968+
SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "using %d threads for concurrent solve\n", nthreads);
29662969

29672970
/* now set up nthreads many concurrent solvers that will be used for the concurrent solve
29682971
* using the preferred priorities of each concurrent solver
29692972
*/
29702973
prefpriosum = 0.0;
29712974
for( i = 0; i < nconcsolvertypes; ++i )
29722975
prefpriosum += SCIPconcsolverTypeGetPrefPrio(concsolvertypes[i]);
2976+
assert(prefpriosum != 0.0);
29732977

29742978
ncandsolvertypes = 0;
29752979
SCIP_CALL( SCIPallocBufferArray(scip, &solvertypes, nthreads + nconcsolvertypes) );
@@ -3005,7 +3009,7 @@ SCIP_RETCODE SCIPsolveConcurrent(
30053009

30063010
SCIP_CALL( SCIPconcsolverCreateInstance(scip->set, concsolvertypes[solvertypes[i]], &concsolver) );
30073011
if( scip->set->concurrent_changeseeds && SCIPgetNConcurrentSolvers(scip) > 1 )
3008-
SCIP_CALL( SCIPconcsolverInitSeeds(concsolver, SCIPrandomGetInt(rndgen, 0, INT_MAX)) );
3012+
SCIP_CALL( SCIPconcsolverInitSeeds(concsolver, (unsigned int)SCIPrandomGetInt(rndgen, 0, INT_MAX)) );
30093013
}
30103014
SCIPfreeRandom(scip, &rndgen);
30113015
SCIPfreeBufferArray(scip, &prios);
@@ -3029,7 +3033,6 @@ SCIP_RETCODE SCIPsolveConcurrent(
30293033
SCIP_CALL( displayRelevantStats(scip) );
30303034

30313035
return retcode;
3032-
#endif
30333036
}
30343037

30353038
/** include specific heuristics and branching rules for reoptimization

src/scip/scipdefplugins.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,6 @@ SCIP_RETCODE SCIPincludeDefaultPlugins(
272272
SCIP_CALL( SCIPincludeNlpSolverWorhp(scip, FALSE) );
273273
SCIP_CALL( SCIPincludeNlpSolverAll(scip) );
274274

275-
#ifdef TPI_TNY
276-
SCIP_CALL( SCIPincludeExternalCodeInformation(scip, "TinyCThread", "Small, portable implementation of the C11 threads API (tinycthread.github.io)") );
277-
#endif
278-
279275
SCIP_CALL( SCIPdebugIncludeProp(scip) ); /*lint !e506 !e774*/
280276

281277
return SCIP_OKAY;

src/tpi/tpi.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,22 @@ SCIP_RETCODE SCIPtpiExit(
153153
void
154154
);
155155

156+
/** indicate whether a working TPI is available */
157+
SCIP_EXPORT
158+
SCIP_Bool SCIPtpiIsAvailable(void);
159+
160+
/** get name of library that the TPI interfaces to */
161+
SCIP_EXPORT
162+
void SCIPtpiGetLibraryName(
163+
char* name, /**< buffer to store name */
164+
int namesize /**< length of name buffer */
165+
);
166+
167+
/** get description of library that the TPI interfaces to */
168+
SCIP_EXPORT
169+
void SCIPtpiGetLibraryDesc(
170+
char* desc, /**< buffer to store description */
171+
int descsize /**< length of description */
172+
);
173+
156174
#endif

src/tpi/tpi_none.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
3434

3535
#include "tpi/tpi.h"
36+
#include "scip/pub_misc.h"
3637

3738
/* do not define struct SCIP_Lock and struct SCIP_Condition, since they are not used */
3839

@@ -219,3 +220,32 @@ SCIP_RETCODE SCIPtpiExit(
219220
{
220221
return SCIP_ERROR;
221222
}
223+
224+
/** indicate whether a working TPI is available */
225+
SCIP_Bool SCIPtpiIsAvailable(void)
226+
{
227+
return FALSE;
228+
}
229+
230+
/** get name of library that the TPI interfaces to */
231+
void SCIPtpiGetLibraryName(
232+
char* name, /**< buffer to store name */
233+
int namesize /**< length of name buffer */
234+
)
235+
{
236+
assert(name != NULL);
237+
238+
(void) SCIPsnprintf(name, namesize, "none");
239+
}
240+
241+
/** get description of library that the TPI interfaces to */
242+
void SCIPtpiGetLibraryDesc(
243+
char* desc, /**< buffer to store description */
244+
int descsize /**< length of description */
245+
)
246+
{
247+
assert(desc != NULL);
248+
assert(descsize >= 1);
249+
250+
*desc = '\0';
251+
}

src/tpi/tpi_openmp.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "tpi/tpi.h"
3636
#include "blockmemshell/memory.h"
3737
#include "scip/pub_message.h"
38+
#include "scip/pub_misc.h"
3839
#include <omp.h>
3940

4041
/* macros for direct access */
@@ -702,3 +703,31 @@ void SCIPtpiDestroyCondition(
702703

703704
BMSfreeMemory(condition);
704705
}
706+
707+
/** indicate whether a working TPI is available */
708+
SCIP_Bool SCIPtpiIsAvailable(void)
709+
{
710+
return TRUE;
711+
}
712+
713+
/** get name of library that the TPI interfaces to */
714+
void SCIPtpiGetLibraryName(
715+
char* name, /**< buffer to store name */
716+
int namesize /**< length of name buffer */
717+
)
718+
{
719+
assert(name != NULL);
720+
721+
(void) SCIPsnprintf(name, namesize, "OpenMP %d", _OPENMP); /*lint !e40*/
722+
}
723+
724+
/** get description of library that the TPI interfaces to */
725+
void SCIPtpiGetLibraryDesc(
726+
char* desc, /**< buffer to store description */
727+
int descsize /**< length of description */
728+
)
729+
{
730+
assert(desc != NULL);
731+
732+
(void) SCIPsnprintf(desc, descsize, "shared-memory multiprocessing library (openmp.org)");
733+
}

src/tpi/tpi_tnycthrd.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "blockmemshell/memory.h"
3737
#include "tinycthread/tinycthread.h"
3838
#include "scip/pub_message.h"
39+
#include "scip/pub_misc.h"
3940

4041
/* macros for direct access */
4142

@@ -840,3 +841,31 @@ int SCIPtpiGetThreadNum(
840841
{
841842
return _threadnumber;
842843
}
844+
845+
/** indicate whether a working TPI is available */
846+
SCIP_Bool SCIPtpiIsAvailable(void)
847+
{
848+
return TRUE;
849+
}
850+
851+
/** get name of library that the TPI interfaces to */
852+
void SCIPtpiGetLibraryName(
853+
char* name, /**< buffer to store name */
854+
int namesize /**< length of name buffer */
855+
)
856+
{
857+
assert(name != NULL);
858+
859+
(void) SCIPsnprintf(name, namesize, "TinyCThread %d.%d", TINYCTHREAD_VERSION_MAJOR, TINYCTHREAD_VERSION_MINOR);
860+
}
861+
862+
/** get description of library that the TPI interfaces to */
863+
void SCIPtpiGetLibraryDesc(
864+
char* desc, /**< buffer to store description */
865+
int descsize /**< length of description */
866+
)
867+
{
868+
assert(desc != NULL);
869+
870+
(void) SCIPsnprintf(desc, descsize, "small portable implementation of the C11 threads API (tinycthread.github.io)");
871+
}

0 commit comments

Comments
 (0)