-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide ability to call SolveInParallel with program generators. #22226
Comments
+1 to implementing this feature -- thanks for starting to work on it! |
I think a concrete example in the code would be helpful. Let's take What the implementation in #22225 achieves is the ability to generate the programs via a lambda and run the par-for loop using the new method. However, what it fails to achieve is the efficient reuse of the Would love some feedback on how we could achieve this in practice. |
I think I have narrowed down the proposal to the following signature:
The reasoning is that some people may need to generate a unique program for the ith program, so they need their generator to be able to return |
I like that this allows us to modify the programs in the generator, instead of creating it each time. The other thing that |
I see two options for exiting early.
I prefer option 1. |
I like option 1 as well, but |
I don't see any issue with |
cc @jwnimmer-tri if you have thoughts before I get too far into an implementation. |
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.) 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
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
The text was updated successfully, but these errors were encountered: