No GPU parallelization in Aiyagari1994

Howdy,

When I run Aiyagari1994.m, the GPU parallelization does not start by default as is described in the beginning of the code. My machine indeed has a GPU and other codes work properly. I tried setting vfoption.parallel = 2, but it was in vain, i.e., no GPU parallelization.

Any ideas?

Weird. Meaning it throws an error? Or?

What happens if you run
A=ones(2,2,'gpuArray')
[this code will only work if matlab can use the gpu, otherwise it will error]

Where exactly did you get the Aiyagrai1994.m from? This one: https://github.com/vfitoolkit/VFItoolkit-matlab-examples/tree/master/HeterogeneousAgentModels ?

No, the code runs correctly, no error. The code you suggested also runs correctly. I downloaded the code from the link you mentioned.

Maybe I’m confused. In the bottom left corner of the MATLAB IDE, there is this “Parallel Pool” button. When I was testing other codes, that option always started working. My interpretation was that the code asked for parallelization and, therefore, the parallel pool activated. But when I run the Aiyagari1994 model, the parallel pool is not getting activated. I interpreted this as the code not using parallelization. Am I right? Does the GPU parallelization requires the parallel pool option to be started?

Ah, that parallel pool refers to parallel cpus (Matlab has to initiate the use of parallel cpus, takes some time). It is not related to gpu.

E.g., if you run
A=ones(2,2,'gpuArray')
You will see parallel pool does not light up, and we are on gpu (everything a gpu does is essentially parallel, so it is redundant to say we are parallelizing on gpu, although admittedly I say parallelizing on gpu all the time :wink: )

Compare with running,
A=zeros(2,2);
parfor ii=1:4
A(ii)=1;
end
this time parallel pool indicator lights up (and stays lit, typically turns off if idle for a half hour).

Note that if you use the parallel pool 5 times in a row, you only have to wait for the pool to start once (if you run the above parfor 5 times, it will be slow on the first, then fast all the others, this is because it has to start the pool the first time).

[PS. The parfor above is terrible coding practice, but illustrates what we are talking about]

If you want a basic idea about GPUs and how they compute vs CPU, the first two parts of

are essentially all still relevant.

1 Like

If you run Aiyagari1994.m twice, once with vfoptions.parallel=1 and once with vfoptions.parallel=2 you should be able to see a huge speed difference (because the later uses the gpu)

Many thanks for the great explanation! Very helpful!

1 Like

But why does the parallel pool activate while running the scripts with GPU? For example, I attempted the Aiyagari transition. When computing both stable states, the parallel pool was turned off. However, it turned on when the transition began.

1 Like

Not 100% sure. I would have to look very closely at what exactly was being done (there is probably some line in the transition code that is activating the parallel pool for cpus, perhaps unnecessarily; because it is largely harmless it is not something I normally go try and correct).

1 Like