For simple algorithms, an accelerator just won’t win. Let’s use OpenMP to parallelize the processor loop. We include the header omp.h, and then apply an OpenMP pragma to the CPU code as in listing 3.19.
void vadd_sw(uint32_t* a, uint32_t *b, uint32_t* c, uint32_t size)
{
#pragma omp parallel for
for (inti = 0; i < size; i++) {
c[i] = a[i] + b[i];
}
}
And that’s it. There are some command line flags to pass to GCC, but CMake will take care of those (assuming you have OpenMP installed), so we can directly build and run. The code for this example is otherwise identical to the code from Example 5.