Hi,
I am using the parallel toolbox to run code that has been developed on a Mac on a Unix cluster. I am using Windows 10 and want to set up the code from my machine to run on the Unix cluster.
The code starts to run locally like this:
%% Set Cluster
% Get a handle to the cluster
c = parcluster;
%define username
username = 'lf';
% Create a list of all the paths in repo and supplement it so that the
% files would be on path and could be read on Cluster
localPath1 = genpath(strcat('/Users/',username,'/Documents/MATLAB/repo/data'))
Having removed the ; after localPath1, I got:
localPath1 =
'/Users/lf/Documents/MATLAB/repo/data;\Users\franssel\Documents\MATLAB\repo\data\XXX'
This, I believe, makes the code buggy as it runs as the paths with different / vs \ throws error messages.
Just FYI: The code continues by replacing the local path by the remote path, i.e. like this if we had only 1 localPath (there are more in the real code):
cellLocalPath{1} = strrep(cellLocalPath{i},strcat('/Users/',username,'/Documents/MATLAB/'),strcat('/YYY/home/',username,'/'))
I am grateful on any advice on how to deal with this as I could not find a solution online.
Thank you and best wishes,
Linnéa

댓글 수: 2

Raymond Norris
Raymond Norris 2020년 8월 16일
Hi Linnea,
Can you clarify a couple of things:
  1. Are you saying the person who originally wrote the code, wrote it with a Mac and that you'd like to submit the code from your Windows 10 machine to a Linux cluster (not running on a Mac)?
  2. How do you plan to submit the job from your machine, with parpool or batch?
I'm not sure where/how cellLocalPath is getting used, but when you call parpool/batch, you can specify additional folders (either on your machine or on the cluster) that can be added to your workers running on the cluster. This might be a slightly easier way to set paths, rather than embedded from within your code. Take a closer look at the command line arguements for parpool and batch for more information.
If not, look at fullfile if the code is being evaluated on the cluster. This will build up the folder with the appropriate file separators.
Raymond
L. Borealis
L. Borealis 2020년 8월 17일
Dear Raymond,
Thank you for the very prompt response!
I will clarify the points and then try some of the suggested answers and post my results.
  1. Exactly right
  2. I submit it using c.batch. Does this make a difference with regards to the advice you gave?
Thank you very much - also to the other responders.
I will respond asap.
Best wishes,
Linnéa

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

 채택된 답변

Image Analyst
Image Analyst 2020년 8월 16일

1 개 추천

Try this:
localPath1 = strrep(localPath1, '\', '/');

댓글 수: 6

Walter Roberson
Walter Roberson 2020년 8월 16일
Also you might need to replace ; with :
L. Borealis
L. Borealis 2020년 8월 18일
Thanks a lot to all three of you - the super easy/obvious answer by Image Analyst worked wonders. I might need to look at Raymond's solution again if it turns out that there are problems elsewhere but it all looks great for now. Thanks a lot!
Antonios Kouzelis
Antonios Kouzelis 2022년 3월 21일
편집: Walter Roberson 2022년 3월 21일
Dear Image Analyst,
I've seen you answer questions on this topic in several threads, but I can't solve it for some reason. I've downloaded a huge Matlab & Simulink file from my company, which has several built-in functions. When running the important built-in function 'run', I get the following error(s):
%in a pop up window:
Exception calling MATLAB:
Error evaluating 'InitFcn' callback of block_diagram 'vehicleModel'.
Callback string is 'vehicleModel_init'
%in the command window:
Error using runSimulations
Error evaluating 'InitFcn' callback of block_diagram 'vehicleModel'.
Callback string is 'vehicleModel_init'
Error in UseCase/run (line 196)
[obj(nusc).logData.(vehicleConfigs(nvc).name), obj(nusc).exceededBounds.(vehicleConfigs(nvc).name)] = runSimulations(obj(nusc),vehicleConfigs(nvc));
Error in run_shortcut (line 1)
usc.run(vc(1));
Error in matlab.internal.project.util.runMATLABCodeInBase
Error in matlab.internal.project.util.runMATLABCodeInBase
Error in matlab.internal.project.util.runMATLABCodeInBase
Error in matlab.internal.project.util.runMATLABCodeInBase - Show complete stack trace
Caused by:
Error using runSimulations
Could not open file
/Users/anto/Documents/Thesis/Modelling/lightyear-company-vehicle-performance-model-2.0-2a9dca746a7a/library\busDefinitions.m.
No such file or directory. - Show complete stack trace
__________________________________________
I checked in the folder and there indeed is a busDefinitions.m file there, along with several other similar files. How can I adjust the \ before busDefinitions.m to a /, for all the files in that folder?
Hope you can help me out, fingers crossed.
Thanks in advance!
Cheers, Antonios
I suggest you fix it right when you get that filename using strrep.
filename = whatever, however you get it
filename = strrep(filename, '\', '/'); % Replace backslash with a forward slash.
% Check if the file exists. Alert the user if it does not exist.
if ~isfile(filename)
% The file REALLY does not exist. Prove it by showing the File Explorer.
warningMessage = sprintf('WARNING : File does not exist:\n', filename);
uiwait(warndlg(warningMessage));
if ispc
% Open the folder in File Explorer if using Windows.
[folder, baseFileNameNoExt, ext] = fileparts(filename);
winopen(folder);
end
end
However on a Windows system it shouldn't matter - the direction of the slashes can be either direction and it should work. Give a screenshot of File Explorer showing the folder in the address field and the file in the panel below.
Walter Roberson
Walter Roberson 2022년 3월 21일
The code is being executed on a non-Windows system, most likely a Mac (based on the directory name structure.) But the model includes code that uses \ as the separator.
You will need to edit the initFcn of block diagram vehicleModel and convert the reference to library\busDefinitions.m into a reference to library/busDefinitions.m . My speculation would be that the initFcn has a run() call coded in it.
Hi guys,
Indeed, I'm using a Macbook. @Walter Roberson I located the script that called the \ location and fixed it. Thanks to you both for the support! Very much appreciated.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2020년 8월 16일

댓글:

2022년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by