STK++ 0.9.13
STK::hidden::BlockPanelProduct< 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
 

Static Public Member Functions

static void run (Lhs const &lhs, Rhs const &rhs, Result &res)
 Main method for Matrices multiplication implementation.
 
template<class SubLhs , class SubRhs >
static void multBlockByPanel (SubLhs const &lhs, SubRhs const &rhs, Result &res)
 matrix product between a lhs block and a rhs panel
 
template<class SubLhs , class SubRhs >
static void multBlockPartByPanel (SubLhs const &lhs, SubRhs const &rhs, Result &res)
 matrix product between a lhs block and a rhs panel
 

Detailed Description

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

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

The structure BlockPanelProduct contains only static methods and typedef and should normally not be used directly.

See also
BlockByPanel

Definition at line 349 of file STK_ArrayByArrayProduct.h.

Member Typedef Documentation

◆ Cmult

Definition at line 352 of file STK_ArrayByArrayProduct.h.

◆ MultCoeff

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

Definition at line 353 of file STK_ArrayByArrayProduct.h.

◆ Type

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

Definition at line 351 of file STK_ArrayByArrayProduct.h.

Member Function Documentation

◆ multBlockByPanel()

template<typename Lhs , typename Rhs , typename Result >
template<class SubLhs , class SubRhs >
static void STK::hidden::BlockPanelProduct< Lhs, Rhs, Result >::multBlockByPanel ( SubLhs const lhs,
SubRhs const rhs,
Result &  res 
)
inlinestatic

matrix product between a lhs block and a rhs panel

Definition at line 419 of file STK_ArrayByArrayProduct.h.

420 {
421 const int k= rhs.beginRows();
422 for (int j=rhs.beginCols(); j<rhs.endCols(); ++j)
423 {
424 int i = lhs.beginRows();
425 res.elt(i,j) += lhs(i ,k) * rhs(k ,j) + lhs(i ,k+1) * rhs(k+1,j)
426 + lhs(i ,k+2) * rhs(k+2,j) + lhs(i ,k+3) * rhs(k+3,j);
427 ++i;
428 res.elt(i,j) += lhs(i,k) * rhs(k ,j) + lhs(i,k+1) * rhs(k+1,j)
429 + lhs(i,k+2) * rhs(k+2,j) + lhs(i,k+3) * rhs(k+3,j);
430 ++i;
431 res.elt(i,j) += lhs(i,k) * rhs(k ,j) + lhs(i,k+1) * rhs(k+1,j)
432 + lhs(i,k+2) * rhs(k+2,j) + lhs(i,k+3) * rhs(k+3,j);
433 ++i;
434 res.elt(i,j) += lhs(i,k) * rhs(k ,j) + lhs(i,k+1) * rhs(k+1,j)
435 + lhs(i,k+2) * rhs(k+2,j) + lhs(i,k+3) * rhs(k+3,j);
436 }
437 }

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

◆ multBlockPartByPanel()

template<typename Lhs , typename Rhs , typename Result >
template<class SubLhs , class SubRhs >
static void STK::hidden::BlockPanelProduct< Lhs, Rhs, Result >::multBlockPartByPanel ( SubLhs const lhs,
SubRhs const rhs,
Result &  res 
)
inlinestatic

matrix product between a lhs block and a rhs panel

Definition at line 440 of file STK_ArrayByArrayProduct.h.

441 {
442 const int k= rhs.beginRows();
443 for (int j=rhs.beginCols(); j<rhs.endCols(); ++j)
444 for(int i=lhs.beginRows(); i<lhs.endRows(); ++i)
445 res.elt(i,j) += lhs(i,k ) * rhs(k ,j) + lhs(i,k+1) * rhs(k+1,j)
446 + lhs(i,k+2) * rhs(k+2,j) + lhs(i,k+3) * rhs(k+3,j);
447 }

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

◆ run()

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

