Using parfeval to call eval function not working - why?
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lisa Taylor
el 27 de Jun. de 2022
Editada: Lisa Taylor
el 28 de Jun. de 2022
First of all, I know using eval at all is generally bad practice, but in this case it's kind of necessary. I have a piece of software where users (other programmers) need to be able to write their own functions to be called at a particular time. It includes a GUI where, before running the software, they can browse to the function that they want to run at a particular point in the process. The name of the function is saved to the GUI model and I use eval to make sure the correct function is run when the time comes. This software has been used for a couple years without issue so the eval aspect of this works just fine for our case.
Now I'm trying to update the software so that this function, that was generated by the user, is run on a parallel pool. An abstraction of my code would look like this:
P = parpool(1);
Q = parallel.pool.DataQueue;
afterEach(Q, @disp);
run_command = "test_func(Q)"; %This is a test function I created, normally this would contain a string with the user's function name and inputs
success = parfeval(P, @eval, 1, run_command);
I then have the function test_func defined as follows:
function test_func(Q)
send(Q, 1);
pause(2);
send(Q, 2);
pause(2);
send(Q, 3);
end
This code above does not display the numbers as expected. When I look at 'success', the FevalFuture, it shows an error message of:
"Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='." at line 39 of this file: C:\Program Files\MATLAB\R2021b\toolbox\parallel\cluster\+parallel\+internal\+queue\evaluateRequest.m.
I'm not sure if this file is part of the eval function or part of the parfeval function. So I guess I'm wondering why my original code which simply looked like
eval(run_command);
works just fine, but putting this into parfeval suddenly throws this random error?
If I change the code to pass test_func into parfeval directly, it works just fine.
P = parpool(1);
Q = parallel.pool.DataQueue;
afterEach(Q, @disp);
run_command = "test_func(Q)"; %This is a test function I created, normally this would contain a string with the user's function name and inputs
success = parfeval(P, @test_func, 1, Q);
So it seems like using @eval as the function passed to parfeval is causing some kind of issue. My question is why? Is this a combination that just doesn't work or is there something wrong with the way I am calling it?
Any insight would be appreciated, as I'm new to parallel computing. Thank you!
0 comentarios
Respuesta aceptada
Walter Roberson
el 27 de Jun. de 2022
Transparency violation. parfor and parfeval need to know the names of the functions at analysis time so that it can copy the code to the workers before evaluation starts.
8 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Asynchronous Parallel Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!