Skip to content

Commit

Permalink
Merge branch 'add-tpi-identification-functions' into 'v9-minor'
Browse files Browse the repository at this point in the history
add API functions to check whether a TPI is available and get library name and description

See merge request integer/scip!3463
  • Loading branch information
svigerske committed Jul 19, 2024
2 parents 12ed15c + 7ad21be commit 9f144a2
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Interface changes
-----------------
### New callbacks
### New API functions

- added SCIPtpiIsAvailable() to check whether a working task processing interface is available (TPI != none)
- added SCIPtpiGetLibraryName() and SCIPtpiGetLibraryDesc()

### Command line interface
### Interfaces to external software
### New parameters
Expand Down
10 changes: 10 additions & 0 deletions src/scip/scip_general.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "scip/struct_stat.h"
#include "scip/syncstore.h"
#include "scip/lapack_calls.h"
#include "tpi/tpi.h"

#include <string.h>
#if defined(_WIN32) || defined(_WIN64)
Expand Down Expand Up @@ -288,6 +289,15 @@ SCIP_RETCODE doScipCreate(
}
#endif

if( SCIPtpiIsAvailable() )
{
char name[20];
char desc[80];
SCIPtpiGetLibraryName(name, (int)sizeof(name));
SCIPtpiGetLibraryDesc(desc, (int)sizeof(desc));
SCIP_CALL( SCIPsetIncludeExternalCode((*scip)->set, name, desc) );
}

return SCIP_OKAY;
}

Expand Down
25 changes: 14 additions & 11 deletions src/scip/scip_solve.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
#include "scip/tree.h"
#include "scip/var.h"
#include "scip/visual.h"
#include "tpi/tpi.h"

