Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Parallel Computing and "The process cannot access the file because it is being used by another process."
Replies: 1   Last Post: Mar 28, 2013 4:26 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Edric Ellis

Posts: 695
Registered: 12/7/04
Re: Parallel Computing and "The process cannot access the file because it is being used by another process."
Posted: Mar 28, 2013 4:26 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Syed " <irtezaa@gatech.edu> writes:

> while using parfor loop, I get "The process cannot access the file
> because it is being used by another process." error generated from an
> executable function embedded in the parfor loop. The function opens a
> file "tmp.key" and writes an image file "tmp.pgm" into "tmp.key"
> file. However, it seems that when this parfor loop runs on parallel
> processors, the processors are unable to access this "tmp.key" at the
> same time, and hence, the error is generated. First of all, is my
> assesment correct? secondly, how to resolve this issue and use parfor
> loop successfully.
>
> Any help is greatly appreciated, please.


It sounds like your assessment is correct. By default, we keep
matlabpool workers having the same current directory as your MATLAB
client, but it sounds like you need to override this when calling your
executable. I'd proceed by making a wrapper function around the
executable which does something like this:

%---8<---8<---8<---8<---8<---
function result = wrapCallToExecutable(args)
t = getCurrentTask(); % empty on the client
if ~isempty(t)
% Get a unique directory name and create that
uniqueDirName = tempname();
ok = mkdir(uniqueDirName);
assert(ok);

% remember the old working directory, and use onCleanup
% to get back there
oldPwd = pwd;
restorePwd = onCleanup(@() cd(oldPwd));

% make an onCleanup to remove the temporary directory
removeTempDir = onCleanup(@() rmdir(uniqueDirName, 's'));
% move to the unique directory
cd(uniqueDirName);
end

% call executable
system(sprintf('exeName.exe %s', args));

% do stuff, fill out 'result'.

end
%---8<---8<---8<---8<---8<---

Cheers,

Edric.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.