Element-wise vector-vector multiplication in BLAS?

前端 未结 4 940
孤独总比滥情好
孤独总比滥情好 2020-12-29 10:53

Is there a means to do element-wise vector-vector multiplication with BLAS, GSL or any other high performance library ?

4条回答
  •  Happy的楠姐
    2020-12-29 11:36

    There is always std::valarray1 which defines elementwise operations that are frequently (Intel C++ /Quse-intel-optimized-headers, G++) compiled into SIMD instructions if the target supports them.

    • http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/cpp/mac/cref_cls/common/cppref_valarray_intro.htm

    Both these compilers will also do auto-vectorization

    • http://software.intel.com/en-us/articles/getting-code-ready-for-parallel-execution-with-intel-parallel-composer/
    • http://gcc.gnu.org/projects/tree-ssa/vectorization.html

    In that case you can just write

    #define N 10000 
    
    float a[N], b[N], c[N]; 
    
    void f1() { 
      for (int i = 1; i < N; i++) 
      c[i] = a[i] + b[i]; 
    } 
    

    and see it compile into vectorized code (using SSE4 e.g.)

    1 Yes they are archaic and often thought of as obsolete, but in practice they are both standard and fit the task very well.

提交回复
热议问题