running parallel optimization problem

Hello
I wrote a function to call a program and optimize its input, the program is working put slow so i thought of using parallel optimization. Then an error appeared that i could not understand.
"Failure in user-supplied fitness function evaluation. GA cannot continue."
The error happens when the FCNVECTORIZER, which is a utility function used for scalar fitness functions.when tries to send the population back to the objective function.
parfor (i = 1:popSize)
y(i,:) = feval(fun,(pop(i,:)));
end
I had not used parallel computing or optimization before. so i need help to solve this issue.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 1월 28일

0 개 추천

For debugging purposes, change the parfor to for and command
dbstop if caught error
and run again. If there is an error, you will be put in the debugger at the place that had the problem.
If no error occurs then you have a problem that is specific to parallel work. If that happens then I would ask whether your code happens to use global variables? The value of global variables are not copied to the workers.
Also you might need to use https://www.mathworks.com/help/distcomp/addattachedfiles.html so that the workers are able to find the function code.
Is your fun possible specified as a string? If it is then change your code to use a function handle: parfor cannot automatically resolve function names that are specified as strings.

댓글 수: 6

Abdulrahman Metawa
Abdulrahman Metawa 2018년 1월 28일
well my function uses a global variables but how to pass the to workers
Abdulrahman Metawa
Abdulrahman Metawa 2018년 1월 29일
편집: Abdulrahman Metawa 2018년 1월 29일
can the worker execute a dos commands:
dos('copy input.dat runningin.dat')
dos('reader runningin tmp.zzz')
dos('solver runningin tmp.zzz')
dos('rename runningin.num input.num')
dos('rename runningin.nod input.nod')
dos('del runningin.*')
Walter Roberson
Walter Roberson 2018년 1월 29일
Yes. However when you use the same file names for each worker then the routines are going to interfere with each other.
Abdulrahman Metawa
Abdulrahman Metawa 2018년 1월 29일
can i specify the directory in which each worker can operate
Not directly, but you can make one and CD there.
td = tempname();
mkdir(td);
cd(td);
Now you can copy in whatever files you need into your current directory.
You might want to add an onCleanup that removes the directory so that the files do not get left around.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

제품

질문:

2018년 1월 28일

댓글:

2018년 1월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by