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

Methods to use for C=AB with A divided in panels and B divided in blocks. 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 multPanelByBlock (Panel< Type > const &panel, Block< Type > const &block, Result &res, int iRow, int jCol)
 Default dimension.
 
static void multPanelByBlock (Panel< Type > const &panel, Block< Type > const &block, Result &res, int iRow, int jCol, int pSize)
 
static void multPanelByBlock (Panel< Type > const &panel, Block< Type > const &block, Result &res, int iRow, int jCol, int pSize, int bSize)
 with panel size and block size dimension given
 

Detailed Description

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

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

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

See also
PanelBlockProduct

Definition at line 204 of file STK_ArrayByArrayProduct.h.

Member Typedef Documentation

◆ Cmult

Definition at line 207 of file STK_ArrayByArrayProduct.h.

◆ CopyLhsImpl

Definition at line 209 of file STK_ArrayByArrayProduct.h.

◆ CopyRhsImpl

Definition at line 210 of file STK_ArrayByArrayProduct.h.

◆ MultCoeff

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

Definition at line 208 of file STK_ArrayByArrayProduct.h.

◆ Type

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

Definition at line 206 of file STK_ArrayByArrayProduct.h.

Member Function Documentation

◆ multPanelByBlock() [1/3]

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

Default dimension.

Definition at line 282 of file STK_ArrayByArrayProduct.h.

284 {
285 for (int i=0; i<panelSize_; ++i)
286 {
287 res.elt(iRow+i,jCol) += panel[i*blockSize_] * block[0]
288 + panel[i*blockSize_+ 1] * block[1]
289 + panel[i*blockSize_+ 2] * block[2]
290 + panel[i*blockSize_+ 3] * block[3];
291 res.elt(iRow+i,jCol+1) += panel[i*blockSize_] * block[4]
292 + panel[i*blockSize_+ 1] * block[5]
293 + panel[i*blockSize_+ 2] * block[6]
294 + panel[i*blockSize_+ 3] * block[7];
295 res.elt(iRow+i,jCol+2) += panel[i*blockSize_] * block[8]
296 + panel[i*blockSize_+ 1] * block[9]
297 + panel[i*blockSize_+ 2] * block[10]
298 + panel[i*blockSize_+ 3] * block[11];
299 res.elt(iRow+i,jCol+3) += panel[i*blockSize_] * block[12]
300 + panel[i*blockSize_+ 1] * block[13]
301 + panel[i*blockSize_+ 2] * block[14]
302 + panel[i*blockSize_+ 3] * block[15];
303 }
304 }
const int panelSize_
const int blockSize_

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

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

◆ multPanelByBlock() [2/3]

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

Definition at line 305 of file STK_ArrayByArrayProduct.h.

307 {
308 for (int i=0; i<pSize; ++i)
309 {
310 res.elt(iRow+i,jCol) += panel[i*blockSize_] * block[0]
311 + panel[i*blockSize_+ 1] * block[1]
312 + panel[i*blockSize_+ 2] * block[2]
313 + panel[i*blockSize_+ 3] * block[3];
314 res.elt(iRow+i,jCol+1) += panel[i*blockSize_] * block[4]
315 + panel[i*blockSize_+ 1] * block[5]
316 + panel[i*blockSize_+ 2] * block[6]
317 + panel[i*blockSize_+ 3] * block[7];
318 res.elt(iRow+i,jCol+2) += panel[i*blockSize_] * block[8]
319 + panel[i*blockSize_+ 1] * block[9]
320 + panel[i*blockSize_+ 2] * block[10]
321 + panel[i*blockSize_+ 3] * block[11];
322 res.elt(iRow+i,jCol+3) += panel[i*blockSize_] * block[12]
323 + panel[i*blockSize_+ 1] * block[13]
324 + panel[i*blockSize_+ 2] * block[14]
325 + panel[i*blockSize_+ 3] * block[15];
326 }
327 }

References STK::blockSize_.

◆ multPanelByBlock() [3/3]

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

with panel size and block size dimension given

Definition at line 329 of file STK_ArrayByArrayProduct.h.

331 {
332 for (int i=0; i<pSize; ++i)
333 for (int j=0; j<bSize; ++j)
334 res.elt(iRow+i,jCol+j) += panel[i*blockSize_] * block[j*blockSize_]
335 + panel[i*blockSize_+1] * block[j*blockSize_+1]
336 + panel[i*blockSize_+2] * block[j*blockSize_+2]
337 + panel[i*blockSize_+3] * block[j*blockSize_+3];
338 }

References STK::blockSize_.

◆ run()

