How can fetch and exec work inside parfor-loop
1 次查看(过去 30 天)
显示 更早的评论
The following is my code: when change parfor to for, everything works fine, but when in parfor-loop, it won't work.
Can someone know how to let exec and fetch work inside a parfor-loop ?Thanks.
sqlStr = 'select echo,wave from vibdata';
parfor m = 1:size(vs_list_temp,1)
DatabaseExpo(xx1,'','',xx2,xx3,m,sqlStr); % let everything do in DatabaseExpo function
end
function DatabaseExpo(loca1,loca2,loca3,loca4,loca5,m,sqlStr)
eval(['conn_' num2str(m) ' = database(loca1,loca2,loca3,loca4,loca5);'])
eval(['curs_' num2str(m) ' = exec(conn_' num2str(m) ',sqlStr);'])
dataObj = fetch(eval(['curs_' num2str(m)]));
data = dataObj.Data;
close(eval(['curs_' num2str(m)]));
close(eval(['conn_' num2str(m)]));
save(['dbrjs' num2str(m)],'data');
2 个评论
Edric Ellis
2021-1-18
What's the error you are getting? Are you sure your database supports multiple concurrent connections? Rather than using eval , you ought to be able to simply something more like this:
parfor m = ..
out{m} = DatabaseExpo(..,m,..);
end
function data = DatabaseExpo(..)
conn = database(..);
curs = exec(conn, sqlStr);
dataObj = fetch(curs);
data = dataObj.Data;
close(curs);
close(conn);
end
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Database Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!