How to speed up calculations?

36 visualizzazioni (ultimi 30 giorni)
F?rat
F?rat il 27 Dic 2011
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.

Risposta accettata

Aurelien Queffurust
Aurelien Queffurust il 27 Dic 2011
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.

Più risposte (2)

Junaid
Junaid il 27 Dic 2011
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 Commenti
Junaid
Junaid il 27 Dic 2011
I do agree with you Sean, but in question he only concern the with speed.
Jan
Jan il 27 Dic 2011
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).

Accedi per commentare.


Jan
Jan il 27 Dic 2011
It depends on the calculations. Please use the profiler to find the bottlenecks and post the relevant code. Then suggestions are possible.

Community Treasure Hunt

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

Start Hunting!

Translated by