template<typename Lhs , typename Rhs , typename Result >
static void STK::hidden::PanelByBlock< 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 214 of file STK_ArrayByArrayProduct.h.

215 {
216#ifdef STK_ARRAYS_DEBUG
217 stk_cout << _T("Entering PanelByBlock::run()\n");
218#endif
219 // compute dimensions
220 int nbInnerLoop = lhs.sizeCols()/blockSize_; // = rhs.sizeRows()/blockSize_;
221 int nbBlocks = rhs.sizeCols()/blockSize_;
222 int nbPanels = lhs.sizeRows()/panelSize_;
223
224 // remaining sizes in the matrices
225 int pSize = lhs.sizeRows() - panelSize_ * nbPanels;
226 int bSize = rhs.sizeCols() - blockSize_ * nbBlocks;
227 int tSize = lhs.sizeCols() - blockSize_ * nbInnerLoop;
228
229 // index of the remaining positions
230 int jLastCol = rhs.beginCols() + blockSize_ * nbBlocks;
231 int iLastRow = lhs.beginRows() + panelSize_ * nbPanels;
232 int kLastPos = rhs.beginRows() + blockSize_ * nbInnerLoop;
233
234 if (nbInnerLoop)
235 {
236 // create panels
237 Panel<Type>* tabPanel = new Panel<Type>[nbPanels+1];
238 Block<Type>* tabBlock = new Block<Type>[nbBlocks+1];
239 // start blocks by panel
240 for (int k = 0, kPos = rhs.beginRows(); k<nbInnerLoop; ++k,kPos += blockSize_)
241 {
242 // data caching
243 for (int i = 0, iRow= lhs.beginRows(); i<nbPanels; ++i, iRow+= panelSize_)
244 { CopyLhsImpl::arrayToPanelByCol( lhs, tabPanel[i], iRow, kPos);}
245 CopyLhsImpl::arrayToPanelByCol( lhs, tabPanel[nbPanels], iLastRow, kPos, pSize);
246 // get blocks
247 for (int j = 0, jCol = rhs.beginCols(); j<nbBlocks; ++j, jCol+=blockSize_)
248 { CopyRhsImpl::arrayToBlockByCol( rhs, tabBlock[j], kPos, jCol);}
249 CopyRhsImpl::arrayToBlockByCol( rhs, tabBlock[nbBlocks], kPos, jLastCol, bSize);
250 // perform the products panels * blocks
251#ifdef _OPENMP
252#pragma omp parallel for
253#endif
254 for (int j = 0; j<nbBlocks; ++j)
255 {
256 int jCol = rhs.beginCols() + j* blockSize_;
257 for (int i = 0,iRow = lhs.beginRows(); i<nbPanels; ++i, iRow += panelSize_)
258 { multPanelByBlock( tabPanel[i], tabBlock[j], res, iRow, jCol);}
259 multPanelByBlock( tabPanel[nbPanels], tabBlock[j], res, iLastRow, jCol, pSize);
260 }
261#ifdef _OPENMP
262#pragma omp parallel for
263#endif
264 for (int i = 0; i<nbPanels; ++i)
265 { multPanelByBlock( tabPanel[i], tabBlock[nbBlocks], res, lhs.beginRows() + i * panelSize_, jLastCol, panelSize_, bSize);}
266 multPanelByBlock( tabPanel[nbPanels], tabBlock[nbBlocks], res, iLastRow, jLastCol, pSize, bSize);
267 } // k loop
268 delete[] tabPanel;
269 delete[] tabBlock;
270 }
271 // treat the remaining rows, columns
272 switch (tSize)
273 {
274 case 0: break;
275 case 1: MultCoeff::mult1Outer(lhs, rhs, res, kLastPos); break;
276 case 2: MultCoeff::mult2Outer(lhs, rhs, res, kLastPos); break;
277 case 3: MultCoeff::mult3Outer(lhs, rhs, res, kLastPos); break;
278 default:break;
279 }
280 }
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
static void arrayToBlockByCol(Array const &m, Block< Type > &block, int iRow, int jCol)
default dimensions
static void arrayToPanelByCol(Array const &m, Panel< Type > &panel, int iRow, int kPos)
default dimensions
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
static void multPanelByBlock(Panel< Type > const &panel, Block< Type > const &block, Result &res, int iRow, int jCol)
Default dimension.

References _T, STK::hidden::CopySubArrayImpl< Array, Type >::arrayToBlockByCol(), STK::hidden::CopySubArrayImpl< Array, Type >::arrayToPanelByCol(), 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::PanelByBlock< Lhs, Rhs, Result >::multPanelByBlock(), STK::panelSize_, and stk_cout.


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