An open source method of characteristics neutron transport code.
pairwise_sum.h
Go to the documentation of this file.
1 
18 template <typename T, typename L>
19 inline double pairwise_sum(T* vector, L length) {
20 
21  double sum = 0;
22 
23  /* Base case: if length is less than 16, perform summation */
24  if (length < 16) {
25 
26 #pragma omp simd reduction(+:sum)
27  for (L i=0; i < length; i++)
28  sum += vector[i];
29  }
30 
31  else {
32  L offset = length % 2;
33  length = floor(length / 2);
34  sum = pairwise_sum<T>(&vector[0], length) +
35  pairwise_sum<T>(&vector[length], length+offset);
36  }
37 
38  return sum;
39 }
double pairwise_sum(T *vector, L length)
Performs a pairwise sum of an array of numbers.
Definition: pairwise_sum.h:19