Blaze 3.9
ThreadMapping.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_SMP_THREADMAPPING_H_
36#define _BLAZE_MATH_SMP_THREADMAPPING_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <utility>
49#include <blaze/util/Types.h>
50
51
52namespace blaze {
53
54//=================================================================================================
55//
56// THREADMAPPING FUNCTIONALITY
57//
58//=================================================================================================
59
60//*************************************************************************************************
62using ThreadMapping = std::pair<size_t,size_t>;
64//*************************************************************************************************
65
66
67//*************************************************************************************************
80template< typename MT // Type of the matrix
81 , bool SO > // Storage order of the matrix
82ThreadMapping createThreadMapping( size_t threads, const Matrix<MT,SO>& A )
83{
84 const size_t M( (*A).rows() );
85 const size_t N( (*A).columns() );
86
87 if( M > N || ( M == N && !SO ) )
88 {
89 const double ratio( double(M)/double(N) );
90 size_t m = min( threads, max( 1UL, static_cast<size_t>( round( sqrt( threads*ratio ) ) ) ) );
91 size_t n = threads / m;
92
93 while( m * n != threads ) {
94 ++m;
95 n = threads / m;
96 }
97
98 return ThreadMapping( m, n );
99 }
100 else
101 {
102 const double ratio( double(N)/double(M) );
103 size_t n = min( threads, max( 1UL, static_cast<size_t>( round( sqrt( threads*ratio ) ) ) ) );
104 size_t m = threads / n;
105
106 while( m * n != threads ) {
107 ++n;
108 m = threads / n;
109 }
110
111 return ThreadMapping( m, n );
112 }
113}
115//*************************************************************************************************
116
117} // namespace blaze
118
119#endif
Header file for the Matrix base class.
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:1339
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375
decltype(auto) round(const DenseMatrix< MT, SO > &dm)
Applies the round() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1436
decltype(auto) sqrt(const DenseMatrix< MT, SO > &dm)
Computes the square root of each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1616
Header file for the round shim.
Header file for the sqrt shim.
Header file for basic type definitions.
Header file for the generic max algorithm.
Header file for the generic min algorithm.