Since the introduction of SolveInParallel in #21957 , there have been several PRs which try to match this pattern (e.g. #21705, #21351, #22222). In these cases, it is memory intensive to generate all the programs at once in memory, however it is easy to say decide what the ith program is. When solving MathematicalProgram in parallel there are a couple of subtleties that are easy to forget/miss when implementing.
1.) Setting CommonSolverOptions.kMaxThread = 1
2.) Skipping over programs which are not thread safe and solving these in a second pass in serial.
3.) Managing the number of solvers which are created by the threads.
Managing these complexities was a major motivator for implementing SolveInParallel and why it is generally a bad idea to implement the parallel for loop manually each time.
To avoid this potential for implementation errors, I propose adding a new overload
Since the introduction of
SolveInParallel
in #21957 , there have been several PRs which try to match this pattern (e.g. #21705, #21351, #22222). In these cases, it is memory intensive to generate all the programs at once in memory, however it is easy to say decide what thei
th program is. When solvingMathematicalProgram
in parallel there are a couple of subtleties that are easy to forget/miss when implementing. 1.) SettingCommonSolverOptions.kMaxThread = 1
2.) Skipping over programs which are not thread safe and solving these in a second pass in serial. 3.) Managing the number of solvers which are created by the threads.Managing these complexities was a major motivator for implementing
SolveInParallel
and why it is generally a bad idea to implement the parallel for loop manually each time.To avoid this potential for implementation errors, I propose adding a new overload
which all parallel for loops of
MathematicalProgram
should route through.I am willing to make this function internal, but I think it could be beneficial to have this in the public API.
See draft PR #22225