assignment_threaded.cpp File Reference
#include "main.h"
#include <Eigen/ThreadPool>

Classes

struct  Eigen::internal::scalar_dummy_op< Scalar, Vectorize >
 
struct  Eigen::internal::functor_traits< scalar_dummy_op< Scalar, Vectorize > >
 

Namespaces

 Eigen
 Namespace containing all symbols from the Eigen library.
 
 Eigen::internal
 Namespace containing low-level routines from the Eigen library.
 

Macros

#define EIGEN_USE_THREADS   1
 

Functions

template<typename PlainObject >
void test_threaded_assignment (const PlainObject &, Index rows=PlainObject::RowsAtCompileTime, Index cols=PlainObject::ColsAtCompileTime)
 
 EIGEN_DECLARE_TEST (test)
 

Macro Definition Documentation

◆ EIGEN_USE_THREADS

#define EIGEN_USE_THREADS   1

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( test  )
79  {
80  for (int i = 0; i < g_repeat; i++) {
81  CALL_SUBTEST(test_threaded_assignment(MatrixXd(), 123, 123));
83  }
84 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
void test_threaded_assignment(const PlainObject &, Index rows=PlainObject::RowsAtCompileTime, Index cols=PlainObject::ColsAtCompileTime)
Definition: assignment_threaded.cpp:34
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
#define CALL_SUBTEST(FUNC)
Definition: main.h:382
static int g_repeat
Definition: main.h:191

References CALL_SUBTEST, Eigen::g_repeat, i, and test_threaded_assignment().

◆ test_threaded_assignment()

template<typename PlainObject >
void test_threaded_assignment ( const PlainObject &  ,
Index  rows = PlainObject::RowsAtCompileTime,
Index  cols = PlainObject::ColsAtCompileTime 
)
35  {
36  using Scalar = typename PlainObject::Scalar;
37  using VectorizationOff = internal::scalar_dummy_op<Scalar, false>;
38  using VectorizationOn = internal::scalar_dummy_op<Scalar, true>;
39 
40  int threads = 4;
41  ThreadPool pool(threads);
42  CoreThreadPoolDevice threadPoolDevice(pool);
43 
44  PlainObject dst(rows, cols), ref(rows, cols), rhs(rows, cols);
45  rhs.setRandom();
46  const auto rhs_xpr = rhs.cwiseAbs2();
47 
48  // linear access
49  dst.setRandom();
50  ref.setRandom();
51  ref = rhs_xpr.unaryExpr(VectorizationOff());
52  dst.device(threadPoolDevice) = rhs_xpr.unaryExpr(VectorizationOff());
53  VERIFY_IS_CWISE_EQUAL(ref, dst);
54 
55  ref = rhs_xpr.unaryExpr(VectorizationOn());
56  dst.device(threadPoolDevice) = rhs_xpr.unaryExpr(VectorizationOn());
57  VERIFY_IS_CWISE_EQUAL(ref, dst);
58 
59  // outer-inner access
60  Index blockRows = numext::maxi(Index(1), rows - 1);
61  Index blockCols = numext::maxi(Index(1), cols - 1);
62  dst.setRandom();
63  ref.setRandom();
64  ref.bottomRightCorner(blockRows, blockCols) =
65  rhs_xpr.bottomRightCorner(blockRows, blockCols).unaryExpr(VectorizationOff());
66  dst.bottomRightCorner(blockRows, blockCols).device(threadPoolDevice) =
67  rhs_xpr.bottomRightCorner(blockRows, blockCols).unaryExpr(VectorizationOff());
68  VERIFY_IS_CWISE_EQUAL(ref.bottomRightCorner(blockRows, blockCols), dst.bottomRightCorner(blockRows, blockCols));
69 
70  ref.setZero();
71  dst.setZero();
72  ref.bottomRightCorner(blockRows, blockCols) =
73  rhs_xpr.bottomRightCorner(blockRows, blockCols).unaryExpr(VectorizationOn());
74  dst.bottomRightCorner(blockRows, blockCols).device(threadPoolDevice) =
75  rhs_xpr.bottomRightCorner(blockRows, blockCols).unaryExpr(VectorizationOn());
76  VERIFY_IS_CWISE_EQUAL(ref.bottomRightCorner(blockRows, blockCols), dst.bottomRightCorner(blockRows, blockCols));
77 }
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
Definition: NonBlockingThreadPool.h:19
#define VERIFY_IS_CWISE_EQUAL(a, b)
Definition: main.h:375
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition: MathFunctions.h:926
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Definition: CoreThreadPoolDevice.h:42

References cols, Eigen::numext::maxi(), rows, and VERIFY_IS_CWISE_EQUAL.

Referenced by EIGEN_DECLARE_TEST().