Memory Overflow when looping over parser function
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I'm trying to create a small benchmark script for a C++ written xtc-parser that should measure the function time for several files of different sizes. In order to minimize errors I want to use the mean of 1000 function calls which leads to the problem that MatLab is allocating more and more memory to save the loaded data. I assigned the to a variable to trick MatLab to overwrite the data and tried to use clear and clearvars but still the memory is not released and more memory is allocated. I'm currently using this code to generate my data and output file.
n=[1:1:10,20:10:100,200:100:1000,2000:1000:16000];
out=[0,0];
for i= n
path=['~/xtc_complex_',num2str(i),'.xtc'];
tic;
for j=1:1000
parseXtc(path);
end;
time=toc;
time2=time/1000;
time3=[1,time2];
out=cat(1,out,time3);
end;
csvwrite('/home/dombrowsky/Benchmark_complex_gro2mat.dat',out);
PS: I am not used to MatLab syntax and therefore every remark regarding my code would be highly appreciated.
0 个评论
回答(1 个)
Jan
2016-12-8
Pre-allocating out is easy:
n = [1:1:10,20:10:100,200:100:1000,2000:1000:16000];
out = zeros(numel(n), 2);
for k = 1:numel(n)
i = n(k);
...
out(k, :) = time3;
end
But you n is such small, that I cannot imagine that this causes a memory overflow. More likely the problem is within parseXtc. Please mention the line, which causes the error.
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!