c++ - Need suggestion to keep arrays in L1 cache -


i have following question, can please me it:

i have following arrays of integers (size 1024) , trying find common elements present in arrays (along position @ common element found):

array1: 15, 89, 100, 167, 202, ... array2: 16, 89, 109, 178,179, 202, ... array3: 15, 89, 100, 178, 189, 202, ... array4: 17, 89, 109, 167, 178, 202, ... array5: 7,   89, 100, 178, 179, 180, 202, ... 

now common elements along position in respective arrays are:

array1: 89(2), 202(5), ... array2: 89(2), 202(6), ... array3: 89(2), 202(6), ... array4: 89(2), 202(6), ... array5: 89(2), 202(7), ... 

is possible keep these arrays in l1 cache while arrays getting intersected. have written simple c++ code pushes common element , position std::pair std::vector. code correct keep elements in l1 cache or should modify code...if yes, please suggest.

your data stay in cache long processor has need or processor needs put other data cache.

my best advice keep data close , perform data accessing together. example: input data, process data, output data. worse case is: input data, process data, output data, repeat data.

you may want use arrays instead of vectors, because vectors dynamically allocate memory , may allocate @ different times. if size of arrays doesn't change, go arrays.

edit 1:
here links describing cache optimizations:
cpu cache optimization
effective cache memory usage

the first link has diagrams explaining how cache works.

you should search "data cache optimization". here more links:
keeping arrays in l1 cache
low level c language optimizations
data locality
eetimes - optimizing cache performance


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -