June 2017
Intermediate to advanced
532 pages
12h 59m
English
Vectorization is a feature that both the CPU and the compiler need to support. Let's have a quick glance at a simple example to briefly understand what vectorization is and how it works. Imagine we want to sum up numbers from a very large vector. A plain implementation of this task can look like this:
std::vector<int> v {1, 2, 3, 4, 5, 6, 7 /*...*/};int sum {std::accumulate(v.begin(), v.end(), 0)};
The compiler will eventually generate a loop from the accumulate call, which could look like this:
int sum {0};for (size_t i {0}; i < v.size(); ++i) { sum += v[i];}
Proceeding from this point, with vectorization allowed and enabled, the compiler could then produce the following code. The loop does four accumulation ...
Read now
Unlock full access