How to speed up calculations?

조회 수: 22 (최근 30일)
F?rat
F?rat 2011년 12월 27일
Hello, I am running a code creating and then analyzing large arrays (let's say consisting 15M data). My problem is that, when the code is running, I observe that the cpu usage is at 25% and RAM usge is about 410 Mb. My computer has 4 gb ram and is 2.9 Ghz. How can I make matlab to use more cpu and ram in order to speed up the calculations. (now the calculation time is about 2 hours). ps: I pre allocated every array, also changed the virtual memory size and swap size and tried to switch 3gb from command prompt with BCDEdit /set increaseuserva 3072 command. Any help would be appreciated.

채택된 답변

Aurelien Queffurust
Aurelien Queffurust 2011년 12월 27일
You have made a lot of things already about hardware enhancement like setting the 3GB Switch. You should use the profiler of MATLAB to find bottlenecks if any.

추가 답변 (2개)

Junaid
Junaid 2011년 12월 27일
Dear,
If you process are sequential then It would be problem. The best way to improve the speed is to avoid loops. As in matlab, you can use high level syntax to avoid looping. Once your avoid unnecessary loops then you will observe that your computation is increased. Secondly try to use maximum Matlab libraries rather then writing your own code in matlab. As anything written in matlab synatx is comparatively very slow compare to mex files. As many of the functions of matlab are written in mex file to boost the computtation. For example, you want to compute the Euclidean distance of one vector Q very large set of vectors M. Where is Q is Colum vector and M is matrix with 10000 colums. Once possible way is to iterate your loop with 10000 times to compute the distance or use optimized code of matlab.
new_Q = repmat(Q,1,size(M,2));
E_distance = sqrt(sum((new_Q-M).^2));
The above code computes the Euclidean distance of Q with each vector in M without loops. If you execute similar code in Loop then you will observe that it 10 folds computational expensive.
  댓글 수: 3
Junaid
Junaid 2011년 12월 27일
I do agree with you Sean, but in question he only concern the with speed.
Jan
Jan 2011년 12월 27일
Vectorization is not a magic accelerator for everything. Example: If several calculations are performed on the same data, the vectorization adds the need of large temporary array such that the runtime grows. This can matter even if the memory is not exhausted.
Allocating memory for temporary arrays needs a lot communication with the slow RAM such that the processor core falls to sleep and the processor load gets smaller than 1/(Number of cores).

댓글을 달려면 로그인하십시오.


Jan
Jan 2011년 12월 27일
It depends on the calculations. Please use the profiler to find the bottlenecks and post the relevant code. Then suggestions are possible.

카테고리

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