Parallel program

I have a programmatic connection from multiple files .m

. The program starts a call to one of them (main) with a name tests.m

, and from there I call the other optFun.m

, where I calculate different parameters. These parameters are calculated within the loop while

, which ends when the number of changes does not change (for example, 4500). The program works fine, but I have to run it like 200 times to get 200 different sets of values. Also, I can use computer s> 12 cores, so I modified the main file a bit .m

, including the statement parfor

, to deploy 12 Matlab staff. My goal is to get 12 different solutions (execution of the original program) in one round.

function [] = tests(Num)
matlabpool open local 12;  
y = zeros(itermax,15);  
z = zeros(itermax,9);
parfor i = 1:itermax   
    [iternum tTot SolOpt ImpCostMAX minABFmax ABFmax ImportCosteABS] =...
             optFun(N, K, AntNum,...  
                    q, eps, Rt, Rs, theta, maxiter,...
                    strcat(particad,num2str(i)));   
     y(i,:) = [ i; iternum; tTot; SolOpt; ImpCostMAX(1); ImpCostMAX(2);...
                q; eps; N; K; AntNum; maxiter;...
                SolOpt/ImpCostMAX(1); SolOpt/ImpCostMAX(2); SolOpt/N];  
     z(i,:) = [ i; minABFmax(1); minABFmax(2); minABFmax(3); ABFmax(1);...
                ABFmax(2); ABFmax(3);...
                ImportCosteABS(1); ImportCosteABS(2)];   
end %parfor

matlabpool close;  
dlmwrite(nombre, y, 'delimiter', ' ','precision', '%9.5f');  
dlmwrite(b, z, 'delimiter', ' ','precision', '%9.5f');

      

I started 12 Matlab workers, but now the program seems to stop before it reaches optimal or correct results . It looks like the solution parameters of my program are outputted before 4500 iterations of the while loop are reached. Although I am getting 12 different solutions. It seems like 12 workers who share the values ​​of some of the variables, therefore, stop when the other workers are good enough about the decisions, or the sum of several of them is considered the right decision. Could you help me understand what's going on?

Thank you very much in advance Relationship

+3


source to share


1 answer


I've had a similar problem in the past. Are you sure that the "independent" evaluations of your for loop are not sharing information about the convergence of your solution with a common variable that they all use? Let's say you define convergence=zeros(1);

outside parfor

and then all subsequent calls to optFun.m use the same variable. This can also apply to a function that stores intermediate values ​​within an array.



While I can't tell if this is really your problem (no code), it might just be. In this case, I would recommend creating an independent container for each of the scores (e.g. a zeros(NoEvals,NoThingsToStore)

, where they will store data independently of each other).

0


source







All Articles