boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Mathematics版 - matlab在循环中读写大文件的问题
相关主题
Ordering a sequence (2)
这儿有用Mathematica的吗?
probability
sampling problem
问一个简单的问题关于循环卷积。
请教一个复数问题
来一道题
考考大师们一道小学题目
问一个排列组合问题
请帮我解答这个题吧
相关话题的讨论汇总
话题: func2话题: filename话题: func1话题: hdf5write话题: matlab
进入Mathematics版参与讨论
1 (共1页)
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?

1 (共1页)
进入Mathematics版参与讨论
相关主题
请帮我解答这个题吧
杨振宁在数学上有什么重要贡献?
哪位高手指点一下projection的具体含义?
How to prove the statement of following?
cauchy sequence
概率体一问
Fibonacci Sequence 和golden ratio的关系?
问一个优化问题
help on orthogonal sequence generator
图的degree sequence的一个问题
相关话题的讨论汇总
话题: func2话题: filename话题: func1话题: hdf5write话题: matlab