Memory Overflow when looping over parser function

조회 수: 3 (최근 30일)
Maximilian Dombrowsky
Maximilian Dombrowsky 2016년 12월 8일
댓글: Jan 2016년 12월 9일
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
Maximilian Dombrowsky 2016년 12월 9일
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