Introduction
An introduction to a problem of calculating the sum of a vector, and how to solve it through various methods in C++.
We'll cover the following
After providing the theory on the memory model and the multithreading interface, I will now apply the theory in practice and provide you a few performance numbers.
Calculating the Sum of a Vector
What is the fastest way to add the elements of a std::vector
? To get the answer, I will fill a std::vector
with one hundred million arbitrary but uniformly distributed numbers
between 1 and 10. The task is to calculate the sum of the numbers in various ways; I use the performance of a single threaded addition as the reference execution time. In this chapter, I will also discuss atomics, locks, thread local data, and tasks.
Let’s start with the single-threaded scenario in the next lesson.
Get hands-on with 1400+ tech skills courses.