Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinMax Reducer with tagged operator doesn't compile #1251

Closed
crtrott opened this issue Dec 4, 2017 · 5 comments
Closed

MinMax Reducer with tagged operator doesn't compile #1251

crtrott opened this issue Dec 4, 2017 · 5 comments
Assignees
Labels
Bug Broken / incorrect code; it could be Kokkos' responsibility, or others’ (e.g., Trilinos)
Milestone

Comments

@crtrott
Copy link
Member

crtrott commented Dec 4, 2017

Reproducer:

#include<Kokkos_Core.hpp>

struct TagMin {};

typedef Kokkos::Experimental::MinMax<double>::value_type value_type;

struct functor {
  Kokkos::View<double*> a;

  functor(Kokkos::View<double*> a_):a(a_) {}

  KOKKOS_INLINE_FUNCTION
  void operator() (const TagMin, const int& i, value_type& val) const {
    if(a(i) < val.min_val) val.min_val = a(i);
    if(a(i) > val.max_val) val.max_val = a(i);
  }
};

int main(int argc, char* argv[]) {
  Kokkos::initialize(argc,argv);

  Kokkos::View<double*> a("A", 100);
  Kokkos::deep_copy(a,5.0);
  a(5) = 3.0;
  a(7) = 6.0;

  value_type result;
  Kokkos::parallel_reduce(Kokkos::RangePolicy<TagMin>(0,100), functor(a), Kokkos::Experimental::MinMax<double>(result));

  printf("Result: %lf %lf\n",result.min_val,result.max_val);

  Kokkos::finalize();
}

Error message:

g++ -I./ -I/home/crtrott/Kokkos/kokkos/core/src -I/home/crtrott/Kokkos/kokkos/containers/src -I/home/crtrott/Kokkos/kokkos/algorithms/src  --std=c++11 -mavx -fopenmp -O3 -g  -c main.cpp
In file included from /home/crtrott/Kokkos/kokkos/core/src/Kokkos_Parallel.hpp:63:0,
                 from /home/crtrott/Kokkos/kokkos/core/src/Kokkos_OpenMP.hpp:61,
                 from /home/crtrott/Kokkos/kokkos/core/src/Kokkos_Core.hpp:57,
                 from main.cpp:1:
/home/crtrott/Kokkos/kokkos/core/src/impl/Kokkos_FunctorAdapter.hpp: In instantiation of ‘static void Kokkos::Impl::FunctorValueJoin<FunctorType, ArgTag, T&, Enable>::join(const FunctorType&, volatile void*, const volatile void*) [with FunctorType = Kokkos::Experimental::MinMax<double>; ArgTag = TagMin; T = Kokkos::Experimental::MinMaxScalar<double>; Enable = void]’:
/home/crtrott/Kokkos/kokkos/core/src/OpenMP/Kokkos_OpenMP_Parallel.hpp:391:24:   required from ‘void Kokkos::Impl::ParallelReduce<FunctorType, Kokkos::RangePolicy<Traits ...>, ReducerType, Kokkos::OpenMP>::execute() const [with FunctorType = functor; ReducerType = Kokkos::Experimental::MinMax<double>; Traits = {TagMin}]’
/home/crtrott/Kokkos/kokkos/core/src/Kokkos_Parallel_Reduce.hpp:895:11:   required from ‘static void Kokkos::Impl::ParallelReduceAdaptor<PolicyType, FunctorType, ReturnType>::execute(const string&, const PolicyType&, const FunctorType&, ReturnType&) [with PolicyType = Kokkos::RangePolicy<TagMin>; FunctorType = functor; ReturnType = Kokkos::Experimental::MinMax<double>; std::__cxx11::string = std::__cxx11::basic_string<char>]’
/home/crtrott/Kokkos/kokkos/core/src/Kokkos_Parallel_Reduce.hpp:1258:74:   required from ‘void Kokkos::parallel_reduce(const PolicyType&, const FunctorType&, const ReturnType&, typename Kokkos::Impl::enable_if<Kokkos::is_execution_policy<PolicyType>::value>::type*) [with PolicyType = Kokkos::RangePolicy<TagMin>; FunctorType = functor; ReturnType = Kokkos::Experimental::MinMax<double>; typename Kokkos::Impl::enable_if<Kokkos::is_execution_policy<PolicyType>::value>::type = void]’
main.cpp:28:119:   required from here
/home/crtrott/Kokkos/kokkos/core/src/impl/Kokkos_FunctorAdapter.hpp:641:27: error: no match for ‘operator+=’ (operand types are ‘volatile Kokkos::Experimental::MinMaxScalar<double>’ and ‘const volatile Kokkos::Experimental::MinMaxScalar<double>’)
       *((volatile T*)lhs) += *((const volatile T*)rhs);
                           ^
make: *** [main.o] Error 1

Works after taking away tag.

@crtrott crtrott self-assigned this Dec 4, 2017
@crtrott crtrott added Blocks Promotion Overview issue for release-blocking bugs Bug Broken / incorrect code; it could be Kokkos' responsibility, or others’ (e.g., Trilinos) labels Dec 4, 2017
@tjfulle
Copy link

tjfulle commented Dec 5, 2017

@crtrott, on my laptop using gcc 6.4 and clang 4.0, and the current version of Kokkos snapshot in to Trilinos, the reproducer compiles and runs, but I get an error in the answer as described in #1250.

@tjfulle
Copy link

tjfulle commented Dec 5, 2017

To add to my previous comment, when I made the reproducer, I used the installed version of Kokkos in Trilinos and the Trilinos makefile to define compiler/compiler flags. In the failing sparta builds, I believe sparta is using the Kokkos makefile directly. Not sure that extra info helps?

@crtrott
Copy link
Member Author

crtrott commented Dec 5, 2017

Did you compile for OpenMP in your Trilinos version? This particular bug seems to be restricted to OpenMP. The "Incorrect Answer" bug actually effects every backend including Serial. If I were just to fix the compilation issue, this reproducer would run into the other bug and give the wrong answer.

@tjfulle
Copy link

tjfulle commented Dec 5, 2017

I’ll check that. I just used the default execution space in Kokkos. I thought I used OpenMP, but maybe not?

@crtrott
Copy link
Member Author

crtrott commented Dec 5, 2017

No it is not. Only if you enable OpenMP globally for Trilinos. I also have added a unit test which catches this issues.

crtrott added a commit that referenced this issue Dec 5, 2017
crtrott added a commit that referenced this issue Dec 5, 2017
@crtrott crtrott added this to the 2017 December milestone Dec 5, 2017
@crtrott crtrott removed the Blocks Promotion Overview issue for release-blocking bugs label Dec 5, 2017
@crtrott crtrott closed this as completed Dec 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Broken / incorrect code; it could be Kokkos' responsibility, or others’ (e.g., Trilinos)
Projects
None yet
Development

No branches or pull requests

2 participants