C++ cache aware programming

后端 未结 10 1492
离开以前
离开以前 2020-12-07 10:53

is there a way in C++ to determine the CPU\'s cache size? i have an algorithm that processes a lot of data and i\'d like to break this data down into chunks such that they f

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 11:43

    Interestingly enough, I wrote a program to do this awhile ago (in C though, but I'm sure it will be easy to incorporate in C++ code).

    http://github.com/wowus/CacheLineDetection/blob/master/Cache%20Line%20Detection/cache.c

    The get_cache_line function is the interesting one, which returns the location of right before the biggest spike in timing data of array accesses. It correctly guessed on my machine! If anything else, it can help you make your own.

    It's based off of this article, which originally piqued my interest: http://igoro.com/archive/gallery-of-processor-cache-effects/

提交回复
热议问题