STK++ 0.9.13
STK::hidden::BlockByPanel< Lhs, Rhs, Result > Struct Template Reference

Methods to use for C=AB with A divided in blocks and B divided in panels. More...

#include <STK_ArrayByArrayProduct.h>

Public Types

typedef Result::Type Type
 
typedef hidden::MultImpl< TypeCmult
 
typedef hidden::MultCoefImpl< Lhs, Rhs, Result > MultCoeff
 
typedef hidden::CopySubArrayImpl< Lhs, TypeCopyLhsImpl
 
typedef hidden::CopySubArrayImpl< Rhs, TypeCopyRhsImpl
 

Static Public Member Functions

static void run (Lhs const &lhs, Rhs const &rhs, Result &res)
 Main method for matrices multiplication implementation.
 
static void multBlockByPanel (Block< Type > const &block, Panel< Type > const &panel, Result &res, int iRow, int jCol)
 Default dimension.
 
static void multBlockByPanel (Block< Type > const &block, Panel< Type > const &panel, Result &res, int iRow, int jCol, int pSize)
 with panel size given
 
static void multBlockByPanel (Block< Type > const &block, Panel< Type > const &panel, Result &res, int iRow, int jCol, int pSize, int bSize)
 with panel size given
 

Detailed Description

template<typename Lhs, typename Rhs, typename Result>
struct STK::hidden::BlockByPanel< Lhs, Rhs, Result >

Methods to use for C=AB with A divided in blocks and B divided in panels.

The structure BlockByPanel use data cache and contains only static method and typedef and should normally not be used directly.

See also
BlockPanelProduct

Definition at line 58 of file STK_ArrayByArrayProduct.h.

Member Typedef Documentation

◆ Cmult

Definition at line 61 of file STK_ArrayByArrayProduct.h.

◆ CopyLhsImpl

Definition at line 63 of file STK_ArrayByArrayProduct.h.

◆ CopyRhsImpl

Definition at line 64 of file STK_ArrayByArrayProduct.h.

◆ MultCoeff

template<typename Lhs , typename Rhs , typename Result >
typedef hidden::MultCoefImpl<Lhs, Rhs, Result> STK::hidden::BlockByPanel< Lhs, Rhs, Result >::MultCoeff

Definition at line 62 of file STK_ArrayByArrayProduct.h.

◆ Type

template<typename Lhs , typename Rhs , typename Result >
typedef Result::Type STK::hidden::BlockByPanel< Lhs, Rhs, Result >::Type

Definition at line 60 of file STK_ArrayByArrayProduct.h.

Member Function Documentation

◆ multBlockByPanel() [1/3]

template<typename Lhs , typename Rhs , typename Result >
static void STK::hidden::BlockByPanel< Lhs, Rhs, Result >::multBlockByPanel ( Block< Type > const block,
Panel< Type > const panel,
Result &  res,
int  iRow,
int  jCol 
)
inlinestatic

Default dimension.

Definition at line 135 of file STK_ArrayByArrayProduct.h.

137 {
138 for (int j=0; j<panelSize_; ++j)
139 {
140 res.elt(iRow ,jCol+j) += panel[j*blockSize_] * block[0]
141 + panel[j*blockSize_+ 1] * block[1]
142 + panel[j*blockSize_+ 2] * block[2]
143 + panel[j*blockSize_+ 3] * block[3];
144 res.elt(iRow+1,jCol+j) += panel[j*blockSize_] * block[4]
145 + panel[j*blockSize_+ 1] * block[5]
146 + panel[j*blockSize_+ 2] * block[6]
147 + panel[j*blockSize_+ 3] * block[7];
148 res.elt(iRow+2,jCol+j) += panel[j*blockSize_] * block[8]
149 + panel[j*blockSize_+ 1] * block[9]
150 + panel[j*blockSize_+ 2] * block[10]
151 + panel[j*blockSize_+ 3] * block[11];
152 res.elt(iRow+3,jCol+j) += panel[j*blockSize_] * block[12]
153 + panel[j*blockSize_+ 1] * block[13]
154 + panel[j*blockSize_+ 2] * block[14]
155 + panel[j*blockSize_+ 3] * block[15];
156 }
157 }
const int panelSize_
const int blockSize_

References STK::blockSize_, and STK::panelSize_.

