CarpetLib's minval and maxval always return first element

Create issue
Issue #2493 resolved
Roland Haas created an issue

This code:

ivect tst;
for(int i = 0 ; i < 3 ; i++)
  tst[i] = 3-i;
std::cerr<<"tst: "<<tst<<" minval: "<<minval(tst)<<"\n";

outputs:

tst: [3,2,1] minval: 3

and as far as I an tell this is due to the DECLARE_REDUCTION_FUNCTION_1 macro used in

DECLARE_REDUCTION_FUNCTION_1(minval, a[0], min, ID)

which assumes that max behaves like *= i.e. accumulates. See vect_helpers.hh:

#define DECLARE_REDUCTION_FUNCTION_1(fn, init, op, final)                      \
  }                                                                            \
  namespace CarpetLib_vect {                                                   \
  template <typename T> inline void fn(T &r, const T &a) {                     \
    using namespace std;                                                       \
    using namespace CarpetLib;                                                 \
    op(r, a);                                                                  \
  }                                                                            \
  }                                                                            \
  namespace CarpetLib {                                                        \
  template <typename T, int D> inline T fn(const vect<T, D> &a) {              \
    T r(init);                                                                 \
    for (int d = 0; d < D; ++d)                                                \
      /* op(r, a[d]); */                                                       \
      CarpetLib_vect::fn(r, a[d]);                                             \
    return final(r);                                                           \
  }

and for just a plain ivect the operator op ends up being std::min.

Comments (5)

  1. Log in to comment