フィルターのクリア

call python function in parfor loop

11 ビュー (過去 30 日間)
Kevin Zhu
Kevin Zhu 2022 年 2 月 19 日
回答済み: Al Danial 2023 年 7 月 8 日
I have managed to call python function in matlab. However, I would like to know if it is possible to call python function within a parfor loop? If it is not, is there a method to perform parallel computation in my python function?
  5 件のコメント
Kevin Zhu
Kevin Zhu 2022 年 2 月 20 日
what do you mean snippet? I have pasted all the warning message from command window here.
Takayuki Nagata
Takayuki Nagata 2023 年 6 月 21 日
Hi.
I am facing the same problem.
My environment is MATLAB R2023a on Windows 10 with Python 3.8.
I would appreciate it if you could give me some guidance.
My MATLAB script is as follows:
clear all
np = py.importlib.import_module('numpy');
nr=10;
alpha=0.2;
q_sbf = np.loadtxt("xxx.txt");
[v_ic_org,~] = pyrunfile('F_extract_initial_state.py',["v_ic_org","u"],q_sbf=q_sbf);
Z=zeros(size(double(v_ic_org)))';
parfor r=1:nr
v_ic = alpha*randn(size(double(v_ic_org)));
tmp = pyrunfile('F_sim_linear_fwd.py',"sol_lin",q_sbf=q_sbf,v_ic=v_ic);
z = double(tmp);
Z(:,r) = z(:,end);
end
Thank you!

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

回答 (1 件)

Al Danial
Al Danial 2023 年 7 月 8 日
An alternative to parfor is to run the loop in parallel with dask. The function running in parallel, sol_lin(), in your case, can either be sent to the cores on your own computer, or to multiple computers on your network.

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by