Parpool with multiple MATLAB sessions

9 views (last 30 days)
Yuka
Yuka on 16 Apr 2020
Answered: TED MOSBY on 1 Sep 2024
I have one MATLAB session running ga() with parpool. When I do simple operations like loading files and plotting in another MATLAB session, sometimes (though not all the time) the session with ga() running will say "Analyzing and transferring files to the workers ...done." in the command line, and then it errors out.
The error says:
"An UndefinedFunction error was thrown on the workers for 'errorMetric'. This might be because the file containing 'GA_errorMetric' is not accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files to be attached."
The errorMetric is the fitness function used in ga, and specifying the file where the function is defined using addAttachedFiles does not solve the issue.

Answers (1)

TED MOSBY
TED MOSBY on 1 Sep 2024
Hi,
The error message you're having can mean that the workers in your parallel pool cannot access the errorMetric function file needed for the genetic algorithm (GA) to evaluate the fitness function. This might happen if the file is not properly attached to the workers or if there are issues with file paths or synchronization between sessions. As you have not provided with the code files and other details I can suggest some general ways which by which you can validate and verify if you are using the parallel pool in the right way. Below are some steps you can try to resolve this issue:
1. Ensure Proper File Attachment
It's important to ensure that the file path is correct and that the file is accessible to all workers.
% Assume 'errorMetric.m' is the file containing your fitness function
pool = gcp(); % Get current parallel pool
addAttachedFiles(pool, {'path/to/errorMetric.m'});
2. Use Absolute Paths
Ensure that you are using absolute paths when specifying the file to avoid any ambiguity about the file's location.
3. Verify File Accessibility
Check that the file errorMetric.m is not open or locked by another process, which could prevent it from being accessed by the parallel workers.
4. Check MATLAB Path
Ensure that the directory containingerrorMetric.m is included in the MATLAB path. You can add it using:
addpath('path/to/your/functions');
5. Synchronize File Changes
If you make changes to errorMetric.m while the parallel pool is running, you'll have to update the workers with the latest version.
  • Restarting the parallel pool after changes:
delete(gcp('nocreate')); % Close current pool
parpool; % Start a new pool
  • Re-attaching the file after changes:
pool = gcp();
addAttachedFiles(pool, {'path/to/errorMetric.m'});
6. Debugging
To diagnose the issue, try these steps:
  • Check Worker Logs: Use spmd blocks to debug and check if the file is accessible on each worker
spmd
if exist('errorMetric.m', 'file') == 2
disp('File is accessible on worker');
else
disp('File is not accessible on worker');
end
end
  • Use which Command: Verify the file path using the which command to ensure MATLAB is accessing the correct file.
which errorMetric
Let me know if this works for you!

Categories

Find more on Parallel Computing Fundamentals in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!