Parallel execution of external application with different parameters
显示 更早的评论
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 个评论
Jan
2011-10-1
How do you determine the core that's running the functions?
回答(2 个)
Jan
2011-10-1
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.
Edric Ellis
2011-10-3
0 个投票
I would use the TEMPNAME function, as recent versions of MATLAB generate names that are highly unlikely to clash.
类别
在 帮助中心 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!