作者mibmibx (Lin)
看板MATLAB
标题[讨论] 平行运算写入问题
时间Wed Apr 25 03:54:41 2018
各位前辈好
我写了一个的script用来把另一个function的数值写入txt档
内容如下
--------------------------
temp = 300;
int_temp = zeros(temp, 1);
filename = ['int_vs_T.txt'];
filepath = sprintf(filename);
fidw = fopen(filepath, 'w+');
for ii = 1 : temp
int_temp(ii, 1) = SO_phase_tran_ver3(400,4,1.5,1.5,0,ii);
fprintf(fidw, '%.6f\r\n', int_temp(ii, 1));
end
fclose(fidw);
--------------------------
由於实在算的很慢,想试试看平行运算
因此我把script改成
-------------------------
parpool(2)
temp = 300;
int_temp = zeros(temp, 1);
filename = ['int_vs_T.txt'];
filepath = sprintf(filename);
fidw = fopen(filepath, 'w+');
parfor ii = 1 : temp
int_temp(ii, 1) = SO_phase_tran_ver3(400,4,1.5,1.5,0,ii);
fprintf(fidw, '%.6f\r\n', int_temp(ii, 1));
end
fclose(fidw);
parpool close
-------------------------
不过改成这样之後会出现以下错误讯息
Invalid file identifier. Use fopen to generate a valid file identifier.
想请问造成这个错误的原因为何?
是因为平行运算没办法同时把资料写入'int_vs_T.txt'这个档案吗?
请问修改的方向是?
希望前辈指点,感激不尽
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 130.126.255.51
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MATLAB/M.1524599683.A.07D.html