English 中文(简体)
序号与增值数据的不同性能
原标题:Caching performance of serial vs padded data
  • 时间:2010-09-01 10:39:53
  •  标签:
  • c
  • caching

I got some objects with certain values, for example: (1)

struct massPoint {
    double pos;
    double vel;
    double acc;
} objects[LOTS];

或相同阵列:

(2)

double pos[LOTS];
double vel[LOTS];
double acc[LOTS];

第一问题: (1) 附加数据和(2) 序列数据是否正确?

第二个问题: 如果某些行动只影响生育和蓄水池,而且没有生物蓄水池,而且有有机水池,那么(2) 就会更好,因为在打断性能方面做得更好,因为胎盘必须用这种方式,而且(1) 必须用这种方式? 或者根本看不到这一概念?

最佳回答

您的第一个问题没有想法

对于您的第二个问题,没有一般性的答案,这取决于你的架构和使用模式。

  • if you really have random (= unpredictable) access and each double makes up a cacheline and your data is correctly aligned both would be equivalent in terms of caching.
  • your second method is clearly superior on modern architectures if you have streaming access to the data, that is for which the compiler / runtime / hardware can easily predict the future access and that have enough hardware registers for the all the pointers and the data
  • your first method could be superior in cases you have only few registers, since for the second the compiler might need to keep track of your current index in the three different arrays

简言之,它可能取决于许多因素,但一种趋势是,在许多情况下,第二种方法比较可取。

问题回答

如果您在just职位上开展工作,则justvelocities,或justReviews,那么(2)就更好了。

在其他情况下,如果你在计算中使用了不止一种类型,则(1)会更好。

假设:

  • the total size of each set is too big to fit in local cache (probable).
  • you re not doing complicated calculations that require other external data anyway.
  • the operations you re performing aren t convertible to vector operations.

虽然坦率地说,这种声音,如过早选择,最好用valgrind,这可以告诉你平台的确切答案。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签