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

Windows: atomic_fetch_sub() #88

Closed
danturner opened this issue Sep 21, 2015 · 2 comments
Closed

Windows: atomic_fetch_sub() #88

danturner opened this issue Sep 21, 2015 · 2 comments
Assignees
Labels
Bug Broken / incorrect code; it could be Kokkos' responsibility, or others’ (e.g., Trilinos)

Comments

@danturner
Copy link

There’s no implementation of atomic_fetch_sub() in Kokkos_Atomic_Windows.hpp.

@danturner
Copy link
Author

Here's the implementation that I used in my local repo:

template < typename T >
KOKKOS_INLINE_FUNCTION
T atomic_fetch_sub(volatile T * const dest,
typename Kokkos::Impl::enable_if< sizeof(T) == sizeof(long), const T >::type val)
{
union { long i; T t; } assume, oldval, newval;

  oldval.t = *dest;

  do {
      assume.i = oldval.i;
      newval.t = assume.t - val;
      oldval.i = _InterlockedCompareExchange((long*)dest, newval.i, assume.i);
  } while (assume.i != oldval.i);

  return oldval.t;

}

crtrott added a commit that referenced this issue Sep 22, 2015
@crtrott crtrott added bug - fix pushed for public testing Bug Broken / incorrect code; it could be Kokkos' responsibility, or others’ (e.g., Trilinos) labels Sep 22, 2015
hcedwar pushed a commit to hcedwar/kokkos that referenced this issue Oct 7, 2015
@crtrott
Copy link
Member

crtrott commented Oct 28, 2015

Pushed to master

@crtrott crtrott closed this as completed Oct 28, 2015
@crtrott crtrott self-assigned this Sep 20, 2016
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