o**n 发帖数: 1249 | 1 最近用matlab遇到了一个问题,代码简化为
for j=1:N
...
func1(...);
func2(...);
...
end
因为func1要计算出一个很大很多的数据给func2用,我在func1中把数据写到一个上百
MB的文件(hdf5write),然后func2中会读这个文件,再进行计算。
结果我发现这个for循环中会有个别的func2的结果是错的,而且我运行这个代码几次,
每次出错的位置(j)不一样,是随机的。
我猜想是不是matlab读写文件的时候又开了一个线程,由于文件太大,所以有了同步问
题,比如某此循环中,func2算的时候func1写的数据还没有完成。可按理说matlab是
Sequence的语言,不应该有这个问题阿,请大家提点。 | r****y 发帖数: 1437 | 2 The filename of your hdf5write to is one fixed filename for all loops,
or the name is different for different j?
I suspect it is the former. If so, just make filename distinctive for each
loop, e.g. fname = [' ', int2str(j), '.hdf']
Another possibility is that file is not closed correctly after you write it.
If it is a temp file, why use hdf5write, just write as mat format?
【在 o**n 的大作中提到】 : 最近用matlab遇到了一个问题,代码简化为 : for j=1:N : ... : func1(...); : func2(...); : ... : end : 因为func1要计算出一个很大很多的数据给func2用,我在func1中把数据写到一个上百 : MB的文件(hdf5write),然后func2中会读这个文件,再进行计算。 : 结果我发现这个for循环中会有个别的func2的结果是错的,而且我运行这个代码几次,
| o**n 发帖数: 1249 | 3 I do use the same filename, though it will be overwritten by the next loop.
II didn't use distinct names coz I don't want to leave too much temp data.
But I'll try what you suggest. Thank you!
it.
【在 r****y 的大作中提到】 : The filename of your hdf5write to is one fixed filename for all loops, : or the name is different for different j? : I suspect it is the former. If so, just make filename distinctive for each : loop, e.g. fname = [' ', int2str(j), '.hdf'] : Another possibility is that file is not closed correctly after you write it. : If it is a temp file, why use hdf5write, just write as mat format?
| o**n 发帖数: 1249 | 4 btw, the reason I'm using hdf5 instead mat is because hdf5 can handle
multiple levels of data such as my data structure: /Data001/X,Y,Z,.. /
Data002/X,Y,Z.. (X, Y, Z are some matrix). You've got to use structure in
this case for mat data, but I think structure is not efficient in terms of
both time and space consumption.
it.
【在 r****y 的大作中提到】 : The filename of your hdf5write to is one fixed filename for all loops, : or the name is different for different j? : I suspect it is the former. If so, just make filename distinctive for each : loop, e.g. fname = [' ', int2str(j), '.hdf'] : Another possibility is that file is not closed correctly after you write it. : If it is a temp file, why use hdf5write, just write as mat format?
|
|