This week i came back to work with this again, and after some research and tests, this is the answer for the main file:
clc; clear;
spmd
mkdir(sprintf('worker%d', labindex));
copyfile('file1.db',sprintf('worker%d/',labindex));
copyfile('file2.mp',sprintf('worker%d/',labindex));
copyfile('file3.txt',sprintf('worker%d/',labindex));
cd(sprintf('worker%d', labindex));
end
funcao = @(x) ZF_Eval_v1_3_new(x,termino);
LB = [0.7 1.0 0.5];
UB = [3.0 3.0 0.7];
options = optimoptions('ga','MaxGenerations',20,'PopulationSize',10,'UseParallel',true); % sets PARALLEL
x = ga(funcao,3,[],[],[],[],LB,UB,[],options);
and the function file remains the same:
function val = ZF_Eval_v1_3_new(x,termino)
dlmwrite('param_otim.txt',[x(1) x(2) x(3) termino],'precision','%.5f'); % writes the individual to be read in the middle of Ansys execution
!C:\"Program Files"\"ANSYS Inc"\v150\ansys\bin\winx64\ANSYS150 -b -i "file3.txt" -o "output.txt" -np 1
T_A=load('temps_monit_ZF.txt','-ascii');
rp = 1; t_sol1 = 1467; t_sol2 = 840; % just parameters
val = rp*sqrt(((t_sol1 -T_A(1))^2 + (t_sol1 -T_A(2))^2 + (t_sol2-T_A(3))^2 + (t_sol2-T_A(4))^2 )); % objective function
end
The execution time was reduced in 40%. As Walter said, the key was to mkdir and copy the files to the workers folders. I used 3 workers for testing, so it created 3 folders, copying all the files i needed on each folder.
Hope its usefull for someone!