How to get username in Parallel Computing
Show older comments
I'm using MatLab Parallel Computing Toolbox on several computers in my office: I've enstabilished a cluster managed by a custom scheduler (the MatLab's own kind: the MJS).
Everything seems to run smoothly as long as I run scripts and functions that have the same path on every PC (e.g. C:\Sample.m), but unfortunately I need to access to functions that are in the Dropbox folder of every computer (for example the file C:\Users\myusername\Dropbox\Sample.m).
To solve the problem, I tried something like this:
parfor j=1:100
myusername=getenv('username');
cd(['C:\Users\',myusername,'\Dropbox'])
Sample(1,2,3);
end
But with this code the "cd" function set the current folder in C:\Users\SYSTEM\Dropbox and obviously it can't find Sample.m in it.
Has anybody any way around this problem?
Accepted Answer
More Answers (1)
Edric Ellis
on 8 Jul 2015
You have several options here. First, you could simply compute your username outside the parfor loop
myusername = getenv('username');
parfor ...
...
cd(['c:\Users\', myusername, '\Dropbox']);
...
end
If you're running a more recent version of MATLAB, then there is automatic dependency analysis that should transfer the functions that you need to the workers when required - which version are you using? You can use listAutoAttachedFiles to see what files have been attached to your pool.
Finally, if you get your MJS administrator to run at security level 3, then the workers will run with your credentials, and getenv('username') will behave as you expect on the workers.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!