359 {
360#ifdef STK_DEBUG
361 stk_cout << _T("Entering BlockPanelProduct::run()\n");
362#endif
363 // compute number of loops
364 int nbInnerLoop = lhs.sizeCols()/blockSize_;
365 int nbBlocks = lhs.sizeRows()/blockSize_;
366 int nbPanels = rhs.sizeCols()/panelSize_;
367
368 // remaining sizes in the matrices
369 int bSize = lhs.sizeRows() - blockSize_ * nbBlocks;
370 int pSize = rhs.sizeCols() - panelSize_ * nbPanels;
371 int tSize = lhs.sizeCols() - blockSize_ * nbInnerLoop;
372
373 // remaining positions in the matrices
374 int kLastPos = lhs.beginCols() + blockSize_ * nbInnerLoop;
375
376 // start blocks by panel
377 for (int k = 0; k<nbInnerLoop; ++k)
378 {
379 TRange<blockSize_> innerRange(lhs.beginCols() + k * blockSize_, blockSize_);
380#ifdef _OPENMP
381#pragma omp parallel for
382#endif
383 for (int i = 0; i<nbBlocks; ++i)
384 {
385 TRange<blockSize_> rowRange(lhs.beginRows() + i * blockSize_, blockSize_);
386 for (int j = 0; j<nbPanels; ++j)
387 {
388 TRange<panelSize_> colRange(rhs.beginCols() + j * panelSize_, panelSize_);
389 multBlockByPanel( lhs.sub(rowRange, innerRange), rhs.sub(innerRange, colRange), res);
390 }
391 // remaining incomplete panels
392 Range colRange(rhs.beginCols() + nbPanels * panelSize_, pSize);
393 multBlockByPanel( lhs.sub(rowRange, innerRange), rhs.sub(innerRange, colRange), res);
394 }
395 Range rowRange(lhs.beginRows() + nbBlocks * blockSize_, bSize);
396#ifdef _OPENMP
397#pragma omp parallel for
398#endif
399 for (int j = 0; j<nbPanels; ++j)
400 {
401 TRange<panelSize_> colRange(res.beginCols() + j * panelSize_, panelSize_);
402 multBlockPartByPanel( lhs.sub(rowRange, innerRange), rhs.sub(innerRange, colRange), res);
403 }
404 // remaining incomplete panels
405 Range colRange(res.beginCols() + nbPanels * panelSize_, pSize);
406 multBlockPartByPanel( lhs.sub(rowRange, innerRange), rhs.sub(innerRange, colRange), res);
407 } // InnerLoop
408 // treat the remaining rows/columns not in outer loop k
409 switch (tSize)
410 {
411 case 1: MultCoeff::mult1Outer(lhs, rhs, res, kLastPos); break;
412 case 2: MultCoeff::mult2Outer(lhs, rhs, res, kLastPos); break;
413 case 3: MultCoeff::mult3Outer(lhs, rhs, res, kLastPos); break;
414 default:break;
415 }
416 }
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
const int panelSize_
const int blockSize_
TRange< UnknownSize > Range
Definition STK_Range.h:59
static void multBlockByPanel(SubLhs const &lhs, SubRhs const &rhs, Result &res)
matrix product between a lhs block and a rhs panel
static void multBlockPartByPanel(SubLhs const &lhs, SubRhs const &rhs, Result &res)
matrix product between a lhs block and a rhs panel
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::blockSize_, STK::hidden::MultCoefImpl< Lhs, Rhs, Result >::mult1Outer(), STK::hidden::MultCoefImpl< Lhs, Rhs, Result >::mult2Outer(), STK::hidden::MultCoefImpl< Lhs, Rhs, Result >::mult3Outer(), STK::hidden::BlockPanelProduct< Lhs, Rhs, Result >::multBlockByPanel(), STK::hidden::BlockPanelProduct< Lhs, Rhs, Result >::multBlockPartByPanel(), STK::panelSize_, and stk_cout.


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