/** calculates number of nonzeros in problem */
static
Expand Down Expand Up @@ -2861,10 +2862,6 @@ SCIP_RETCODE SCIPsolveConcurrent(
SCIP* scip /**< SCIP data structure */
)
{
#ifdef TPI_NONE
SCIPerrorMessage("SCIP was compiled without task processing interface. Concurrent solve not possible\n");
return SCIP_PLUGINNOTFOUND;
#else
SCIP_RETCODE retcode;
int i;
SCIP_RANDNUMGEN* rndgen;
Expand All @@ -2873,7 +2870,13 @@ SCIP_RETCODE SCIPsolveConcurrent(

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

SCIP_CALL( SCIPsetIntParam(scip, "timing/clocktype", SCIP_CLOCKTYPE_WALL) );
if( !SCIPtpiIsAvailable() )
{
SCIPerrorMessage("SCIP was compiled without task processing interface. Concurrent solve not possible\n");
return SCIP_PLUGINNOTFOUND;
}

SCIP_CALL( SCIPsetIntParam(scip, "timing/clocktype", (int)SCIP_CLOCKTYPE_WALL) );

minnthreads = scip->set->parallel_minnthreads;
maxnthreads = scip->set->parallel_maxnthreads;
Expand All @@ -2887,7 +2890,7 @@ SCIP_RETCODE SCIPsolveConcurrent(
{
int nconcsolvertypes;
SCIP_CONCSOLVERTYPE** concsolvertypes;
SCIP_Longint nthreads;
int nthreads;
SCIP_Real memorylimit;
int* solvertypes;
SCIP_Longint* weights;
Expand Down Expand Up @@ -2933,8 +2936,8 @@ SCIP_RETCODE SCIPsolveConcurrent(
/* estimate maximum number of copies that be created based on memory limit */
if( !scip->set->misc_avoidmemout )
{
nthreads = MAX(1, memorylimit / (4.0*SCIPgetMemExternEstim(scip)/1048576.0));
SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "estimated a maximum of %lli threads based on memory limit\n", nthreads);
nthreads = MAX(1, memorylimit / (4.0*SCIPgetMemExternEstim(scip)/1048576.0)); /*lint !e666 !e524*/
SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "estimated a maximum of %d threads based on memory limit\n", nthreads);
}
else
{
Expand Down Expand Up @@ -2962,14 +2965,15 @@ SCIP_RETCODE SCIPsolveConcurrent(
return SCIPsolve(scip);
}
nthreads = MIN(nthreads, maxnthreads);
SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "using %lli threads for concurrent solve\n", nthreads);
SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "using %d threads for concurrent solve\n", nthreads);

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

ncandsolvertypes = 0;
SCIP_CALL( SCIPallocBufferArray(scip, &solvertypes, nthreads + nconcsolvertypes) );
Expand Down Expand Up @@ -3005,7 +3009,7 @@ SCIP_RETCODE SCIPsolveConcurrent(

SCIP_CALL( SCIPconcsolverCreateInstance(scip->set, concsolvertypes[solvertypes[i]], &concsolver) );
if( scip->set->concurrent_changeseeds && SCIPgetNConcurrentSolvers(scip) > 1 )
SCIP_CALL( SCIPconcsolverInitSeeds(concsolver, SCIPrandomGetInt(rndgen, 0, INT_MAX)) );
SCIP_CALL( SCIPconcsolverInitSeeds(concsolver, (unsigned int)SCIPrandomGetInt(rndgen, 0, INT_MAX)) );
}
SCIPfreeRandom(scip, &rndgen);
SCIPfreeBufferArray(scip, &prios);
Expand All @@ -3029,7 +3033,6 @@ SCIP_RETCODE SCIPsolveConcurrent(
SCIP_CALL( displayRelevantStats(scip) );

return retcode;
#endif
}

/** include specific heuristics and branching rules for reoptimization
Expand Down
4 changes: 0 additions & 4 deletions src/scip/scipdefplugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,6 @@ SCIP_RETCODE SCIPincludeDefaultPlugins(
SCIP_CALL( SCIPincludeNlpSolverWorhp(scip, FALSE) );
SCIP_CALL( SCIPincludeNlpSolverAll(scip) );

#ifdef TPI_TNY
SCIP_CALL( SCIPincludeExternalCodeInformation(scip, "TinyCThread", "Small, portable implementation of the C11 threads API (tinycthread.github.io)") );
#endif

SCIP_CALL( SCIPdebugIncludeProp(scip) ); /*lint !e506 !e774*/

return SCIP_OKAY;
Expand Down
18 changes: 18 additions & 0 deletions src/tpi/tpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,22 @@ SCIP_RETCODE SCIPtpiExit(
void
);

/** indicate whether a working TPI is available */
SCIP_EXPORT
SCIP_Bool SCIPtpiIsAvailable(void);

/** get name of library that the TPI interfaces to */
SCIP_EXPORT
void SCIPtpiGetLibraryName(
char* name, /**< buffer to store name */
int namesize /**< length of name buffer */
);

/** get description of library that the TPI interfaces to */
SCIP_EXPORT
void SCIPtpiGetLibraryDesc(
char* desc, /**< buffer to store description */
int descsize /**< length of description */
);

#endif
30 changes: 30 additions & 0 deletions src/tpi/tpi_none.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/

#include "tpi/tpi.h"
#include "scip/pub_misc.h"

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

Expand Down Expand Up @@ -219,3 +220,32 @@ SCIP_RETCODE SCIPtpiExit(
{
return SCIP_ERROR;
}

/** indicate whether a working TPI is available */
SCIP_Bool SCIPtpiIsAvailable(void)
{
return FALSE;
}

/** get name of library that the TPI interfaces to */
void SCIPtpiGetLibraryName(
char* name, /**< buffer to store name */
int namesize /**< length of name buffer */
)
{
assert(name != NULL);

(void) SCIPsnprintf(name, namesize, "none");
}

/** get description of library that the TPI interfaces to */
void SCIPtpiGetLibraryDesc(
char* desc, /**< buffer to store description */
int descsize /**< length of description */
)
{
assert(desc != NULL);
assert(descsize >= 1);

*desc = '\0';
}
29 changes: 29 additions & 0 deletions src/tpi/tpi_openmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "tpi/tpi.h"
#include "blockmemshell/memory.h"
#include "scip/pub_message.h"
#include "scip/pub_misc.h"
#include <omp.h>

/* macros for direct access */
Expand Down Expand Up @@ -702,3 +703,31 @@ void SCIPtpiDestroyCondition(

BMSfreeMemory(condition);
}

/** indicate whether a working TPI is available */
SCIP_Bool SCIPtpiIsAvailable(void)
{
return TRUE;
}

/** get name of library that the TPI interfaces to */
void SCIPtpiGetLibraryName(
char* name, /**< buffer to store name */
int namesize /**< length of name buffer */
)
{
assert(name != NULL);

(void) SCIPsnprintf(name, namesize, "OpenMP %d", _OPENMP); /*lint !e40*/
}

/** get description of library that the TPI interfaces to */
void SCIPtpiGetLibraryDesc(
char* desc, /**< buffer to store description */
int descsize /**< length of description */
)
{
assert(desc != NULL);

(void) SCIPsnprintf(desc, descsize, "shared-memory multiprocessing library (openmp.org)");
}
29 changes: 29 additions & 0 deletions src/tpi/tpi_tnycthrd.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "blockmemshell/memory.h"
#include "tinycthread/tinycthread.h"
#include "scip/pub_message.h"
#include "scip/pub_misc.h"

/* macros for direct access */

Expand Down Expand Up @@ -840,3 +841,31 @@ int SCIPtpiGetThreadNum(
{
return _threadnumber;
}

/** indicate whether a working TPI is available */
SCIP_Bool SCIPtpiIsAvailable(void)
{
return TRUE;
}

/** get name of library that the TPI interfaces to */
void SCIPtpiGetLibraryName(
char* name, /**< buffer to store name */
int namesize /**< length of name buffer */
)
{
assert(name != NULL);

(void) SCIPsnprintf(name, namesize, "TinyCThread %d.%d", TINYCTHREAD_VERSION_MAJOR, TINYCTHREAD_VERSION_MINOR);
}

/** get description of library that the TPI interfaces to */
void SCIPtpiGetLibraryDesc(
char* desc, /**< buffer to store description */
int descsize /**< length of description */
)
{
assert(desc != NULL);

(void) SCIPsnprintf(desc, descsize, "small portable implementation of the C11 threads API (tinycthread.github.io)");
}

0 comments on commit 9f144a2

Please sign in to comment.