35 #ifndef _BLAZE_MATH_SMP_HPX_DENSEVECTOR_H_ 36 #define _BLAZE_MATH_SMP_HPX_DENSEVECTOR_H_ 43 #include <hpx/include/parallel_for_loop.hpp> 94 template<
typename VT1
99 void hpxAssign( DenseVector<VT1,TF1>& lhs,
const DenseVector<VT2,TF2>& rhs, OP op )
101 using hpx::parallel::for_loop;
102 using hpx::parallel::execution::par;
106 using ET1 = ElementType_t<VT1>;
107 using ET2 = ElementType_t<VT2>;
109 constexpr
bool simdEnabled( VT1::simdEnabled && VT2::simdEnabled && IsSIMDCombinable_v<ET1,ET2> );
110 constexpr
size_t SIMDSIZE( SIMDTrait< ElementType_t<VT1> >::
size );
112 const bool lhsAligned( (~lhs).isAligned() );
113 const bool rhsAligned( (~rhs).isAligned() );
116 const size_t addon ( ( ( (~lhs).
size() % threads ) != 0UL )? 1UL : 0UL );
117 const size_t equalShare ( (~lhs).
size() / threads + addon );
118 const size_t rest ( equalShare & ( SIMDSIZE - 1UL ) );
119 const size_t sizePerThread( ( simdEnabled && rest )?( equalShare - rest + SIMDSIZE ):( equalShare ) );
121 for_loop( par,
size_t(0), threads, [&](
int i)
123 const size_t index( i*sizePerThread );
125 if( index >= (~lhs).
size() )
128 const size_t size(
min( sizePerThread, (~lhs).
size() - index ) );
130 if( simdEnabled && lhsAligned && rhsAligned ) {
131 auto target( subvector<aligned>( ~lhs, index,
size,
unchecked ) );
132 const auto source( subvector<aligned>( ~rhs, index,
size,
unchecked ) );
133 op( target, source );
135 else if( simdEnabled && lhsAligned ) {
136 auto target( subvector<aligned>( ~lhs, index,
size,
unchecked ) );
137 const auto source( subvector<unaligned>( ~rhs, index,
size,
unchecked ) );
138 op( target, source );
140 else if( simdEnabled && rhsAligned ) {
141 auto target( subvector<unaligned>( ~lhs, index,
size,
unchecked ) );
142 const auto source( subvector<aligned>( ~rhs, index,
size,
unchecked ) );
143 op( target, source );
146 auto target( subvector<unaligned>( ~lhs, index,
size,
unchecked ) );
147 const auto source( subvector<unaligned>( ~rhs, index,
size,
unchecked ) );
148 op( target, source );
173 template<
typename VT1
178 void hpxAssign( DenseVector<VT1,TF1>& lhs,
const SparseVector<VT2,TF2>& rhs, OP op )
180 using hpx::parallel::for_loop;
181 using hpx::parallel::execution::par;
186 const size_t addon ( ( ( (~lhs).
size() % threads ) != 0UL )? 1UL : 0UL );
187 const size_t sizePerThread( (~lhs).
size() / threads + addon );
189 for_loop( par,
size_t(0), threads, [&](
int i)
191 const size_t index( i*sizePerThread );
193 if( index < (~lhs).
size() )
196 const size_t size(
min( sizePerThread, (~lhs).
size() - index ) );
197 auto target( subvector<unaligned>( ~lhs, index,
size,
unchecked ) );
198 const auto source( subvector<unaligned>( ~rhs, index,
size,
unchecked ) );
199 op( target, source );
232 template<
typename VT1
236 inline auto smpAssign( Vector<VT1,TF1>& lhs,
const Vector<VT2,TF2>& rhs )
237 -> EnableIf_t< IsDenseVector_v<VT1> && ( !IsSMPAssignable_v<VT1> || !IsSMPAssignable_v<VT2> ) >
243 assign( ~lhs, ~rhs );
267 template<
typename VT1
271 inline auto smpAssign( Vector<VT1,TF1>& lhs,
const Vector<VT2,TF2>& rhs )
272 -> EnableIf_t< IsDenseVector_v<VT1> && IsSMPAssignable_v<VT1> && IsSMPAssignable_v<VT2> >
282 assign( ~lhs, ~rhs );
285 hpxAssign( ~lhs, ~rhs, Assign() );
318 template<
typename VT1
322 inline auto smpAddAssign( Vector<VT1,TF1>& lhs,
const Vector<VT2,TF2>& rhs )
323 -> EnableIf_t< IsDenseVector_v<VT1> && ( !IsSMPAssignable_v<VT1> || !IsSMPAssignable_v<VT2> ) >
329 addAssign( ~lhs, ~rhs );
353 template<
typename VT1
357 inline auto smpAddAssign( Vector<VT1,TF1>& lhs,
const Vector<VT2,TF2>& rhs )
358 -> EnableIf_t< IsDenseVector_v<VT1> && IsSMPAssignable_v<VT1> && IsSMPAssignable_v<VT2> >
368 addAssign( ~lhs, ~rhs );
371 hpxAssign( ~lhs, ~rhs, AddAssign() );
404 template<
typename VT1
408 inline auto smpSubAssign( Vector<VT1,TF1>& lhs,
const Vector<VT2,TF2>& rhs )
409 -> EnableIf_t< IsDenseVector_v<VT1> && ( !IsSMPAssignable_v<VT1> || !IsSMPAssignable_v<VT2> ) >
415 subAssign( ~lhs, ~rhs );
439 template<
typename VT1
443 inline auto smpSubAssign( Vector<VT1,TF1>& lhs,
const Vector<VT2,TF2>& rhs )
444 -> EnableIf_t< IsDenseVector_v<VT1> && IsSMPAssignable_v<VT1> && IsSMPAssignable_v<VT2> >
454 subAssign( ~lhs, ~rhs );
457 hpxAssign( ~lhs, ~rhs, SubAssign() );
490 template<
typename VT1
494 inline auto smpMultAssign( Vector<VT1,TF1>& lhs,
const Vector<VT2,TF2>& rhs )
495 -> EnableIf_t< IsDenseVector_v<VT1> && ( !IsSMPAssignable_v<VT1> || !IsSMPAssignable_v<VT2> ) >
501 multAssign( ~lhs, ~rhs );
525 template<
typename VT1
529 inline auto smpMultAssign( Vector<VT1,TF1>& lhs,
const Vector<VT2,TF2>& rhs )
530 -> EnableIf_t< IsDenseVector_v<VT1> && IsSMPAssignable_v<VT1> && IsSMPAssignable_v<VT2> >
540 multAssign( ~lhs, ~rhs );
543 hpxAssign( ~lhs, ~rhs, MultAssign() );
576 template<
typename VT1
580 inline auto smpDivAssign( Vector<VT1,TF1>& lhs,
const Vector<VT2,TF2>& rhs )
581 -> EnableIf_t< IsDenseVector_v<VT1> && ( !IsSMPAssignable_v<VT1> || !IsSMPAssignable_v<VT2> ) >
587 divAssign( ~lhs, ~rhs );
611 template<
typename VT1
615 inline auto smpDivAssign( Vector<VT1,TF1>& lhs,
const Vector<VT2,TF2>& rhs )
616 -> EnableIf_t< IsDenseVector_v<VT1> && IsSMPAssignable_v<VT1> && IsSMPAssignable_v<VT2> >
626 divAssign( ~lhs, ~rhs );
629 hpxAssign( ~lhs, ~rhs, DivAssign() );
Header file for auxiliary alias declarations.
Headerfile for the generic min algorithm.
Header file for basic type definitions.
Header file for the SparseVector base class.
Header file for the Assign functor.
constexpr Unchecked unchecked
Global Unchecked instance.The blaze::unchecked instance is an optional token for the creation of view...
Definition: Check.h:138
Header file for the AddAssign functor.
Header file for the DenseVector base class.
Header file for the SIMD trait.
auto smpDivAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP division assignment of a vector to a dense vector.
Definition: DenseVector.h:220
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SMP_ASSIGNABLE(T)
Constraint on the data type.In case the given data type T is SMP-assignable (can be assigned by multi...
Definition: SMPAssignable.h:81
#define BLAZE_HPX_PARALLEL_MODE
Compilation switch for the HPX parallelization.This compilation switch enables/disables the paralleli...
Definition: SMP.h:96
Header file for the implementation of the Subvector view.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the SubAssign functor.
System settings for the shared-memory parallelization.
Header file for the IsSMPAssignable type trait.
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1147
Header file for the serial section implementation.
Header file for the EnableIf class template.
bool isSerialSectionActive()
Returns whether a serial section is active or not.
Definition: SerialSection.h:213
Header file for the IsSIMDCombinable type trait.
Header file for run time assertion macros.
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
Header file for the IsDenseVector type trait.
Header file for the MultAssign functor.
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
Header file for SMP utility functions.
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:112
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
auto smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:191
BLAZE_ALWAYS_INLINE size_t getNumThreads()
Returns the number of threads used for thread parallel operations.
Definition: Functions.h:77
Header file for the DivAssign functor.
Constraint on the data type.
Header file for the function trace functionality.