Reputation: 1454
I have written a program in matlab and my algorithm depends on few parameters let's say a and b with a=1:10
and b=1:10
I want to find those values of a
and b
which gives me the best results.
My main code is as follows:
a= 0.1:0.1:1;
b= 1:1:10;
arr_mat = zeros(length(a),length(b));
for i=1:length(a)
for j=1:length(b)
disp(['loop no = ',num2str(i),' & ',num2str(j)]);
knn = a(j);
eta = b(i);
arr_mat(i,j) = called_function(knn,eta);
end
end
The program runs but is very computationally expensive. I was wondering if there is any matlab inbuilt parallel processing toolbox which will be helpful for me in this case. I was thinking along these lines :
Divide my main program into parts:
a1= 0.1:0.1:0.5;
b1= 1:1:5;
arr_mat1 = zeros(length(a1),length(b1));
for i1=1:length(a)
for j1=1:length(b)
disp(['loop no = ',num2str(i1),' & ',num2str(j1)]);
knn1 = a1(j);
eta1 = b1(i);
arr_mat1(i,j) = called_function(knn1,eta1);
end
end
a2= 0.6:0.1:1;
b2= 6:1:10;
arr_mat2 = zeros(length(a2),length(b2));
for i2=1:length(a2)
for j2=1:length(b2)
disp(['loop no = ',num2str(i2),' & ',num2str(j2)]);
knn2 = a2(j);
eta2 = b2(i);
arr_mat2(i,j) = called_function(knn2,eta2);
end
end
Run the codes in parallel. My system configuration is : Intel Core i7-3770 @ 3.40 GHz with 32.0 GB RAM. I have MATLAB 2013b installed.
I have consulted this question and have tried to write my own code in that format:
clc;clear all;close all;
% run ixmas for different modifications
a= 0.1:0.1:1;
b= 1:1:10;
arr_mat = zeros(length(a),length(b));
matlabpool open local 2
parfor i=1:length(a)
for j=1:length(b)
disp(['loop no = ',num2str(i),' & ',num2str(j)]);
knn = a(j);
eta = b(i);
recog = 0;
for k=1:5
recog(k) = ixmas(knn,eta);
end
arr_mat(i,j) = mean(recog);
end
end
end
matlabpool close
This code throws up the error : "Illegal use of reserved keyword "end"." My queries :
Upvotes: 0
Views: 110
Reputation: 1409
matlabpool does not open a statement that needs a closing end
. In the linked question the end is closing the spmd
statement.
The meaning of the statement matlabpool open local 2
is:
matlabpool
open or closes a pool of matlab parallel processing worker processes.
open
tells matlab to run these workers. (this is the default)
local
tells matlab to open these workers on the local machine (this is the default)
2
tells matlab to run 2 such workers (default is number of cpus)
You can just matlabpool without any parameters.
in order to configure the local profile go to the matlab home tab and choose 'manage clusters' under the parallel menu.
Also, for some strange reason matlab can't split the array between the workers when the parfor is not in the inner most loop. change the inner for to parfor and it will work.
Upvotes: 1