在FORTRAN中用新列扩展密集矩阵的最有效方法是什么?
说T是一个密集的矩阵m乘n ,我想用n + 1。 我能想到的一个策略:在每一步重新分配并分配最后一列,或者是否会有一些更好的方法,比如先分配一些空间并检查是否足够,如果不是这样的重新分配类型的东西?任何想法?
解决方案假设 m 和在某些意义上,n 不会太大,这样你的矩阵就可以适应内存,而你所追求的是时间表现,我会做什么我会分配一个大的矩阵并存储实际的大小分开。例如,这就是BLAS库用作主要维度的原因。然后,当您需要添加列时,请检查您的实际大小是否仍小于最大大小,并在必要时重新分配内存。
What would be the most efficient way to expand a dense matrix with new columns in FORTRAN?
Say T is a dense matrix m by n
and I would like to make it m by n+1. One strategy I could think of : Reallocate at each step and assign the last column or would there be some better ways, such as allocating some space before and checking if that is sufficient and if not do the reallocation kind of stuff? Any ideas?
解决方案Assuming m and n are in some sense not exceedingly large, so that your matrices fit into memory and what you're after is performance in time, what I'd do I'd allocate a large matrix and store the actual size separately. This is what, for example, BLAS libraries use as a 'leading dimension'. Then, when you need to add a column, you check if your actual size is still smaller than the maximum size, and reallocate memory if necessary.
更多推荐
展开一个密集的矩阵
发布评论