Is mat.h thread-safe?
显示 更早的评论
So here's the problem--I have a directory containing about 10,000 matlab files, and I need to read them all into matlab. The thing is, this directory is mounted over a network. These are small files, and the overall network nandwidth is pretty good. However, the latency is terrible--on the order of 300ms per file. I've tested it, and asynchronous file reading gets me a speed-up of 10x or more in reading files like these. The thing is, matlab dosn't support asynchronous file reads out of the box, for reasons we can only imagine.
So, I'm going to try writing it myself in mex. The matlab docs say that you can get threading to work in a mex file, but that you can't interact with matlab, since the mex interface isn't thread-safe:
However, the interface for file reading in c doesn't actually use mex.h, it uses mat.h:
Furthermore, the examples they provide don't actually show any interaction with matlab--instead they load a .mat file inside an ordinary C main() function. This suggests that I can spawn multiple threads and perform multiple asynchronous loads via the matGetVariable interface, and then collect them back into the main mex workspace at the end. However, I'm not sure whether these calls to matGetVariable are going to step on eachother. (I'm also not terribly familiar with pthreads; I know they CAN do stuff like this, but suggestions on how would be appreciated)
To save everyone time, I've already thought about copying the files to the local filesystem (e.g. via the unix() command) as well as using the matlab parallel toolbox. Neither of these are viable options for various reasons.
4 个评论
Walter Roberson
2013-2-3
Would it perhaps be viable to do something like
rsh SERVER -c '(produce a batch of file names) | cpio -oac | gzip -9 | ttcp -s -t CLIENT'
and on client,
ttcp -r -t | gunzip | cpio -idm
That is, bundle up a group of files into an archive, compress the archive, send it fast over the net, have the receiver unzip and unbundle
cpio (or even tar) are amazingly faster at creating bunches of files than ftp or rcp. I do not recall that I ever did a comparison test to scp -r though.
leptogenesis
2013-2-3
Jan
2013-2-3
I do not dare to post this as an answer, but it is at least an obvious and successful strategy: Do not store small data in 10'000 file, when you access them over a network with a high latency. Better use one or a few large MAT files instead.
leptogenesis
2013-2-5
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!