YAKL
YAKL_intrinsics_minval.h
Go to the documentation of this file.
1 
2 #pragma once
3 // Included by YAKL_intrinsics.h
4 
6 namespace yakl {
7  namespace intrinsics {
8 
9  template <class T, int rank, int myStyle>
10  inline T minval( Array<T,rank,memHost,myStyle> const &arr ) {
11  #ifdef YAKL_DEBUG
12  if (!arr.initialized()) { yakl_throw("ERROR: calling minval on an array that has not been initialized"); }
13  #endif
14  typename std::remove_cv<T>::type m = arr.data()[0];
15  for (int i=1; i<arr.totElems(); i++) {
16  if (arr.data()[i] < m) { m = arr.data()[i]; }
17  }
18  return m;
19  }
20 
21  template <class T, int rank, int myStyle>
22  inline T minval( Array<T,rank,memDevice,myStyle> const &arr , Stream stream = Stream() ) {
23  #ifdef YAKL_DEBUG
24  if (!arr.initialized()) { yakl_throw("ERROR: calling minval on an array that has not been initialized"); }
25  #endif
26  typedef typename std::remove_cv<T>::type TNC; // T Non-Const
27  ParallelMin<TNC,memDevice> pmin(arr.totElems(),stream);
28  return pmin( const_cast<TNC *>(arr.data()) );
29  }
30 
31  template <class T, int rank, class D0, class D1, class D2, class D3>
33  typename std::remove_cv<T>::type m = arr.data()[0];
34  for (int i=1; i<arr.totElems(); i++) {
35  if (arr.data()[i] < m) { m = arr.data()[i]; }
36  }
37  return m;
38  }
39 
40  template <class T, int rank, unsigned D0, unsigned D1, unsigned D2, unsigned D3>
42  typename std::remove_cv<T>::type m = arr.data()[0];
43  for (int i=1; i<arr.totElems(); i++) {
44  if (arr.data()[i] < m) { m = arr.data()[i]; }
45  }
46  return m;
47  }
48 
49  }
50 }
52 
yakl::FSArray::totElems
static constexpr unsigned totElems()
Get the total number of array elements.
Definition: YAKL_FSArray.h:179
yakl::Stream
Implements the functionality of a stream for parallel kernel execution. If the Stream::create() metho...
Definition: YAKL_streams_events.h:394
__YAKL_NAMESPACE_WRAPPER_END__
#define __YAKL_NAMESPACE_WRAPPER_END__
Definition: YAKL.h:20
yakl::intrinsics::minval
T minval(Array< T, rank, memHost, myStyle > const &arr)
Definition: YAKL_intrinsics_minval.h:10
__YAKL_NAMESPACE_WRAPPER_BEGIN__
#define __YAKL_NAMESPACE_WRAPPER_BEGIN__
Definition: YAKL.h:19
YAKL_INLINE
#define YAKL_INLINE
Used to decorate functions called from kernels (parallel_for and parallel_outer) or from CPU function...
Definition: YAKL_defines.h:140
yakl::yakl_throw
YAKL_INLINE void yakl_throw(const char *msg)
Throw an error message. Works from the host or device.
Definition: YAKL_error.h:17
yakl::Array
This declares the yakl::Array class. Please see the yakl::styleC and yakl::styleFortran template spec...
Definition: YAKL_Array.h:40
yakl::CSArray
C-style array on the stack similar in nature to, e.g., float arr[ny][nx];
Definition: YAKL_CSArray.h:30
yakl
yakl::CSArray::totElems
static constexpr unsigned totElems()
Get the total number of array elements.
Definition: YAKL_CSArray.h:131
yakl::CSArray::data
YAKL_INLINE T * data() const
Get the underlying raw data pointer.
Definition: YAKL_CSArray.h:123
yakl::FSArray::data
YAKL_INLINE T * data() const
Get the underlying raw data pointer.
Definition: YAKL_FSArray.h:171
yakl::FSArray
Fortran-style array on the stack similar in nature to, e.g., float arr[ny][nx];
Definition: YAKL_FSArray.h:53