1

I would like to shut down my parallel pool by a button press in a Matlab GUI to stop the execution of functions running on these pool workers.

Unfortunately this only works when starting the functions with "parfeval()". In this case, as soon as I press the button, my parallel pool is shutting down and therefore the functions called with parfeval() stop running.

As I prefer using "spmd" over "parfeval" to establish communication between the workers, I tried the same but it failed.

Nothing is happening on a button press and the parallel pool is only shutting down as soon as I cancel the whole script with ctrl+c.

Hope someone can assist me with this problem.

Working:

function StartButtonPushed2(app,event)
    pool = gcp();
    parfeval(pool, @dosomething, 0, app);
end

Not working:

function StartButtonPushed1(app,event)
    pool = gcp();
    spmd 
        dosomething(app);
    end
end

function StopButtonPushed(app,event)
    delete(gcp); %shutdown pool
end

Goal:

My final goal is, to start different functions in parallel by using a start button.

These functions are supposed to collect data from SPS, OPC UA Server and different Sensors and continuously write the collected data to a SQL Database.

To write the data to the DB I thought about having another parallel function - let's call it "writeDB" - which is receiving chunks of data from the data-collecting functions and upload it.

The stop button should end the data collection by interrupting all functions - currently I am doing this by deleting the parpool.

Thanks in advance!

timosmd
  • 159
  • 11

1 Answers1

1

For your use-case, asynchronous execution of the parallel tasks is critical.

The asynchronous evaluation of fcn does not block MATLAB (from doc parfeval)

When using parfeval your primary MATLAB instance is not blocked, allowing the GUI to execute code. Synchronous interfaces like spmd or parfor are not suitable for your situation. While the workers are busy, your primary instance is blocked and unable to execute any code.

Related (same question asking for parfor): https://mathworks.com/matlabcentral/answers/401838-how-to-halt-parfor-execution-from-a-ui

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • Thanks a lot for the information! So I need to stick with parfeval. But I guess I won't be able to establish communication between the differen parfeval-functions then, right? This might be a problem... – timosmd Apr 09 '20 at 11:37
  • I am not sure how to understand your question. Is your goal to use the output of of one function all as the input of the next, without communicating the data? If so I would stitch both functions together to one anonymous function and use a single call of `parfeval`. I might have missed something here, a new question with some code example might help where data should flow. – Daniel Apr 09 '20 at 12:04
  • I edited my first question and added my final goal. – timosmd Apr 09 '20 at 12:46