| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Stokhos Package |
| 4 |
// |
| 5 |
// Copyright 2009 NTESS and the Stokhos contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef KOKKOS_ATOMIC_MP_VECTOR_HPP |
| 11 |
#define KOKKOS_ATOMIC_MP_VECTOR_HPP |
| 12 |
|
| 13 |
#include "Sacado_MP_Vector.hpp" |
| 14 |
#include "Kokkos_Core.hpp" |
| 15 |
|
| 16 |
//---------------------------------------------------------------------------- |
| 17 |
// Overloads of Kokkos atomic functions for Sacado::MP::Vector scalar type |
| 18 |
//---------------------------------------------------------------------------- |
| 19 |
|
| 20 |
namespace Kokkos { |
| 21 |
|
| 22 |
template <typename Storage> |
| 23 |
KOKKOS_INLINE_FUNCTION |
| 24 |
void |
| 25 |
atomic_assign(volatile Sacado::MP::Vector<Storage>* const dest, |
| 26 |
const Sacado::MP::Vector<Storage>& src ) |
| 27 |
{ |
| 28 |
typedef typename Storage::ordinal_type ordinal_type; |
| 29 |
typedef typename Storage::volatile_pointer pointer; |
| 30 |
pointer dest_c = dest->coeff(); |
| 31 |
const ordinal_type sz = dest->size(); |
| 32 |
if (src.hasFastAccess(sz)) |
| 33 |
for (ordinal_type i=0; i<sz; ++i) |
| 34 |
atomic_exchange(dest_c+i, src.fastAccessCoeff(i)); |
| 35 |
else |
| 36 |
for (ordinal_type i=0; i<sz; ++i) |
| 37 |
atomic_exchange(dest_c+i, src.coeff(i)); |
| 38 |
} |
| 39 |
|
| 40 |
template <typename Storage> |
| 41 |
KOKKOS_INLINE_FUNCTION |
| 42 |
void |
| 43 |
atomic_add(volatile Sacado::MP::Vector<Storage>* const dest, |
| 44 |
const Sacado::MP::Vector<Storage>& src) |
| 45 |
{ |
| 46 |
typedef typename Storage::ordinal_type ordinal_type; |
| 47 |
typedef typename Storage::volatile_pointer pointer; |
| 48 |
pointer dest_c = dest->coeff(); |
| 49 |
const ordinal_type sz = dest->size(); |
| 50 |
if (src.hasFastAccess(sz)) |
| 51 |
for (ordinal_type i=0; i<sz; ++i) |
| 52 |
atomic_add(dest_c+i, src.fastAccessCoeff(i)); |
| 53 |
else |
| 54 |
for (ordinal_type i=0; i<sz; ++i) |
| 55 |
atomic_add(dest_c+i, src.coeff(i)); |
| 56 |
} |
| 57 |
|
| 58 |
} // namespace Kokkos |
| 59 |
|
| 60 |
//---------------------------------------------------------------------------- |
| 61 |
//---------------------------------------------------------------------------- |
| 62 |
|
| 63 |
#endif /* #ifndef KOKKOS_ATOMIC_MP_VECTOR_HPP */ |