Is it possible to load and modify the same .mat file in two instances of matlab?

4 ビュー (過去 30 日間)
I am attempting to parallelize my Matlab code without using the parallel computing toolbox, since parfor cannot be compiled using mcc, as far as I know.
Would I run into any issues if I ran the following code simultaneously on two or more Matlab instances?
function simulate(input_data,index,foo,bar)
load(foo);
load(bar);
tempdata = subfunction(input_data(index,:));
if all(tempdata(:,2) <10)
foo_data= vertcat(foo_data,[tempdata,input_data(index,end)]);
else
bar_data = vertcat(bar_data,[tempdata,input_data(index,end)]);
end
save(foo,'foo_data');
save(bar,'bar_data');
end
(where subfunction is another .m file in the current working directory)
Each instance of matlab would have a different index input.
Thanks in advance!
  2 件のコメント
José-Luis
José-Luis 2014 年 1 月 17 日
I think that would depend on your OS more than on Matlab.
Margaret
Margaret 2014 年 1 月 17 日
I'm planning to compile my code using mcc, and run my code in parallel job tasks. I'm still trying to figure out how the m-code would handle the i/o. So, my OS would be Linux?

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

採用された回答

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014 年 1 月 17 日
編集済み: Bruno Pop-Stefanov 2014 年 1 月 17 日
I don't know if your code would work but trying to access a single resource from two different processes sounds like a bad idea. I can't speak for MATLAB, but in general, for safety reasons, when a process opens a file (a resource), the file is locked until the process releases it. Assuming that you could access your data in two instances of MATLAB, you don't know how and in which order each unit of data is accessed at a lower, byte level. You could end up with deleted segments of your data, or with duplicated data. If you really want to run two instances of MATLAB, I would recommend to split your data in two and give one side each.
  4 件のコメント
Margaret
Margaret 2014 年 1 月 17 日
Thanks again Bruno! You've been a great help.
Walter Roberson
Walter Roberson 2014 年 1 月 18 日
I do seem to recall that the parts of a .mat file can be concatenated, but possibly not the header as well... that part I do not recall. Also if a variable occurs in multiple places, the last version of it would hold; they would not be concatenated together.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel Computing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by