Error when running function with batch()
Hi. I am using batch() to run a function with a par-for loop inside. When I run it as a script (instead of a function), everything works fine. However, when I replace the script with the equivalent function, I get an error. Here are the details:
%(A) Using batch() to call script. This works fine!
job = batch(parcluster(‘local’), ‘batchscript’,’Pool’,5);
%(B) Using batch() to call function. This produces an error.
jm=6;
job = batch(parcluster(‘local’),’batchfun’,0,{jm},’Pool’,5);
The script (batchscript.m) I am running in A, looks something like that:
jm = 6;
run(‘Paths.m’) %This creates ‘pth’ using ‘jm’
parfor vh = 1:length(alld)
parfun01(vh,jm,pth)
end
The function (batchfun.m) I am running in B, looks something like that:
function batchfun(jm)
run(‘Paths.m’) %This creates ‘pth’ using ‘jm’
parfor vh = 1:length(alld)
parfun01(vh,jm,pth)
end
They reason why I decided to turn this from a scrip to a function was because I wanted to pass jm as an input, instead of always changing the script. However, I cannot understand why it works perfectly fine as a script, but not as a function.
The error I am getting when running B) is the following:
getReport(job.Tasks(1).Error)
ans =
‘Error using batchfun (line 66)
The source code (E:Analysisbatchfun.m) for the parfor-loop that is trying to
execute on the worker could not be found.
Caused by:
Unrecognized function or variable ‘pth’.
Error using remoteParallelFunction (line 84)
Worker unable to find file.
Unrecognized function or variable ‘pth’.’
Anyone could please help me with what’s wrong? Thanks!Hi. I am using batch() to run a function with a par-for loop inside. When I run it as a script (instead of a function), everything works fine. However, when I replace the script with the equivalent function, I get an error. Here are the details:
%(A) Using batch() to call script. This works fine!
job = batch(parcluster(‘local’), ‘batchscript’,’Pool’,5);
%(B) Using batch() to call function. This produces an error.
jm=6;
job = batch(parcluster(‘local’),’batchfun’,0,{jm},’Pool’,5);
The script (batchscript.m) I am running in A, looks something like that:
jm = 6;
run(‘Paths.m’) %This creates ‘pth’ using ‘jm’
parfor vh = 1:length(alld)
parfun01(vh,jm,pth)
end
The function (batchfun.m) I am running in B, looks something like that:
function batchfun(jm)
run(‘Paths.m’) %This creates ‘pth’ using ‘jm’
parfor vh = 1:length(alld)
parfun01(vh,jm,pth)
end
They reason why I decided to turn this from a scrip to a function was because I wanted to pass jm as an input, instead of always changing the script. However, I cannot understand why it works perfectly fine as a script, but not as a function.
The error I am getting when running B) is the following:
getReport(job.Tasks(1).Error)
ans =
‘Error using batchfun (line 66)
The source code (E:Analysisbatchfun.m) for the parfor-loop that is trying to
execute on the worker could not be found.
Caused by:
Unrecognized function or variable ‘pth’.
Error using remoteParallelFunction (line 84)
Worker unable to find file.
Unrecognized function or variable ‘pth’.’
Anyone could please help me with what’s wrong? Thanks! Hi. I am using batch() to run a function with a par-for loop inside. When I run it as a script (instead of a function), everything works fine. However, when I replace the script with the equivalent function, I get an error. Here are the details:
%(A) Using batch() to call script. This works fine!
job = batch(parcluster(‘local’), ‘batchscript’,’Pool’,5);
%(B) Using batch() to call function. This produces an error.
jm=6;
job = batch(parcluster(‘local’),’batchfun’,0,{jm},’Pool’,5);
The script (batchscript.m) I am running in A, looks something like that:
jm = 6;
run(‘Paths.m’) %This creates ‘pth’ using ‘jm’
parfor vh = 1:length(alld)
parfun01(vh,jm,pth)
end
The function (batchfun.m) I am running in B, looks something like that:
function batchfun(jm)
run(‘Paths.m’) %This creates ‘pth’ using ‘jm’
parfor vh = 1:length(alld)
parfun01(vh,jm,pth)
end
They reason why I decided to turn this from a scrip to a function was because I wanted to pass jm as an input, instead of always changing the script. However, I cannot understand why it works perfectly fine as a script, but not as a function.
The error I am getting when running B) is the following:
getReport(job.Tasks(1).Error)
ans =
‘Error using batchfun (line 66)
The source code (E:Analysisbatchfun.m) for the parfor-loop that is trying to
execute on the worker could not be found.
Caused by:
Unrecognized function or variable ‘pth’.
Error using remoteParallelFunction (line 84)
Worker unable to find file.
Unrecognized function or variable ‘pth’.’
Anyone could please help me with what’s wrong? Thanks! batch, parfor, parallel computing, parallel MATLAB Answers — New Questions