Referenced by STK::hidden::BlockByPanel< Lhs, Rhs, Result >::run().

◆ multBlockByPanel() [2/3]

template<typename Lhs , typename Rhs , typename Result >
static void STK::hidden::BlockByPanel< Lhs, Rhs, Result >::multBlockByPanel ( Block< Type > const block,
Panel< Type > const panel,
Result &  res,
int  iRow,
int  jCol,
int  pSize 
)
inlinestatic

with panel size given

Definition at line 159 of file STK_ArrayByArrayProduct.h.

161 {
162 for (int j=0; j<pSize; ++j)
163 {
164 res.elt(iRow ,jCol+j) += panel[j*blockSize_] * block[0]
165 + panel[j*blockSize_+ 1] * block[1]
166 + panel[j*blockSize_+ 2] * block[2]
167 + panel[j*blockSize_+ 3] * block[3];
168 res.elt(iRow+1,jCol+j) += panel[j*blockSize_] * block[4]
169 + panel[j*blockSize_+ 1] * block[5]
170 + panel[j*blockSize_+ 2] * block[6]
171 + panel[j*blockSize_+ 3] * block[7];
172 res.elt(iRow+2,jCol+j) += panel[j*blockSize_] * block[8]
173 + panel[j*blockSize_+ 1] * block[9]
174 + panel[j*blockSize_+ 2] * block[10]
175 + panel[j*blockSize_+ 3] * block[11];
176 res.elt(iRow+3,jCol+j) += panel[j*blockSize_] * block[12]
177 + panel[j*blockSize_+ 1] * block[13]
178 + panel[j*blockSize_+ 2] * block[14]
179 + panel[j*blockSize_+ 3] * block[15];
180 }
181 }

References STK::blockSize_.

◆ multBlockByPanel() [3/3]

template<typename Lhs , typename Rhs , typename Result >
static void STK::hidden::BlockByPanel< Lhs, Rhs, Result >::multBlockByPanel ( Block< Type > const block,
Panel< Type > const panel,
Result &  res,
int  iRow,
int  jCol,
int  pSize,
int  bSize 
)
inlinestatic

with panel size given

Definition at line 183 of file STK_ArrayByArrayProduct.h.

185 {
186 for (int i=0; i<bSize; ++i)
187 for (int j=0; j<pSize; ++j)
188 { res.elt(iRow+i,jCol+j) += panel[j*blockSize_] * block[i*blockSize_]
189 + panel[j*blockSize_+1] * block[i*blockSize_+1]
190 + panel[j*blockSize_+2] * block[i*blockSize_+2]
191 + panel[j*blockSize_+3] * block[i*blockSize_+3];
192 }
193 }

References STK::blockSize_.

◆ run()

template<typename Lhs , typename Rhs , typename Result >
static void STK::hidden::BlockByPanel< Lhs, Rhs, Result >::run ( Lhs const lhs,
Rhs const rhs,
Result &  res 
)
inlinestatic

Main method for matrices multiplication implementation.

Note
res have been resized and initialized to zero outside this method.

Definition at line 69 of file STK_ArrayByArrayProduct.h.

