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.

回答(1 个)

Jan
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 个评论
Maximilian Dombrowsky
Thank you very much for your quick response.
parseXtc in the for loop is creating this problem. The main Problem is that xtc files consist of large matrixes (e.g., I use matrixes with row size n (1-16000) and column size 5400) which has to be reproduced in my test. parseXtc is a matlab script that uses the output of a C++ program and is present in the package gro2mat.
Jan
Jan 2016-12-9
As long as we do not see the failing code, we cannot suggest an improvement.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by