Error with reading file within a parfor loop in a compiled application
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello
I have an application that has a parfor loop in it. Part of the loop reads a .csv file and compares some values. When I run the program via MATLAB it runs perfectly fine. I have also compiled the program, but when I run the compiled program I get an error related to the file:
Unable to find or open 'C:\Program Files\MATLAB\R2022a\bin\win64\file.csv'. Check the path and filename or file permissions.
Possibly interesting is that the directory in the error is NOT where the file is..... the file is in the directory where the exe is being run from which I have obtained using the following code:
F = readcell(fullfile(getcurrentdir(),'file.csv'))
using this function to find the directory being used to execute the program:
function currentDir = getcurrentdir()
if isdeployed && ispc
[status, result] = system('set path');
currentDir = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
It seems like getcurrentdir() does NOT return the directory from where the compiled program is running when called inside the parfor loop - instead it returns this other directory 'C:\Program Files\MATLAB\R2022a\bin\win64\'
I'm suspecting this has to do with calling getcurrentdir() from within the parfor loop since it does NOT happen when I run like a normal for loop by setting the number of workers to 0
Why does this only happen when its compiled? It runs perfectly when running via MATLAB source code.
Is there a way to deal with this issue? Do I have to pass the data from file.csv into the function that runs the parfor loop so that It does not have to read the file in the actual loop?
Any help would be appreciated.
Thanks!
1 commentaire
Bruno Luong
le 29 Sep 2023
A workaround is perhaps calling getcurrentdir outside the parfor (then pass it to the worker)
Réponses (1)
Walter Roberson
le 29 Sep 2023
4 commentaires
Walter Roberson
le 29 Sep 2023
You would potentially need to do that if you are updating the csv without updating the executable.
Voir également
Catégories
En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!