Error 'The process cannot access the file because it is being used by another process' during a parfor loop
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Tong Zhao
il 15 Feb 2022
Commentato: Tong Zhao
il 16 Feb 2022
I am using parfor loop and system() function to run batches of simulations based on a codgenerated file from a simulink model, and writing to output files and logs.
And on Win10, I get an error like the following:
Error using driftTrans_rsim (line 129)
Error running batch file 'driftTrans_001' :
C:\github\DriftControl\rapid_sim_Win10>echo "driftTrans.exe -p driftTrans_prm_sets.mat@1 -o driftTrans_run1.mat -L 60 2>&1>> driftTrans_001_run_scr.log"
"driftTrans.exe -p driftTrans_prm_sets.mat@1 -o driftTrans_run1.mat -L 60 2>&1>> driftTrans_001_run_scr.log"
C:\github\DriftControl\rapid_sim_Win10>driftTrans.exe -p driftTrans_prm_sets.mat@1 -o driftTrans_run1.mat -L 60 2>&1 1>>driftTrans_001_run_scr.log
The process cannot access the file because it is being used by another process.
C:\github\DriftControl\rapid_sim_Win10>echo "driftTrans.exe -p driftTrans_prm_sets.mat@2 -o driftTrans_run2.mat -L 60 2>&1>> driftTrans_001_run_scr.log"
"driftTrans.exe -p driftTrans_prm_sets.mat@2 -o driftTrans_run2.mat -L 60 2>&1>> driftTrans_001_run_scr.log"
C:\github\DriftControl\rapid_sim_Win10>driftTrans.exe -p driftTrans_prm_sets.mat@2 -o driftTrans_run2.mat -L 60 2>&1 1>>driftTrans_001_run_scr.log
The process cannot access the file because it is being used by another process.
It seems that the parallel workers have conflict in accessing files. There are four types of files involved:
1 model file, with the name driftTrans.exe;
2 parameter sets file, with the name driftTrans_prm_sets.mat;
3 simulation output file, with the names driftTrans_run1.mat, driftTrans_run2.mat, ...;
4 log file, with the names driftTrans_001_run_scr.log, driftTrans_002_run_scr.log, ....
While generating the batch script, I made sure that each line creates a unique simulation output file name; however, the log files are per batch file, and every batch file contains 20 lines to run 20 simulations. What I cannot tell is, whether the error was because of writing to the same log file, or because of multiple workers trying to access the same model file driftTrans.exe.
Any tip on how to identify the source of the error? Also just a note, the program runs perfectly fine on an Ubuntu 18.04.6 OS, but causes error in Windows 10.
0 Commenti
Risposta accettata
Walter Roberson
il 15 Feb 2022
Your code is using the same error log file for both. driftTrans_001_run_scr.log . This is unlike your text description where you expect driftTrans_002_run_scr.log for the second one.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Simulink Coder in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!