global optimization in parallel in combination with external pde solver

I use MultiStart from the global optimization toolbox to run lsqnonlin solver for a bunch of start
vectors. I want to run the local run indices in parallel since one forward solve is quite expensive.
function [fval, Jacob] = myObj(x)
% write params to file
...
% invoke pde solver with system call
system(path_to_pde_solver);
% read fval and Jacob from files
...
end
As you can see, the objective function writes the current point in parameter space to a file,
invokes the pde solver (Abaqus,...) which reads the parameter file and writes fval and Jacob in a
file. Finally, the objective function reads fval and Jacob from files which were generated by the
pde solver.
This, of course, does not work if multiple run indices operate on the same files since things get
mixed up.
However, it is safe if there are as many file exchange directories as there are run indices running
in parallel. For instance, say I call MultiStart in parallel with six cores on my local machine. Then,
six directories are created and the indices running successively on core 1 ,write their data always in directory 1,
and the indices running on core 2 write their data always in directory_2,...
I have full control on the pde solver, so I can pass whatever arguments to the pde solver in the
system call.
Does that sound reasonable and can this be realized with MultiStart and parallel computing toolbox?
Any starting points or alternatives are greatly appreciated!
Best regards

13 comentarios

People who work with numerics always say: The proof of the pudding is in the eating.
Yes. But I do not know how the run indices are distributed on the local machine if I create a parpool object. What I need is something like a " 0 <= worker id < numWorkers", which I can pass to the objective function to write in a directory "baseDirectory_<worker id>". Any ideas?
Torsten
Torsten el 18 de Nov. de 2023
Editada: Torsten el 18 de Nov. de 2023
I have no experience with parallel computations, but wouldn't it be possible in this case to program "Multistart" on your own by calling "lsqnonlin" in a loop for different initial guesses for the parameters, run this loop in parallel and use the loop index "i" as the worker id (which could then be passed to your objective function) ? I'm not sure, though, whether calls in the loop that depend on the loop index are possible in a parallelized loop.
Yes, I think multistart does nothing else under the hood (unfortunately, there is no insight in its source code).
I like to work with enclosed packages. Multistart was designed to work also in parallel, so it should work for me too.
Anyway, I think the loop index "i" is not the correct number for me. Say I have 1000 start points, this would mean I create a pool with 1000 workers.
Based on my understanding, if I have 100 start vectors and create a pool with 5 workers, each pool gets 20 local runs which are run successively on this pool. But I am not sure if it works like that.
Torsten
Torsten el 18 de Nov. de 2023
Editada: Torsten el 18 de Nov. de 2023
Isn't this a question you should ask Mathworks Technical Support ?
And if you do so, please report back - it's an interesting question.
Say I have 1000 start points, this would mean I create a pool with 1000 workers.
I don't think that a loop over 1000 start points will be immediately distributed in completeness on 1000 workers. This would be very restrictive to parallelize loops in general.
And if you do so, please report back - it's an interesting question.
Do you think the technical support is the right place to ask? Not the community?
In any case, I will report here -- of course!
Torsten
Torsten el 18 de Nov. de 2023
Editada: Torsten el 18 de Nov. de 2023
I think to answer this question reliably, one needs to have deeper knowledge about the MATLAB internals. Technical Support should be the right place to ask in my opinion.
But noone hinders you just to test the idea: make a loop over 1000 initial values, supply the loop index to the objective function and try to parallelize this loop. The computer won't take damage ...
But noone hinders you just to test the idea: make a loop over 1000 initial values, supply the loop index to the objective function and try to parallelize this loop. The computer won't take damage ...
"task = getCurrentTask" followed by "task.ID" gives an identifier in the range [1,...,NumWorkers].
Now, what remains to figure out is if there is more than one loop index running at a time within a worker, that is, whether the above taskID is a unique file identifier or not. If not, as you said, the best solution is probably to code the loop by myself and using the loop index as file identifier.
Did you get an answer from MathWorks ? Or did you prefer not to submit a service request ?
SA-W
SA-W el 20 de Nov. de 2023
Editada: SA-W el 20 de Nov. de 2023
I did not ask the technical support, but created another chat since I found similar questions of this kind in the community here.
Based on the tests I have run, getCurrentTask.Id is a unique identifier and there are no two indices running simultaneously on a worker. This is also what is mentioned in the comment I received in the linked question.
I did not ask the technical support
Just out of curiosity: Don't you have a valid licence or what's the reason ?
Just out of curiosity: Don't you have a valid licence or what's the reason ?
I have one. But, to be honest, I found it more realistic to get an answer here than from the technical support.
I don't think so - at least not for such a technical question. But you are of course free to do what you like.

Iniciar sesión para comentar.

 Respuesta aceptada

Jasvin
Jasvin el 22 de En. de 2024
Editada: Jasvin el 22 de En. de 2024
So as per the current discussion, it looks like your key requirement is to figure out how Parallel solving works with "MultiStart" and I believe the below documentation page describes exactly that:
Also to add to the point about "getCurrentTask", you can through all the properties available to you on this page: https://www.mathworks.com/help/parallel-computing/parallel.task.html
Among these properties, the "Worker" property seemed to be of most relevance, the "ID" property is associated with each task and "Worker" property would fetch you the worker that's running this task.
These are the properties you can fetch from a "Worker" object:
You can use this data (worker name and task ID) and pass it to your objective function to generate a unique directory that data should be read from/written to.

Más respuestas (0)

Preguntada:

el 18 de Nov. de 2023

Editada:

el 22 de En. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by