Parallel execution of external application with different parameters
3 views (last 30 days)
Show older comments
Im trying to run an optimization were for each iteration an external simulation program is run from within MATLAB. I basically communicate with the external program through ascii files (to send parameters to the application and to later read the results back).
If I try to run it parallel just as it is, I would get some race conditions because of the usage of the same filename. How could I retrieve a unique ID based on the core thats runing the fitting functions?
1 Comment
Answers (2)
Jan
on 1 Oct 2011
If all files are created by the same Matlab session, you can create unique IDs based on the current time:
function ID = TimeID
S = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
D = T(4) * 360000 + T(5) * 6000 + T(6) * 100; % 100th of a second
ID = S(1 + rem(fix([D / 250047, D / 3969, D / 63, D]), 63));
pause(0.01); % Optional
The IDs have 4 characters which are allowed in file names, e.g.: 'Z_Hs'. They are unique inside a single Matlab session and inside an interval of 24 hours.
If you create more than 100 IDs per second, the PAUSE command cares for uniqueness. The IDs can be non-unique, if the function runs more than 24 hours.
Do not use the 1000th of seconds under Matlab. There is a strong correlation between the values in subsequent calls of CLOCK, even if a random pause is inserted between the calls.
This method does not take the core into account, but perhaps you can add this feature.
0 Comments
Edric Ellis
on 3 Oct 2011
I would use the TEMPNAME function, as recent versions of MATLAB generate names that are highly unlikely to clash.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!