2 Replies Latest reply on Dec 12, 2011 1:19 PM by MicahVillmow

    What is the best way to sum the members of a vector

    doug65536

      I have a vector in my kernel, and I need to sum up all of its members.

      Is there a function or at least best way to sum it up? I am doing the following right now but I wondered if there was a better way that I am not finding in the builtin functions.


      float8 t = (float8)0;

      // ... code to get a bunch of results into the vector members ...

       

      // Horizontal add

      t.s0 += t.s1;

      t.s2 += t.s3;

      t.s4 += t.s5;

      t.s6 += t.s7;

      t.s0 += t.s2;

      t.s4 += t.s6;

      t.s0 += t.s4;



       

      Is there a better way to perform the "horizontal add" part?

      Thanks