cs205-lecture-examples

Example codes used during Harvard CS205 lectures
git clone https://git.0xfab.ch/cs205-lecture-examples.git
Log | Files | Refs | README | LICENSE

f.c (382B)


      1 // #define RESTRICT
      2 // #define IVDEP
      3 
      4 #ifdef RESTRICT
      5 void f(float *__restrict__ dst, float *__restrict__ src, float a)
      6 #else
      7 void f(float *dst, float *src, float a)
      8 #endif /* RESTRICT */
      9 {
     10 #ifdef IVDEP
     11 #pragma GCC ivdep
     12 #else
     13 #ifdef _OPENMP
     14 #pragma omp simd
     15 #endif /* _OPENMP */
     16 #endif /* IVDEP */
     17     for (int i = 0; i < 1024; ++i) {
     18         dst[i] = dst[i] + a * src[i];
     19     }
     20 }