Quantcast
Channel: Why are elementwise additions much faster in separate loops than in a combined loop? - Stack Overflow
Browsing all 12 articles
Browse latest View live

Answer by mathengineer for Why are elementwise additions much faster in...

It may be old C++ and optimizations. On my computer I obtained almost the same speed: One loop: 1.577 ms Two loops: 1.507 ms I run Visual Studio 2015 on an E5-1620 3.5 GHz processor with 16 GB RAM.

View Article



Answer by Francis Cugler for Why are elementwise additions much faster in...

The Original Question Why is one loop so much slower than two loops? Conclusion: Case 1 is a classic interpolation problem that happens to be an inefficient one. I also think that this was one of the...

View Article

Answer by user1899861 for Why are elementwise additions much faster in...

I cannot replicate the results discussed here. I don't know if poor benchmark code is to blame, or what, but the two methods are within 10% of each other on my machine using the following code, and one...

View Article

Answer by Guillaume Kiz for Why are elementwise additions much faster in...

The first loop alternates writing in each variable. The second and third ones only make small jumps of element size. Try writing two parallel lines of 20 crosses with a pen and paper separated by 20...

View Article

Answer by OldCurmudgeon for Why are elementwise additions much faster in...

Imagine you are working on a machine where n was just the right value for it only to be possible to hold two of your arrays in memory at one time, but the total memory available, via disk caching, was...

View Article


Image may be NSFW.
Clik here to view.

Answer by Johannes Gerer for Why are elementwise additions much faster in...

OK, the right answer definitely has to do something with the CPU cache. But to use the cache argument can be quite difficult, especially without data. There are many answers, that led to a lot of...

View Article

Image may be NSFW.
Clik here to view.

Answer by Mysticial for Why are elementwise additions much faster in separate...

Upon further analysis of this, I believe this is (at least partially) caused by data alignment of the four pointers. This will cause some level of cache bank/way conflicts. If I've guessed correctly on...

View Article

Answer by James for Why are elementwise additions much faster in separate...

It's because the CPU doesn't have so many cache misses (where it has to wait for the array data to come from the RAM chips). It would be interesting for you to adjust the size of the arrays continually...

View Article


Answer by Emilio Garavaglia for Why are elementwise additions much faster in...

It's not because of a different code, but because of caching: RAM is slower than the CPU registers and a cache memory is inside the CPU to avoid to write the RAM every time a variable is changing. But...

View Article


Answer by Puppy for Why are elementwise additions much faster in separate...

The second loop involves a lot less cache activity, so it's easier for the processor to keep up with the memory demands.

View Article

Image may be NSFW.
Clik here to view.

Why are elementwise additions much faster in separate loops than in a...

Suppose a1, b1, c1, and d1 point to heap memory and my numerical code has the following core loop. const int n = 100000; for (int j = 0; j < n; j++) { a1[j] += b1[j]; c1[j] += d1[j]; } This loop is...

View Article

Answer by gnasher729 for Why are elementwise additions much faster in...

To make this code run fast, the CPU will need to do cache prefetching. Basically the CPU learns that you are accessing sequential data, and reads data from RAM before it is actually needed.The double...

View Article
Browsing all 12 articles
Browse latest View live




Latest Images