Error 'The process cannot access the file because it is being used by another process' during a parfor loop

조회 수: 14 (최근 30일)
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.

채택된 답변

Walter Roberson
Walter Roberson 2022년 2월 15일
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.
  댓글 수: 1
Tong Zhao
Tong Zhao 2022년 2월 16일
Thanks Walter. I am trying to now remove the logging, but I do not know how to modify the batch commands to do so. The batch commands I have is like the following
driftTrans.exe -p driftTrans_prm_sets.mat@1 -o driftTrans_run1.mat -L 60 2>&1>> driftTrans_001_run_scr.log
Do you know how to remove the logging process? I'll give it a go after the modification.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by