- Yes! Isn't that great?
- Yes, because there are two problems with your code: (a) you're using a lot of for loops instead vector operations and (b) you're measuring GPU performance incorrectly. To fix (a), you should read this doc page that explains how to vectorize your code to get the best performance. To fix (b), you should take a look at my answer to a previous question and use the functions timeit and gputimeit.
GPU utilization and parallel computation With Matlab for heavy computation
20 views (last 30 days)
I have decent/ok machine with core i7 (8 cores), 32G of RAM and Nvidia geForce GTX 1080i and running Matlab 2018b. At the moment I am a bit confuse about how to use these resources in best way to run my Monte-Carlo simulation code. The two questions I have now:
1- How can I make all the heavy computaion to be run on the GPU alonside parallel compution capability of Matlab rather than the CPU and hence I can decide what is best to use? I have read different help topics and the conclusion I think I have got is, the data I have to work with should be in the form of gpuArray Am I right? or do I miss something here?. let us assume that I have the foollowing simple code to be run on GPU :
% First_Vector=zeros(2,3,'gpuArray'); 1
Tset1= [20 20 20:30 30 30];
Test2= [50 50 50;60 60 60];
% the main code
% End of the main code
%% Function 1
does the commented lines (1-5) are enough to run the 'main code' on the GPU?
2- I have tested the following simple code on GPU and CPU, CPU performance was by far better than GPU. is that supposed to be normal ?
thanks in advanced.
G = ones(10,10,'gpuArray');
for i=1: 1000
G = ones(10,10);
for i=1: 1000
% Elapsed time is 0.628241 seconds.
Andrea Picciau on 3 Jul 2019
Edited: Andrea Picciau on 3 Jul 2019
I'll try to answer your questions in order...