MATLAB Engine RunOptions do not seem to work with parfeval

1 回表示 (過去 30 日間)
Nolin Borrero Jr
Nolin Borrero Jr 2024 年 4 月 10 日
回答済み: Nolin Borrero Jr 2024 年 4 月 17 日
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 件のコメント
Sam Marshalik
Sam Marshalik 2024 年 4 月 11 日
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 2024 年 4 月 11 日
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.

サインインしてコメントする。

採用された回答

Nolin Borrero Jr
Nolin Borrero Jr 2024 年 4 月 17 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by