Reputation: 308
In my Matlab script, I run an algorithm with a for
loop in which, at each iteration, I need to do a gradient descent. All the gradient descent are independent. Here is the structure of my script :
for i=1:p
x=gradient_descent(x_init,grad_g,opts(i));
end
where opts(i)
is a structure which contains variables necessary to the gradient descent. In this case, $p=145$. My script runs in $8$ seconds on my machine (without using any parallel trick).
I have the impression that my script can be parallelized since each gradient descent in independent. When I un matlabpool
on my computer, I can use up to 4 labs. Simultaneously, each lab could run a gradient descent and, instead of doing one gradient descent at a time, I would be able to do 4. But I do not know how I could parallelize my script. From what I have found on Internet, I could use the batch
function, right ?
Upvotes: 0
Views: 258
Reputation: 745
I think this should work:
parfor i=1:p
x{i}=gradient_descent(x_init,grad_g,opts(i));
end
Upvotes: 4