MATLAB Engine RunOptions do not seem to work with parfeval

1 view (last 30 days)
I am using MATLAB Engine with 2023b. When I specify a TextWriter in RunOptions, the expected behavior is that all disp() functions well send the value to the TextWriter. This works for the client portion of the function. If I create a worker thread using parfeval and provide a dataQueue, I expected to be able to make calls to disp basically the same way.
msg = parallel.pool.DataQueue;
msg.afterEach(@disp);
However, the behavior that I'm seeing is that these messages end up in the MATLAB Command Window.
Is there any way around this? Can I get the disp calls from the worker thread to use the same TextWriter that was specified in RunOptions?
Also, if I use MATLAB Runtime, then the messages in afterEach(@disp) do not show up at all.
  2 Comments
Sam Marshalik
Sam Marshalik on 11 Apr 2024
Hey Nolin, can you provide a bit more information about your situation and goal.
Are you looking to create a DataQueue between multiple threaded workers or something else?
parfeval workers run in the background, so how are you looking to collect their displays output?
Nolin Borrero Jr
Nolin Borrero Jr on 11 Apr 2024
I am creating a DataQueue per my example. This DataQueue is set to call disp on the afterEach.
In calls using MATLAB Runtime, you provide a RunOptions struct from C#:
// Summary:
// Creates a MathWorks.MATLAB.Types.RunOptions instance to run MATLAB functions
// with the specified output and error streams and given number of output arguments
// either synchronously or asynchronously.
//
// Parameters:
// output:
// Stream used to store the standard output from the MATLAB function.
//
// error:
// Stream used to store the error message from the MATLAB function.
//
// nargout:
// Number of returned values.
//
// async:
// Whether to run the function asynchronously.
public RunOptions(TextWriter output, TextWriter error, int nargout = 1, bool async = false)
I am looking to collect their displays outputs using the TextWriter output in the RunOptions.

Sign in to comment.

Accepted Answer

Nolin Borrero Jr
Nolin Borrero Jr on 17 Apr 2024
Found out that afterEach will not use the TextWriter so this is not possible.
The closest workaround is using norml 'disp' calls on the worker task which will be stored in the Diary for the worker and then you can poll that diary looking for updates.

More Answers (0)

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!