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
2018년 1월 28일
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
2018년 1월 28일
Walter Roberson
2018년 1월 28일
Recode to avoid using global variables.
Abdulrahman Metawa
2018년 1월 29일
편집: Abdulrahman Metawa
2018년 1월 29일
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
2018년 1월 29일
Walter Roberson
2018년 1월 29일
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)에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!