Function definition not supported on cluster, but available in interactive mode

When I try to run the following program
% Test program
for i=1:3600
waitawhile(1)
disp(i)
end
function waitawhile(time)
% wait time seconds
pause(time)
end
in Matlab (2020a) on a cluster in interactive mode (also with the -no-display option) and Matlab online it works perfectly, but when I submit it as a job on a cluster (srun matlab -nodisplay test.m) I get the following error
function waitawhile(time)
Error: Function definition not supported in this context. Create function in code file.
End
Error: Illigal use of reserved keyword 'end'
I am not sure why this error occurs and why Matlab should have a problem with a local function within a script. Is there a specific reason why this code does not work on the same cluster in interactive mode and not when submitted as a job?

댓글 수: 4

I would recommend verifying the srun gives you a MATLAB session that is running R2016b or later. It is possible that since srun is a script, that it is invoking a different version of MATLAB.
The version information shows the same version (R2020a [9.8.0.1451342] - 64 bit) for both the interactive and submitted test script.
The '. m' does not have much influence on running the code. If I remove the function in the test script and replace waitawhile with pause the code runs just fine. It has more to do the infile subroutine I presume.

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

답변 (1개)

Baoning Wu
Baoning Wu 2023년 5월 23일
I encounter the exact same problem. Any solution you found?

카테고리

도움말 센터File Exchange에서 Third-Party Cluster Configuration에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2021년 3월 29일

답변:

2023년 5월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by