46 #ifndef _PEXSI_PSELINV_HPP_
47 #define _PEXSI_PSELINV_HPP_
63 #include "pexsi/TreeBcast.hpp"
68 #define IDX_TO_TAG(lidx,tag) (SELINV_TAG_COUNT*(lidx)+(tag))
69 #define IDX_TO_TAG2(sidx,lidx,tag) (SELINV_TAG_COUNT*(sidx)+(tag))
70 #define TAG_TO_IDX(tag,typetag) (((tag)-(typetag))/SELINV_TAG_COUNT)
80 enum MSGTYPE {LSIZE=0,LROWSIZE,USIZE,UCOLSIZE,LCONTENT,LROWCONTENT,UCONTENT,UCOLCONTENT,MSGCOUNT};
85 bool operator() (
int i,
int j) {
return ((lookup)(i)<(lookup)(j));}
90 typedef std::vector<bool> bitMask;
91 typedef std::map<bitMask , std::vector<Int> > bitMaskSet;
117 GridType( MPI_Comm Bcomm,
int nprow,
int npcol );
183 LBlock& operator = (
const LBlock& LB) {
191 friend std::ostream& operator<<(std::ostream& out,
const LBlock& vec)
193 out <<
"(" << vec.blockIdx <<
", " << vec.numRow <<
", " << vec.numCol <<std::endl<<
"rows " << vec.rows <<std::endl<<
"nzval " <<std::endl<< vec.nzval <<
")";
233 UBlock& operator = (
const UBlock& UB) {
242 friend std::ostream& operator<<(std::ostream& out,
const UBlock& vec)
244 out <<
"(" << vec.blockIdx <<
", " << vec.numRow <<
", " << vec.numCol <<std::endl<<
"cols " << vec.cols <<std::endl<<
"nzval " <<std::endl<< vec.nzval <<
")";
258 {
return g->mpirank; }
262 {
return g->mpirank / g->numProcCol; }
266 {
return g->mpirank % g->numProcCol; }
271 {
return bnum % g->numProcRow; }
276 {
return bnum % g->numProcCol; }
281 {
return (i%g->numProcRow) * g->numProcCol + j%g->numProcCol; }
286 {
return bnum / g->numProcRow; }
291 {
return bnum / g->numProcCol; }
296 {
return iLocal * g->numProcRow +
MYROW( g ); }
301 {
return jLocal * g->numProcCol +
MYCOL( g ); }
306 {
return (a%b) ? ( a/b + 1 ) : ( a/b ); }
310 {
return s->superIdx[i]; }
315 {
return s->superPtr[bnum]; }
322 {
return s->superPtr[bnum]; }
327 {
return s->superPtr[bnum+1] - s->superPtr[bnum]; }
331 {
return s->superPtr.m() - 1; }
336 {
return s->superIdx.m(); }
360 namespace LBlockMask{
373 Int
inline serialize(LBlock<T>& val, std::ostream& os,
const std::vector<Int>& mask){
374 if(mask[LBlockMask::BLOCKIDX]==1) serialize(val.blockIdx, os, mask);
375 if(mask[LBlockMask::NUMROW ]==1) serialize(val.numRow, os, mask);
376 if(mask[LBlockMask::NUMCOL ]==1) serialize(val.numCol, os, mask);
377 if(mask[LBlockMask::ROWS ]==1) serialize(val.rows, os, mask);
378 if(mask[LBlockMask::NZVAL ]==1) serialize(val.nzval, os, mask);
383 Int
inline deserialize(LBlock<T>& val, std::istream& is,
const std::vector<Int>& mask){
384 if(mask[LBlockMask::BLOCKIDX]==1) deserialize(val.blockIdx, is, mask);
385 if(mask[LBlockMask::NUMROW ]==1) deserialize(val.numRow, is, mask);
386 if(mask[LBlockMask::NUMCOL ]==1) deserialize(val.numCol, is, mask);
387 if(mask[LBlockMask::ROWS ]==1) deserialize(val.rows, is, mask);
388 if(mask[LBlockMask::NZVAL ]==1) deserialize(val.nzval, is, mask);
408 namespace UBlockMask{
420 Int
inline serialize(UBlock<T>& val, std::ostream& os,
const std::vector<Int>& mask){
422 if(mask[i]==1) serialize(val.blockIdx, os, mask); i++;
423 if(mask[i]==1) serialize(val.numRow, os, mask); i++;
424 if(mask[i]==1) serialize(val.numCol, os, mask); i++;
425 if(mask[i]==1) serialize(val.cols, os, mask); i++;
426 if(mask[i]==1) serialize(val.nzval, os, mask); i++;
431 Int
inline deserialize(UBlock<T>& val, std::istream& is,
const std::vector<Int>& mask){
433 if(mask[i]==1) deserialize(val.blockIdx, is, mask); i++;
434 if(mask[i]==1) deserialize(val.numRow, is, mask); i++;
435 if(mask[i]==1) deserialize(val.numCol, is, mask); i++;
436 if(mask[i]==1) deserialize(val.cols, is, mask); i++;
437 if(mask[i]==1) deserialize(val.nzval, is, mask); i++;
511 static PMatrix<T> *
Create(
const GridType * pGridType,
const SuperNodeType * pSuper,
const SuperLUOptions * pLuOpt);
512 static PMatrix<T> *
Create(
const SuperLUOptions * pLuOpt);
519 SELINV_TAG_U_CONTENT,
521 SELINV_TAG_L_CONTENT,
524 SELINV_TAG_D_CONTENT,
526 SELINV_TAG_L_SIZE_CD,
527 SELINV_TAG_L_CONTENT_CD,
538 const GridType* grid_;
540 const SuperNodeType* super_;
542 const SuperLUOptions * options_;
544 std::vector<std::vector<Int> > ColBlockIdx_;
545 std::vector<std::vector<Int> > RowBlockIdx_;
546 std::vector<std::vector<LBlock<T> > > L_;
547 std::vector<std::vector<UBlock<T> > > U_;
549 std::vector<std::vector<Int> > workingSet_;
553 BolNumMat isSendToBelow_;
554 BolNumMat isSendToRight_;
555 BolNumVec isSendToDiagonal_;
556 BolNumMat isSendToCrossDiagonal_;
558 BolNumMat isRecvFromBelow_;
559 BolNumVec isRecvFromAbove_;
560 BolNumVec isRecvFromLeft_;
561 BolNumMat isRecvFromCrossDiagonal_;
564 std::vector<TreeBcast *> fwdToBelowTree_;
565 std::vector<TreeBcast *> fwdToRightTree_;
566 std::vector<TreeReduce<T> *> redToLeftTree_;
567 std::vector<TreeReduce<T> *> redToAboveTree_;
572 std::vector<Int> RowLocalPtr;
573 std::vector<Int> BlockIdxLocal;
574 std::vector<char> SstrLcolSend;
575 std::vector<char> SstrUrowSend;
576 std::vector<char> SstrLcolRecv;
577 std::vector<char> SstrUrowRecv;
578 Int SizeSstrLcolSend;
579 Int SizeSstrUrowSend;
580 Int SizeSstrLcolRecv;
581 Int SizeSstrUrowRecv;
612 inline void GetWorkSet(std::vector<Int> & snodeEtree, std::vector<std::vector<Int> > & WSet);
621 inline void SendRecvCD_UpdateU(std::vector<SuperNodeBufferType > & arrSuperNodes, Int stepSuper);
639 Int NumCol()
const {
return super_ -> superIdx.m(); }
641 Int NumSuper()
const {
return super_ ->superPtr.m() - 1; }
650 std::vector< std::vector<Int> > & ColBlockIdx() {
return ColBlockIdx_; }
651 std::vector< std::vector<Int> > & RowBlockIdx() {
return RowBlockIdx_; }
652 std::vector<Int> & ColBlockIdx(Int jLocal) {
return ColBlockIdx_[jLocal]; }
653 std::vector<Int> & RowBlockIdx(Int iLocal) {
return RowBlockIdx_[iLocal]; }
658 Int
NumBlockL( Int jLocal )
const {
return L_[jLocal].size(); }
662 Int
NumBlockU( Int iLocal )
const {
return U_[iLocal].size(); }
673 std::vector<LBlock<T> >&
L( Int jLocal ) {
return L_[jLocal]; }
677 std::vector<UBlock<T> >&
U( Int iLocal ) {
return U_[iLocal]; }
681 std::vector<std::vector<int> >&
WorkingSet( ) {
return workingSet_; }
685 Int
CountSendToRight(Int ksup) { Int count= std::count (isSendToRight_.VecData(ksup), isSendToRight_.VecData(ksup) + grid_->numProcCol,
true);
return (isSendToRight_(
MYCOL(grid_),ksup)?count-1:count); }
689 Int
CountSendToBelow(Int ksup) { Int count= std::count (isSendToBelow_.VecData(ksup), isSendToBelow_.VecData(ksup) + grid_->numProcRow,
true);
return (isSendToBelow_(
MYROW(grid_),ksup)?count-1:count); }
693 Int
CountRecvFromBelow(Int ksup) { Int count= std::count (isRecvFromBelow_.VecData(ksup), isRecvFromBelow_.VecData(ksup) + grid_->numProcRow,
true);
return (isRecvFromBelow_(
MYROW(grid_),ksup)?count-1:count); }
697 Int
CountSendToCrossDiagonal(Int ksup) { Int count= std::count (isSendToCrossDiagonal_.VecData(ksup), isSendToCrossDiagonal_.VecData(ksup) + grid_->numProcCol,
true);
return ((isSendToCrossDiagonal_(
MYCOL(grid_),ksup) &&
MYROW(grid_)==
PROW(ksup,grid_))?count-1:count); }
701 Int
CountRecvFromCrossDiagonal(Int ksup) { Int count= std::count (isRecvFromCrossDiagonal_.VecData(ksup), isRecvFromCrossDiagonal_.VecData(ksup) + grid_->numProcRow,
true);
return ((isRecvFromCrossDiagonal_(
MYROW(grid_),ksup) &&
MYCOL(grid_)==
PCOL(ksup,grid_))?count-1:count); }
708 void GetEtree(std::vector<Int> & etree_supno );
892 void GetColumn ( Int colIdx,
NumVec<T>& col );
944 inline int IdxToTag(Int lidx, Int tag) {
return SELINV_TAG_COUNT*(lidx)+(tag);}
955 #endif //_PEXSI_PSELINV_HPP_
virtual void PreSelInv()
PreSelInv prepares the structure in L_ and U_ so that SelInv only involves matrix-matrix multiplicati...
Definition: pselinv_impl.hpp:2668
Int blockIdx
Block index (supernodal index)
Definition: pselinv.hpp:214
void PMatrixToDistSparseMatrix(DistSparseMatrix< T > &A)
PMatrixToDistSparseMatrix converts the PMatrix into a distributed compressed sparse column matrix for...
Definition: pselinv_impl.hpp:3129
void SelInvIntra_P2p(Int lidx)
SelInvIntra_P2p.
Definition: pselinv_impl.hpp:1202
A thin interface for passing parameters to set the SuperLU options.
Definition: superlu_dist_internal.hpp:62
std::vector< LBlock< T > > & L(Int jLocal)
L returns the vector of nonzero L blocks for the local block column jLocal.
Definition: pselinv.hpp:673
SuperNodeType describes mapping between supernode and column, the permutation information, and potentially the elimination tree (not implemented here).
Definition: pselinv.hpp:143
Interface with SuperLU_Dist (version 3.0 and later)
void GetNegativeInertia(Real &inertia)
GetNegativeInertia computes the negative inertia of a PMatrix. This can be used to estimate e...
Int PROW(Int bnum, const GridType *g)
PROW returns the processor row that the bnum-th block (supernode) belongs to.
Definition: pselinv.hpp:270
Thin interface to LAPACK.
Int numRow
Number of nonzero rows.
Definition: pselinv.hpp:165
void UnpackData(SuperNodeBufferType &snode, std::vector< LBlock< T > > &LcolRecv, std::vector< UBlock< T > > &UrowRecv)
UnpackData.
Definition: pselinv_impl.hpp:965
Int MYPROC(const GridType *g)
MYPROC returns the current processor rank.
Definition: pselinv.hpp:257
Int NumLocalBlockCol() const
NumLocalBlockCol returns the total number of block columns.
Definition: pselinv.hpp:644
Int PCOL(Int bnum, const GridType *g)
PCOL returns the processor column that the bnum-th block (supernode) belongs to.
Definition: pselinv.hpp:275
Int LBi(Int bnum, const GridType *g)
LBi returns the local block number on the processor at processor row PROW( bnum, g )...
Definition: pselinv.hpp:285
Int SuperSize(Int bnum, const SuperNodeType *s)
SuperSize returns the size of the block bnum.
Definition: pselinv.hpp:326
Int LBj(Int bnum, const GridType *g)
LBj returns the local block number on the processor at processor column PCOL( bnum, g ).
Definition: pselinv.hpp:290
Int GBj(Int jLocal, const GridType *g)
GBj returns the global block number from a local block number in the column direction.
Definition: pselinv.hpp:300
Int numCol
Number of nonzero columns.
Definition: pselinv.hpp:168
Int NumCol(const SuperNodeType *s)
NumCol returns the total number of columns for a supernodal partiiton.
Definition: pselinv.hpp:335
Definition: pselinv.hpp:569
Int CountRecvFromCrossDiagonal(Int ksup)
CountRecvFromCrossDiagonal returns the number of cross diagonal processors with which current process...
Definition: pselinv.hpp:701
void GetDiagonal(NumVec< T > &diag)
GetDiagonal extracts the diagonal elements of the PMatrix.
Definition: pselinv_impl.hpp:3071
std::vector< std::vector< int > > & WorkingSet()
WorkingSet returns the ordered list of supernodes which could be done in parallel.
Definition: pselinv.hpp:681
Implementation of the parallel SelInv.
void GetWorkSet(std::vector< Int > &snodeEtree, std::vector< std::vector< Int > > &WSet)
GetWorkSet.
Definition: pselinv_impl.hpp:1125
Int FirstBlockRow(Int bnum, const SuperNodeType *s)
FirstBlockRow returns the first column of a block bnum. Note: the functionality of FirstBlockRow is e...
Definition: pselinv.hpp:321
Definition: pselinv.hpp:82
void GetEtree(std::vector< Int > &etree_supno)
GetEtree computes the supernodal elimination tree to be used later in the pipelined selected inversio...
Definition: pselinv_impl.hpp:1058
const GridType * Grid() const
Grid returns the GridType structure of the current PMatrix.
Definition: pselinv.hpp:665
LBlock stores a nonzero block in the lower triangular part or the diagonal part in PSelInv...
Definition: pselinv.hpp:159
Int PNUM(Int i, Int j, const GridType *g)
PNUM returns the processor rank that the bnum-th block (supernode) belongs to.
Definition: pselinv.hpp:280
virtual void ConstructCommunicationPattern()
ConstructCommunicationPattern constructs the communication pattern to be used later in the selected i...
Definition: pselinv_impl.hpp:1942
Sparse matrix and Distributed sparse matrix in compressed column format.
void ConstructCommunicationPattern_P2p()
ConstructCommunicationPattern_P2p constructs the communication pattern to be used later in the select...
Definition: pselinv_impl.hpp:1950
Int GBi(Int iLocal, const GridType *g)
GBi returns the global block number from a local block number in the row direction.
Definition: pselinv.hpp:295
GridType is the PSelInv way of defining the grid.
Definition: pselinv.hpp:106
Interface with MPI to facilitate communication.
Int MYCOL(const GridType *g)
MYCOL returns my processor column.
Definition: pselinv.hpp:265
Int CountSendToCrossDiagonal(Int ksup)
CountSendToCrossDiagonal returns the number of cross diagonal processors with which current processor...
Definition: pselinv.hpp:697
Int NumLocalBlockRow() const
NumLocalBlockRow returns the total number of block rows.
Definition: pselinv.hpp:647
Various utility subroutines.
const SuperNodeType * SuperNode() const
SuperNode returns the supernodal partition of the current PMatrix.
Definition: pselinv.hpp:669
static PMatrix< T > * Create(const GridType *pGridType, const SuperNodeType *pSuper, const SuperLUOptions *pLuOpt)
Create is a factory method which returns a pointer to a new PMatrix.
Definition: pselinv_impl.hpp:4158
IntNumVec rows
Dimension numRow * 1, index (0-based) for the number of nonzero rows.
Definition: pselinv.hpp:171
Int numCol
Number of nonzero columns.
Definition: pselinv.hpp:220
UBlock stores a nonzero block in the upper triangular part in PSelInv.
Definition: pselinv.hpp:211
std::vector< UBlock< T > > & U(Int iLocal)
U returns the vector of nonzero U blocks for the local block row iLocal.
Definition: pselinv.hpp:677
Int FirstBlockCol(Int bnum, const SuperNodeType *s)
FirstBlockCol returns the first column of a block bnum.
Definition: pselinv.hpp:314
Int NnzLocal()
NnzLocal computes the number of nonzero elements (L and U) saved locally.
Definition: pselinv_impl.hpp:4042
Int blockIdx
Block index (supernodal index)
Definition: pselinv.hpp:162
PMatrix contains the main data structure and the computational routine for the parallel selected inve...
Definition: ngchol_interf.hpp:57
void SendRecvCD_UpdateU(std::vector< SuperNodeBufferType > &arrSuperNodes, Int stepSuper)
SendRecvCD_UpdateU.
Definition: pselinv_impl.hpp:742
Int BlockIdx(Int i, const SuperNodeType *s)
BlockIdx returns the block index of a column i.
Definition: pselinv.hpp:309
Int numRow
Number of nonzero rows.
Definition: pselinv.hpp:217
Int CountSendToRight(Int ksup)
CountSendToRight returns the number of processors to the right of current processor with which it has...
Definition: pselinv.hpp:685
Int CountSendToBelow(Int ksup)
CountSendToBelow returns the number of processors below current processor with which it has to commun...
Definition: pselinv.hpp:689
Int CEILING(Int a, Int b)
CEILING is used for computing the storage space for local number of blocks.
Definition: pselinv.hpp:305
NumMat< T > nzval
Dimension numRow * numCol, nonzero elements.
Definition: pselinv.hpp:226
Int NumSuper(const SuperNodeType *s)
NumSuper returns the total number of supernodes.
Definition: pselinv.hpp:330
void SelInv_P2p()
Point-to-point version of the selected inversion.
Definition: pselinv_impl.hpp:2633
Int CountRecvFromBelow(Int ksup)
CountRecvFromBelow returns the number of processors below the current processor from which it receive...
Definition: pselinv.hpp:693
Int NumBlockL(Int jLocal) const
NumBlockL returns the number of nonzero L blocks for the local block column jLocal.
Definition: pselinv.hpp:658
NumMat< T > nzval
Dimension numRow * numCol, nonzero elements.
Definition: pselinv.hpp:175
IntNumVec cols
Dimension numRow * 1, index (0-based) for the number of nonzero rows.
Definition: pselinv.hpp:223
Int NumBlockU(Int iLocal) const
NumBlockU returns the number of nonzero U blocks for the local block row iLocal.
Definition: pselinv.hpp:662
virtual void SelInv()
SelInv is the main function for the selected inversion.
Definition: pselinv_impl.hpp:2608
LongInt Nnz()
Nnz computes the total number of nonzero elements in the PMatrix.
Definition: pselinv_impl.hpp:4073
void SelInv_lookup_indexes(SuperNodeBufferType &snode, std::vector< LBlock< T > > &LcolRecv, std::vector< UBlock< T > > &UrowRecv, NumMat< T > &AinvBuf, NumMat< T > &UBuf)
SelInv_lookup_indexes.
Definition: pselinv_impl.hpp:385
void PMatrixToDistSparseMatrix2(const DistSparseMatrix< T > &A, DistSparseMatrix< T > &B)
PMatrixToDistSparseMatrix2 is a more efficient version which performs the same job as PMatrixToDistSp...
Definition: pselinv_impl.hpp:3732
void ComputeDiagUpdate(SuperNodeBufferType &snode)
ComputeDiagUpdate.
Definition: pselinv_impl.hpp:1019
DistSparseMatrix describes a Sparse matrix in the compressed sparse column format (CSC) and distribut...
Definition: sparse_matrix.hpp:91
Int MYROW(const GridType *g)
MYROW returns my processor row.
Definition: pselinv.hpp:261