70 {
71#ifdef STK_ARRAYS_DEBUG
72 stk_cout << _T("Entering BlockByPanel::run()\n");
73#endif
74 // compute dimensions
75 int nbInnerLoop = lhs.sizeCols()/blockSize_; // = rhs.sizeRows()/blockSize_;
76 int nbBlocks = lhs.sizeRows()/blockSize_;
77 int nbPanels = rhs.sizeCols()/panelSize_;
78 // remaining sizes in the matrices
79 int pSize = rhs.sizeCols() - panelSize_*nbPanels;
80 int bSize = lhs.sizeRows() - blockSize_*nbBlocks;
81 int tSize = lhs.sizeCols() - blockSize_*nbInnerLoop;
82 // = rhs.sizeRows() - rhs.sizeRows()/blockSize_
83 int iLastRow = lhs.beginRows() + nbBlocks * blockSize_;
84 int jLastCol = rhs.beginCols() + nbPanels * panelSize_;
85 int kLastPos = lhs.beginCols() + blockSize_ * nbInnerLoop;
86 // start
87 if (nbInnerLoop)
88 {
89 // create panels and blocks
90 Panel<Type>* tabPanel = new Panel<Type>[nbPanels+1];
91 Block<Type>* tabBlock = new Block<Type>[nbBlocks+1];
92 // start blocks by panel
93 for (int k = 0,kPos = lhs.beginCols(); k<nbInnerLoop; ++k, kPos += blockSize_)
94 {
95 // data caching
96 for (int i = 0, iRow = lhs.beginRows(); i<nbBlocks; ++i, iRow += blockSize_)
97 { CopyLhsImpl::arrayToBlock( lhs, tabBlock[i], iRow, kPos);}
98 CopyLhsImpl::arrayToBlock( lhs, tabBlock[nbBlocks], iLastRow, kPos, bSize);
99 for (int j = 0, jCol = rhs.beginCols(); j<nbPanels; ++j, jCol += panelSize_)
100 { CopyRhsImpl::arrayToPanel( rhs, tabPanel[j], kPos, jCol);}
101 CopyRhsImpl::arrayToPanel( rhs, tabPanel[nbPanels], kPos, jLastCol, pSize);
102 // block by panel products
103#ifdef _OPENMP
104#pragma omp parallel for
105#endif
106 for (int i = 0; i<nbBlocks; ++i)
107 {
108 int iRow = lhs.beginRows()+ i * blockSize_;
109 for (int j = 0, jCol = rhs.beginCols(); j<nbPanels; ++j, jCol += panelSize_)
110 { multBlockByPanel( tabBlock[i], tabPanel[j], res, iRow, jCol);}
111 }
112 for (int i = 0, iRow = lhs.beginRows(); i<nbBlocks; ++i,iRow += blockSize_)
113 { multBlockByPanel( tabBlock[i], tabPanel[nbPanels], res, iRow, jLastCol, pSize);}
114#ifdef _OPENMP
115#pragma omp parallel for
116#endif
117 for (int j = 0; j<nbPanels; ++j)
118 { multBlockByPanel( tabBlock[nbBlocks], tabPanel[j], res, iLastRow, rhs.beginCols() + j * panelSize_, panelSize_, bSize);}
119 multBlockByPanel( tabBlock[nbBlocks], tabPanel[nbPanels], res, iLastRow, jLastCol, pSize, bSize);
120 } // InnerLoop
121 delete[] tabBlock;
122 delete[] tabPanel;
123 } // if IneerLoop
124 // treat the remaining rows, columns
125 switch (tSize)
126 {
127 case 0: break;
128 case 1: MultCoeff::mult1Outer(lhs, rhs, res, kLastPos); break;
129 case 2: MultCoeff::mult2Outer(lhs, rhs, res, kLastPos); break;
130 case 3: MultCoeff::mult3Outer(lhs, rhs, res, kLastPos); break;
131 default:break;
132 }
133 }
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
static void multBlockByPanel(Block< Type > const &block, Panel< Type > const &panel, Result &res, int iRow, int jCol)
Default dimension.
static void arrayToPanel(Array const &m, Panel< Type > &panel, int iRow, int jCol)
copy a part of an array in a Panel
static void arrayToBlock(Array const &m, Block< Type > &block, int iRow, int jCol)
copy a part of an Array in a Block
static void mult2Outer(Lhs const &lhs, Rhs const &rhs, Result &res, int k)
multiplication with two outer rows/columns
static void mult1Outer(Lhs const &lhs, Rhs const &rhs, Result &res, int k)
multiplication with one outer rows/columns
static void mult3Outer(Lhs const &lhs, Rhs const &rhs, Result &res, int k)
multiplication with three outer rows/columns

References _T, STK::hidden::CopySubArrayImpl< Array, Type >::arrayToBlock(), STK::hidden::CopySubArrayImpl< Array, Type >::arrayToPanel(), STK::blockSize_, STK::hidden::MultCoefImpl< Lhs, Rhs, Result >::mult1Outer(), STK::hidden::MultCoefImpl< Lhs, Rhs, Result >::mult2Outer(), STK::hidden::MultCoefImpl< Lhs, Rhs, Result >::mult3Outer(), STK::hidden::BlockByPanel< Lhs, Rhs, Result >::multBlockByPanel(), STK::panelSize_, and stk_cout.


The documentation for this struct was generated from the following file: