IPCC  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CMatrixOperation Class Reference

This class include matrix operations, matrix data type and related data. More...

#include "MatrixOperation.h"

Collaboration diagram for CMatrixOperation:
Collaboration graph

Classes

class  CCSR
 Data and operation representation of CSR(Compressed Sparse Row) More...
 
class  CDMatrix
 Data and operation representation of Matrix. More...
 
struct  CSR_ELEMENT_DATA
 CSR element data. More...
 
class  CVector
 This class for describing vector for Lanczos method. More...
 
struct  FILL_MATRIX_DATA
 Hamiltonian building data. More...
 

Public Types

typedef std::vector< double > double_vector_t
 
typedef std::vector< unsigned int > uint_vector_t
 
typedef struct
CMatrixOperation::CSR_ELEMENT_DATA
LPCSR_ELEMENT_DATA
 
typedef struct
CMatrixOperation::FILL_MATRIX_DATA
LPFILL_MATRIX_DATA
 

Public Member Functions

 CMatrixOperation ()
 Constructor. More...
 
 ~CMatrixOperation ()
 Destructor. More...
 

Static Public Member Functions

static CMatrixOperation::CCSRBuildCSRFromOneDimArray (double *pReal, double *pImaginary, unsigned int nRowOrder, unsigned int nColumnOrder)
 Building CSR from one dimension array. More...
 
static CMatrixOperation::CCSRBuildCSRFromFileTemp (FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
 Building CSR from file using double, double, double, double order. More...
 
static CMatrixOperation::CCSRBuildCSRFromFile_ (FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
 Building CSR from file using int, int, double, double order. More...
 
static CMatrixOperation::CCSRBuildCSRFromFileUnsortdata (FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
 uilding CSR form file and before building CSR sorting data More...
 
static void FreeCSR (CMatrixOperation::CCSR *pCSR)
 Deallocating CSR memory. More...
 
static void DumpCSR (CMatrixOperation::CCSR *pCSR, const char *pstrFileName)
 For dubugging save CSR information into file. More...
 
static void AllocateLocalCSR (CMatrixOperation::CCSR **mine, CMatrixOperation::CCSR **left, CMatrixOperation::CCSR **right, int nLBIndex)
 
static void FreeLocalCSR (CMatrixOperation::CCSR *mine, CMatrixOperation::CCSR *left, CMatrixOperation::CCSR *right)
 
static void BuildLocalCSR (CMatrixOperation::CCSR *source, CMatrixOperation::CCSR *mine, CMatrixOperation::CCSR *left, CMatrixOperation::CCSR *right)
 
static void UpdateLocalCSR (CMatrixOperation::CCSR *source, CMatrixOperation::CCSR *mine, CMatrixOperation::CCSR *left, CMatrixOperation::CCSR *right)
 
static int Compare (const void *pA, const void *pB)
 For qick sort compare operation. More...
 
static void MVMulEx_AsyncCommWithLocalBlocks (CMatrixOperation::CCSR *mylocalblock, CMatrixOperation::CCSR *leftlocalblock, CMatrixOperation::CCSR *rightlocalblock, CVector *pVector, CVector *pResult, double *X, double *Xrt, double *Xlt)
 Matrix and vector multiple operation using by block csr. More...
 
static void MVMulOptimal (CCSR *pAMatrix, CVector *pVector, CVector *pResult, int nLBIndex)
 Matrix and vector multiple operation for multiple call. More...
 
static void MVMulEx_Optimal (CCSR *pAMatrix, CVector *pVector, CVector *pResult, unsigned int, unsigned int, CVector *, int nSizePHI, int nLBIndex)
 Matrix and vector multiple operation for 1 layer exchanging communication. More...
 
static void MVMulOptimal_Nooffload (CCSR *pAMatrix, CVector *pVector, CVector *pResult, int nLBIndex)
 Added by jhkang end. More...
 
static void MVMul (CCSR *pAMatrix, CVector *pVector, CVector *pResult, int nLBIndex)
 Matrix and vector multiple operation. More...
 
static bool VVDot (CVector *pVector1, CVector *pVector2, CComplex *pResult)
 Between vectors dot product operation. More...
 
static void MVMul (CDMatrix *pMatrix, CVector *pVector, CVector *pResult)
 Matrix and vector multiple operation for dense matrix. More...
 
static void MMMul (CDMatrix *pMatrix, CDMatrix *pMatrixOperand, CDMatrix *pResult)
 Matrix and matrix multiple operation. More...
 
static bool IsSame (double operand1, double operand2, double tol)
 Compare two double variable. More...
 
static bool IsSameA (double operand1, double operand2, double tol)
 Compare two double variable. More...
 
static bool IsSame (CComplex operand1, CComplex operand2, double tol)
 Compare two vectors with tolerance. More...
 
static bool IsSame (CVector *pVector1, CVector *pVector2)
 Compare two vectors with general tolerance(1e-8) More...
 
static int Gram_schmidt (CVector *pVect1, CVector *pVect2)
 Added by jhkang, matrix operation. More...
 
static void AddVectors (CVector *pVector1, CVector *pVector2, CVector *pResult)
 
static void SubstractVectors (CVector *pVector1, CVector *pVector2, CVector *pResult)
 
static void ScalarMulVectors (double fValue, CVector *pVector1, CVector *pResult)
 Added by jhkang end. More...
 

Static Public Attributes

static CComplexpValueBuffer = NULL
 For MPI Optimized operation using. More...
 
static unsigned int * pRow = NULL
 For MPI Optimized operation using. More...
 
static unsigned int * pColumn = NULL
 For MPI Optimized operation using. More...
 

Detailed Description

This class include matrix operations, matrix data type and related data.

Date
27/May/2014

Definition at line 22 of file MatrixOperation.h.

Member Typedef Documentation

typedef std::vector<double> CMatrixOperation::double_vector_t

Definition at line 26 of file MatrixOperation.h.

typedef std::vector<unsigned int> CMatrixOperation::uint_vector_t

Definition at line 29 of file MatrixOperation.h.

Constructor & Destructor Documentation

CMatrixOperation::CMatrixOperation ( )

Constructor.


        CCSR Class member function - End

        CMatrixOperation Class member function - End

Definition at line 1836 of file MatrixOperation.cpp.

1837 {
1838 }
CMatrixOperation::~CMatrixOperation ( )

Destructor.

Definition at line 1840 of file MatrixOperation.cpp.

1841 {
1842 }

Member Function Documentation

void CMatrixOperation::AddVectors ( CVector pVector1,
CVector pVector2,
CVector pResult 
)
static

Definition at line 3297 of file MatrixOperation.cpp.

References ERROR_WRONG_ORDER_OPERATION, CMatrixOperation::CVector::GetAt(), CMatrixOperation::CVector::GetSize(), and CMatrixOperation::CVector::SetAt().

3298 {
3299  unsigned int nSize = pVector1->GetSize();
3300  if (nSize != pVector2->GetSize())
3301  {
3303  }
3304 
3305  for (unsigned int i = 0; i < nSize; i++)
3306  {
3307  pResult->SetAt(i, pVector1->GetAt(i) + pVector2->GetAt(i));
3308  }
3309 }
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: Global.h:64

Here is the call graph for this function:

void CMatrixOperation::AllocateLocalCSR ( CMatrixOperation::CCSR **  mine,
CMatrixOperation::CCSR **  left,
CMatrixOperation::CCSR **  right,
int  nLBIndex 
)
static

        CMatrixOperation Class member function - End

Parameters
mineLocal CSR buffer
leftLeft node CSR buffer
rightright node CSR buffer

Definition at line 2946 of file MatrixOperation.cpp.

References ERROR_MALLOC, CMPIManager::GetCurrentRank(), CMPIManager::GetLoadBalanceCount(), CMPIManager::GetMPIComm(), and CMPIManager::GetTotalNodeCount().

Referenced by CLanczosLaunching::LaunchingLanczos().

2947 {
2948  unsigned int nRowCount, nColumnCount;
2949  int myrank = CMPIManager::GetCurrentRank();
2950  int ncpus = CMPIManager::GetTotalNodeCount();
2951  int left_neighbor = (myrank-1+ncpus)%ncpus; // top neighbor
2952  int right_neighbor = (myrank+1)%ncpus; // bottom neighbor
2953  unsigned int temp;
2954 
2955  nRowCount = CMPIManager::GetLoadBalanceCount(myrank, nLBIndex);
2956  *mine = NULL; *left = NULL; *right = NULL;
2957 
2958  // Allocate mine
2959  *mine = new CMatrixOperation::CCSR();
2960  if (*mine == NULL)
2961  throw ERROR_MALLOC;
2962  nColumnCount = CMPIManager::GetLoadBalanceCount(myrank, nLBIndex);
2963  (*mine)->SetRowCount(nRowCount);
2964  (*mine)->SetColumnCount(nColumnCount);
2965  (*mine)->BuildDataBuffer(); temp = 0;
2966  for (int jj=0; jj<myrank; jj++)
2967  temp += CMPIManager::GetLoadBalanceCount(jj, nLBIndex);
2968  (*mine)->SetFirstRowIndex((double)temp); // FirstRowIndex will be used in a bit different way: Starting "column" index.
2969 
2970 // printf("%d %d %d %d %d %d\n", myrank, left_neighbor, right_neighbor, (int)(*mine)->GetFirstRowIndex(), (*mine)->GetColumnCount(), (*mine)->GetNoneZeroCount());
2971 
2972  // Allocate left
2973  *left = new CMatrixOperation::CCSR();
2974  if (*left == NULL)
2975  throw ERROR_MALLOC;
2976  nColumnCount = CMPIManager::GetLoadBalanceCount(left_neighbor, nLBIndex);
2977  (*left)->SetRowCount(nRowCount);
2978  (*left)->SetColumnCount(nColumnCount);
2979  (*left)->BuildDataBuffer(); temp = 0;
2980  for (int jj=0; jj<left_neighbor; jj++)
2981  temp += CMPIManager::GetLoadBalanceCount(jj, nLBIndex);
2982  (*left)->SetFirstRowIndex((double)temp); // FirstRowIndex will be used in a bit different way: Starting "column" index.
2983 
2984  //Allocate right
2985  *right = new CMatrixOperation::CCSR();
2986  if (*right == NULL)
2987  throw ERROR_MALLOC;
2988  nColumnCount = CMPIManager::GetLoadBalanceCount(right_neighbor, nLBIndex);
2989  (*right)->SetRowCount(nRowCount);
2990  (*right)->SetColumnCount(nColumnCount);
2991  (*right)->BuildDataBuffer(); temp = 0;
2992  for(int jj=0; jj<right_neighbor; jj++)
2993  temp += CMPIManager::GetLoadBalanceCount(jj, nLBIndex);
2994  (*right)->SetFirstRowIndex((double)temp); // FirstRowIndex will be used in a bit different way: Starting "column" index.
2995 
2996  MPI_Barrier(CMPIManager::GetMPIComm());
2997 }
static int GetLoadBalanceCount(int nRank, int nLBIndex)
Definition: MPIManager.cpp:168
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: Global.h:62
static int GetTotalNodeCount()
Definition: MPIManager.h:42
static int GetCurrentRank()
Definition: MPIManager.h:40
static MPI_Comm GetMPIComm()
Definition: MPIManager.h:64
Data and operation representation of CSR(Compressed Sparse Row)

Here is the call graph for this function:

Here is the caller graph for this function:

CMatrixOperation::CCSR * CMatrixOperation::BuildCSRFromFile_ ( FILE *  fDataFile,
unsigned int  nRowOrder,
unsigned int  nColumnOrder,
int  nDataCount 
)
static

Building CSR from file using int, int, double, double order.

Parameters
fDataFileSource file name
nRowOrderThe row order of matrix
nColumnOrderThe column order of matrix
nDataCountNonzero value count
Returns
CSR

Definition at line 1885 of file MatrixOperation.cpp.

References CMatrixOperation::CCSR::BuildDataBuffer(), CMatrixOperation::CCSR::FinishPush(), CMatrixOperation::CCSR::PushNoneZeroValue(), REPEAT_COUNT, CMatrixOperation::CCSR::SetColumnCount(), and CMatrixOperation::CCSR::SetRowCount().

1886 {
1888  size_t readSize;
1889  unsigned int i;
1891  memset(Data, NULL, sizeof(CMatrixOperation::CSR_ELEMENT_DATA)*REPEAT_COUNT);
1892 
1893  if (NULL == pCSR)
1894  return pCSR;
1895 
1896  pCSR->SetRowCount(nRowOrder);
1897  pCSR->SetColumnCount(nColumnOrder);
1898  pCSR->BuildDataBuffer();
1899 
1900  while (0 != (readSize = fread(Data, sizeof(CSR_ELEMENT_DATA), REPEAT_COUNT, fDataFile)))
1901  {
1902  for (i = 0; i < readSize; i++)
1903  {
1904  if (0 == Data[i].nRow && 0 == Data[i].nColumn)
1905  break;
1906 
1907  pCSR->PushNoneZeroValue(Data[i].fReal, Data[i].fImaginary, (unsigned int)Data[i].nRow - 1, (unsigned int)Data[i].nColumn - 1);
1908  }
1909  }
1910 
1911  pCSR->FinishPush();
1912 
1913  return pCSR;
1914 }
void SetColumnCount(unsigned int nColumn)
Settting column size of matrix.
void PushNoneZeroValue(double fRealValue, double fImaginaryValue, unsigned int nRow, unsigned int nCol)
Saving none zero value.
#define REPEAT_COUNT
void BuildDataBuffer()
Allocating memory for class member variable.
void SetRowCount(unsigned int nRow)
Settting row size of matrix.
void FinishPush()
Insert end index of none zero value index.
Data and operation representation of CSR(Compressed Sparse Row)

Here is the call graph for this function:

CMatrixOperation::CCSR * CMatrixOperation::BuildCSRFromFileTemp ( FILE *  fDataFile,
unsigned int  nRowOrder,
unsigned int  nColumnOrder,
int  nDataCount 
)
static

Building CSR from file using double, double, double, double order.

Parameters
fDataFileSource file name
nRowOrderThe row order of matrix
nColumnOrderThe column order of matrix
nDataCountNonzero value count
Returns
CSR

Definition at line 1853 of file MatrixOperation.cpp.

References CMatrixOperation::CCSR::BuildDataBuffer(), CMatrixOperation::CSR_ELEMENT_DATA::fImaginary, CMatrixOperation::CCSR::FinishPush(), CMatrixOperation::CSR_ELEMENT_DATA::fReal, CMatrixOperation::CSR_ELEMENT_DATA::nColumn, CMatrixOperation::CSR_ELEMENT_DATA::nRow, CMatrixOperation::CCSR::PushNoneZeroValue(), REPEAT_COUNT, CMatrixOperation::CCSR::SetColumnCount(), and CMatrixOperation::CCSR::SetRowCount().

1854 {
1856  size_t readSize;
1857  unsigned int i;
1859 
1860  if (NULL == pCSR)
1861  return pCSR;
1862 
1863  pCSR->SetRowCount(nRowOrder);
1864  pCSR->SetColumnCount(nColumnOrder);
1865  pCSR->BuildDataBuffer();
1866 
1867  while (0 != (readSize = fread(Data, sizeof(CSR_ELEMENT_DATA), REPEAT_COUNT, fDataFile)))
1868  {
1869  for (i = 0; i < readSize; i++)
1870  pCSR->PushNoneZeroValue(Data[i].fReal, Data[i].fImaginary, (unsigned int)Data[i].nRow - 1, (unsigned int)Data[i].nColumn - 1);
1871  }
1872 
1873  pCSR->FinishPush();
1874 
1875  return pCSR;
1876 }
void SetColumnCount(unsigned int nColumn)
Settting column size of matrix.
void PushNoneZeroValue(double fRealValue, double fImaginaryValue, unsigned int nRow, unsigned int nCol)
Saving none zero value.
#define REPEAT_COUNT
void BuildDataBuffer()
Allocating memory for class member variable.
void SetRowCount(unsigned int nRow)
Settting row size of matrix.
void FinishPush()
Insert end index of none zero value index.
Data and operation representation of CSR(Compressed Sparse Row)

Here is the call graph for this function:

CMatrixOperation::CCSR * CMatrixOperation::BuildCSRFromFileUnsortdata ( FILE *  fDataFile,
unsigned int  nRowOrder,
unsigned int  nColumnOrder,
int  nDataCount 
)
static

uilding CSR form file and before building CSR sorting data

Parameters
fDataFileSource file name
nRowOrderThe row order of matrix
nColumnOrderThe column order of matrix
nDataCountNonzero value count
Returns
CSR

Definition at line 1951 of file MatrixOperation.cpp.

References CMatrixOperation::CCSR::BuildDataBuffer(), Compare(), CMatrixOperation::CCSR::FinishPush(), CMatrixOperation::CCSR::PushNoneZeroValue(), CMatrixOperation::CCSR::SetColumnCount(), and CMatrixOperation::CCSR::SetRowCount().

1952 {
1953  LPCSR_ELEMENT_DATA lpData = (LPCSR_ELEMENT_DATA)malloc(sizeof(CSR_ELEMENT_DATA)* nDataCount);
1955  int i;
1956 
1957  if (lpData == NULL)
1958  return pCSR;
1959 
1960  for (i = 0; i < nDataCount; i++)
1961  {
1962  fread(&lpData[i], sizeof(CSR_ELEMENT_DATA), 1, fDataFile);
1963  }
1964 
1965  pCSR->SetRowCount(nRowOrder);
1966  pCSR->SetColumnCount(nColumnOrder);
1967  pCSR->BuildDataBuffer();
1968 
1969  qsort(lpData, nDataCount, sizeof(CSR_ELEMENT_DATA), CMatrixOperation::Compare);
1970 
1971  for (i = 0; i < nDataCount; i++)
1972  {
1973  pCSR->PushNoneZeroValue(lpData[i].fReal, lpData[i].fImaginary, (unsigned int)lpData[i].nRow - 1, (unsigned int)lpData[i].nColumn - 1);
1974  }
1975  pCSR->FinishPush();
1976 
1977  return pCSR;
1978 
1979 }
void SetColumnCount(unsigned int nColumn)
Settting column size of matrix.
void PushNoneZeroValue(double fRealValue, double fImaginaryValue, unsigned int nRow, unsigned int nCol)
Saving none zero value.
void BuildDataBuffer()
Allocating memory for class member variable.
struct CMatrixOperation::CSR_ELEMENT_DATA * LPCSR_ELEMENT_DATA
void SetRowCount(unsigned int nRow)
Settting row size of matrix.
void FinishPush()
Insert end index of none zero value index.
Data and operation representation of CSR(Compressed Sparse Row)
static int Compare(const void *pA, const void *pB)
For qick sort compare operation.

Here is the call graph for this function:

CMatrixOperation::CCSR * CMatrixOperation::BuildCSRFromOneDimArray ( double *  pReal,
double *  pImaginary,
unsigned int  nRowOrder,
unsigned int  nColumnOrder 
)
static

Building CSR from one dimension array.

Parameters
pRealReal number part of Source of matrix
pImaginaryImaginary number part of Source of matrix
nRowOrderThe row order of matrix
nColumnOrderThe column order of matrix
Returns
CSR

Definition at line 1987 of file MatrixOperation.cpp.

References CMatrixOperation::CCSR::BuildDataBuffer(), CMatrixOperation::CCSR::FinishPush(), CMatrixOperation::CCSR::PushNoneZeroValue(), CMatrixOperation::CCSR::SetColumnCount(), and CMatrixOperation::CCSR::SetRowCount().

1988 {
1989  unsigned int row, col;
1991 
1992  if (NULL == pCSR)
1993  return pCSR;
1994 
1995  pCSR->SetRowCount(nRowOrder);
1996  pCSR->SetColumnCount(nColumnOrder);
1997  pCSR->BuildDataBuffer();
1998 
1999  unsigned int nIndex = 0;
2000  bool bPushedInRow = false;
2001  for (row = 0; row < nRowOrder; row++)
2002  {
2003  for (col = 0; col < nColumnOrder; col++)
2004  {
2005  if (0 != pReal[row*nColumnOrder + col] || 0 != pImaginary[row*nColumnOrder + col])
2006  {
2007  pCSR->PushNoneZeroValue(pReal[nIndex], pImaginary[nIndex], row, col);
2008  bPushedInRow = true;
2009  }
2010  nIndex++;
2011  }
2012  }
2013  pCSR->FinishPush();
2014 
2015  return pCSR;
2016 }
void SetColumnCount(unsigned int nColumn)
Settting column size of matrix.
void PushNoneZeroValue(double fRealValue, double fImaginaryValue, unsigned int nRow, unsigned int nCol)
Saving none zero value.
void BuildDataBuffer()
Allocating memory for class member variable.
void SetRowCount(unsigned int nRow)
Settting row size of matrix.
void FinishPush()
Insert end index of none zero value index.
Data and operation representation of CSR(Compressed Sparse Row)

Here is the call graph for this function:

void CMatrixOperation::BuildLocalCSR ( CMatrixOperation::CCSR source,
CMatrixOperation::CCSR mine,
CMatrixOperation::CCSR left,
CMatrixOperation::CCSR right 
)
static
Parameters
sourceCopying source CSR
mineLocal CSR buffer
leftLeft node CSR buffer
rightright node CSR buffer

Definition at line 3005 of file MatrixOperation.cpp.

References CMatrixOperation::CCSR::FinishPush(), CMatrixOperation::CCSR::GetColumnCount(), CMatrixOperation::CCSR::GetFirstRowIndex(), CComplex::GetImaginaryNumber(), CComplex::GetRealNumber(), CMatrixOperation::CCSR::GetRowCount(), CMatrixOperation::CCSR::GetValue(), CMatrixOperation::CCSR::m_vectColumn, CMatrixOperation::CCSR::m_vectRow, pColumn, pRow, and CMatrixOperation::CCSR::PushNoneZeroValue().

Referenced by CLanczosLaunching::LaunchingLanczos().

3006 {
3007  CMatrixOperation::pRow = source->m_vectRow.data();
3008  CMatrixOperation::pColumn = source->m_vectColumn.data();
3009  //CKNMemoryManager::LPVECTOR_ELEMENTS lpMatrixValueElement = NULL;
3010  CComplex *pData = NULL;
3011  unsigned int my_nnz, left_nnz, right_nnz;
3012  int isthisrowfilled;
3013 
3014  //lpMatrixValueElement = source->GetValueElement();
3015 
3016  // 1. Build left local block.
3017 
3018  left_nnz = 0;
3019 
3020  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
3021  {
3022  isthisrowfilled = -1;
3023  unsigned int nSubStart = CMatrixOperation::pRow[ii], nSubEnd = CMatrixOperation::pRow[ii + 1];
3024  unsigned int startColIndex = (int)left->GetFirstRowIndex(), endColIndex = startColIndex + left->GetColumnCount() - 1;
3025 
3026  for (unsigned int jj = nSubStart; jj < nSubEnd; jj++)
3027  {
3028  unsigned int nColIndex = CMatrixOperation::pColumn[jj];
3029 
3030  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
3031  {
3032  isthisrowfilled = 0;
3033  left_nnz++;
3034  pData = source->GetValue(jj);
3035  //left->PushNoneZeroValue(lpMatrixValueElement->pfReal[jj], lpMatrixValueElement->pfImaginary[jj], ii, nColIndex-startColIndex);
3036  left->PushNoneZeroValue(pData->GetRealNumber(), pData->GetImaginaryNumber(), ii, nColIndex-startColIndex);
3037  }
3038  }
3039 
3040  if(isthisrowfilled == -1)
3041  {
3042  left_nnz++;
3043  left->PushNoneZeroValue(0.0, 0.0, ii, 0);
3044  }
3045  }
3046 
3047  left->FinishPush();
3048 
3049 // if(CMPIManager::IsRootRank())
3050 // printf("Left block conversion completed: left_nnz = %d (computed), %d (CSR-allocated)\n", left_nnz, left->GetNoneZeroCount());
3051 
3052  // 2. Build right block
3053 
3054  right_nnz = 0;
3055 
3056  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
3057  {
3058  isthisrowfilled = -1;
3059  unsigned int nSubStart = CMatrixOperation::pRow[ii], nSubEnd = CMatrixOperation::pRow[ii + 1];
3060  unsigned int startColIndex = (int)right->GetFirstRowIndex(), endColIndex = startColIndex + right->GetColumnCount() - 1;
3061 
3062  for (unsigned int jj = nSubStart; jj < nSubEnd; jj++)
3063  {
3064  unsigned int nColIndex = CMatrixOperation::pColumn[jj];
3065  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
3066  {
3067  isthisrowfilled = 0;
3068  right_nnz++;
3069  pData = source->GetValue(jj);
3070  //right->PushNoneZeroValue(lpMatrixValueElement->pfReal[jj], lpMatrixValueElement->pfImaginary[jj], ii, nColIndex-startColIndex);
3071  right->PushNoneZeroValue(pData->GetRealNumber(), pData->GetImaginaryNumber(), ii, nColIndex-startColIndex);
3072  }
3073  }
3074 
3075  if(isthisrowfilled == -1)
3076  {
3077  right_nnz++;
3078  right->PushNoneZeroValue(0.0, 0.0, ii, 0);
3079  }
3080  }
3081 
3082  right->FinishPush();
3083 
3084 // if(CMPIManager::IsRootRank())
3085 // printf("Right block conversion completed: right_nnz = %d (computed), %d (CSR-allocated)\n", right_nnz, right->GetNoneZeroCount());
3086 
3087  // 3. Build my block
3088 
3089  my_nnz = 0;
3090 
3091  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
3092  {
3093  unsigned int nSubStart = CMatrixOperation::pRow[ii], nSubEnd = CMatrixOperation::pRow[ii + 1];
3094  unsigned int startColIndex = (int)mine->GetFirstRowIndex(), endColIndex = startColIndex + mine->GetColumnCount() - 1;
3095 
3096  for(unsigned int jj = nSubStart; jj < nSubEnd; jj++)
3097  {
3098  unsigned int nColIndex = CMatrixOperation::pColumn[jj];
3099  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
3100  {
3101  my_nnz++;
3102  pData = source->GetValue(jj);
3103  //mine->PushNoneZeroValue(lpMatrixValueElement->pfReal[jj], lpMatrixValueElement->pfImaginary[jj], ii, nColIndex-startColIndex);
3104  mine->PushNoneZeroValue(pData->GetRealNumber(), pData->GetImaginaryNumber(), ii, nColIndex-startColIndex);
3105  }
3106  }
3107  }
3108 
3109  mine->FinishPush();
3110 
3111 // if(CMPIManager::IsRootRank())
3112 // printf("My block conversion completed: my_nnz = %d (computed), %d (CSR-allocated)\n", my_nnz, mine->GetNoneZeroCount());
3113 
3114 }
unsigned int GetRowCount()
static unsigned int * pColumn
For MPI Optimized operation using.
void PushNoneZeroValue(double fRealValue, double fImaginaryValue, unsigned int nRow, unsigned int nCol)
Saving none zero value.
CComplex * GetValue(unsigned int nIndex)
Getting none zero element value by index.
unsigned int GetColumnCount()
Getting row size of matrix.
This class for complex operation and saving value.
Definition: Complex.h:16
double GetFirstRowIndex()
Set first row index.
static unsigned int * pRow
For MPI Optimized operation using.
double GetImaginaryNumber() const
Get imaginary part.
Definition: Complex.h:25
void FinishPush()
Insert end index of none zero value index.
uint_vector_t m_vectColumn
A member variable for saving column information.
uint_vector_t m_vectRow
A member variable for saving row information.
double GetRealNumber() const
Get real part.
Definition: Complex.h:24

Here is the call graph for this function:

Here is the caller graph for this function:

int CMatrixOperation::Compare ( const void *  pA,
const void *  pB 
)
static

For qick sort compare operation.

Parameters
pACompare target CSR element
pBCompare target CSR element
Returns
Comparing result

Definition at line 1921 of file MatrixOperation.cpp.

References CMatrixOperation::CSR_ELEMENT_DATA::nColumn, and CMatrixOperation::CSR_ELEMENT_DATA::nRow.

Referenced by BuildCSRFromFileUnsortdata().

1922 {
1925 
1926  if (lpA->nRow > lpB->nRow)
1927  return 1;
1928  else if (lpA->nRow < lpB->nRow)
1929  return -1;
1930 
1931  if (lpA->nRow == lpB->nRow)
1932  {
1933  if (lpA->nColumn > lpB->nColumn)
1934  return 1;
1935  else if (lpA->nColumn < lpB->nColumn)
1936  return -1;
1937  else if (lpB->nColumn == lpB->nColumn)
1938  return 0;
1939  }
1940 
1941  return -1;
1942 }
struct CMatrixOperation::CSR_ELEMENT_DATA * LPCSR_ELEMENT_DATA

Here is the caller graph for this function:

static void CMatrixOperation::DumpCSR ( CMatrixOperation::CCSR pCSR,
const char *  pstrFileName 
)
inlinestatic

For dubugging save CSR information into file.

Definition at line 247 of file MatrixOperation.h.

References CMatrixOperation::CCSR::DumpCSR().

Here is the call graph for this function:

void CMatrixOperation::FreeCSR ( CMatrixOperation::CCSR pCSR)
static

Deallocating CSR memory.

Parameters
pCSRCSR class pointer that want to deallocating memeory

Definition at line 2138 of file MatrixOperation.cpp.

References CMatrixOperation::CCSR::Finalize().

Referenced by CTBMS_Solver::FinalEvn(), CSPLoop::Finalize(), and FreeLocalCSR().

2139 {
2140  if (NULL == pCSR)
2141  return;
2142 
2143  pCSR->Finalize();
2144 
2145  delete pCSR;
2146  pCSR = NULL;
2147 }
void Finalize()
Deallocating memory for member variable.

Here is the call graph for this function:

Here is the caller graph for this function:

void CMatrixOperation::FreeLocalCSR ( CMatrixOperation::CCSR mine,
CMatrixOperation::CCSR left,
CMatrixOperation::CCSR right 
)
static
Parameters
mineLocal CSR buffer
leftLeft node CSR buffer
rightright node CSR buffer

Definition at line 3238 of file MatrixOperation.cpp.

References FreeCSR().

Referenced by CLanczosLaunching::LaunchingLanczos().

3239 {
3240  if (mine != NULL)
3241  {
3243  mine = NULL;
3244  }
3245  if (left != NULL)
3246  {
3248  left = NULL;
3249  }
3250  if (right != NULL)
3251  {
3253  right = NULL;
3254  }
3255 }
static void FreeCSR(CMatrixOperation::CCSR *pCSR)
Deallocating CSR memory.

Here is the call graph for this function:

Here is the caller graph for this function:

int CMatrixOperation::Gram_schmidt ( CVector pVect1,
CVector pVect2 
)
static

Added by jhkang, matrix operation.

Doing gam schmidt orthogonalization

Parameters
pVect1Orthogonalization standard
pVect2Orthogonalization target

Definition at line 2880 of file MatrixOperation.cpp.

References GENERAL_TOLERANCE, CComplex::GetRealNumber(), IsSameA(), CTimeMeasurement::MeasurementEnd(), CTimeMeasurement::MeasurementStart(), CMatrixOperation::CVector::MinusVector(), CMatrixOperation::CVector::Normalize(), CMatrixOperation::CVector::ScalarMultiple(), CTimeMeasurement::VVDOT, and VVDot().

Referenced by CLanczosMethod::MergeDegeneratedEigenvalues().

2881 {
2882  CComplex result;
2883  CVector tempVector;
2884 
2886  CMatrixOperation::VVDot(pVect1, pVect2, &result);
2888  if( IsSameA(result.GetRealNumber(), 0, GENERAL_TOLERANCE ))
2889  return 1;
2890 
2891  tempVector = *pVect1;
2892  tempVector.Normalize(true);
2893  pVect2->Normalize(true);
2894 
2896  CMatrixOperation::VVDot(&tempVector, pVect2, &result);
2898  tempVector.ScalarMultiple(result);
2899 
2900  pVect2->MinusVector(&tempVector);
2901  pVect2->Normalize(true);
2902 
2904  CMatrixOperation::VVDot(pVect1, pVect2, &result);
2906  if( IsSameA(result.GetRealNumber(), 0, GENERAL_TOLERANCE ))
2907  return 1;
2908  else
2909  return 0;
2910 
2911 
2912 }
#define GENERAL_TOLERANCE
General tolerance definition.
Definition: Global.h:47
static void MeasurementEnd(MEASUREMENT_INDEX index)
Measurement end for part.
static void MeasurementStart(MEASUREMENT_INDEX index)
Measurement start for part.
static bool IsSameA(double operand1, double operand2, double tol)
Compare two double variable.
This class for complex operation and saving value.
Definition: Complex.h:16
static bool VVDot(CVector *pVector1, CVector *pVector2, CComplex *pResult)
Between vectors dot product operation.
double GetRealNumber() const
Get real part.
Definition: Complex.h:24

Here is the call graph for this function:

Here is the caller graph for this function:

bool CMatrixOperation::IsSame ( double  operand1,
double  operand2,
double  tol 
)
static

Compare two double variable.

Parameters
operand1First operand
operand2Second operand
tolDifference tolerance

Definition at line 2855 of file MatrixOperation.cpp.

Referenced by CLanczosMethod::DoResidualCheck(), CLanczosMethod::IntegrateEigenvalues(), CLanczosMethod::IntegrateEigenvaluesEx(), IsSame(), CSPLoop::MapZBandCB(), and CLanczosMethod::MergeDegeneratedEigenvalues().

2856 {
2857  if (fabs(operand1 - operand2) > tol)
2858  return false;
2859  else
2860  return true;
2861 }

Here is the caller graph for this function:

bool CMatrixOperation::IsSame ( CComplex  operand1,
CComplex  operand2,
double  tol 
)
static

Compare two vectors with tolerance.

Parameters
operand1Comparing operand 1
operand2Comparing operand 2
Returns
Comparing result

Definition at line 3262 of file MatrixOperation.cpp.

References CComplex::GetImaginaryNumber(), and CComplex::GetRealNumber().

3263 {
3264  if( fabs(fabs(operand1.GetRealNumber()) - fabs(operand2.GetRealNumber())) > tol )
3265  return false;
3266 
3267  if( fabs(fabs(operand1.GetImaginaryNumber()) - fabs(operand2.GetImaginaryNumber())) > tol )
3268  return false;
3269  else
3270  return true;
3271 }
double GetImaginaryNumber() const
Get imaginary part.
Definition: Complex.h:25
double GetRealNumber() const
Get real part.
Definition: Complex.h:24

Here is the call graph for this function:

bool CMatrixOperation::IsSame ( CVector pVector1,
CVector pVector2 
)
static

Compare two vectors with general tolerance(1e-8)

Added by jhkang, Vector operration.

Parameters
pVector1Comparing vector operand 1
pVector2Comparing vector operand 2
Returns
Comparing result

Definition at line 3278 of file MatrixOperation.cpp.

References GENERAL_TOLERANCE, CMatrixOperation::CVector::GetNorm(), IsSame(), and CMatrixOperation::CVector::MinusVector().

Here is the call graph for this function:

bool CMatrixOperation::IsSameA ( double  operand1,
double  operand2,
double  tol 
)
static

Compare two double variable.

Parameters
operand1First operand
operand2Second operand
tolDifference tolerance

Definition at line 2868 of file MatrixOperation.cpp.

Referenced by Gram_schmidt(), and CLanczosMethod::MergeDegeneratedEigenvalues().

2869 {
2870  if (fabs(fabs(operand1) - fabs(operand2)) > tol)
2871  return false;
2872  else
2873  return true;
2874 }

Here is the caller graph for this function:

void CMatrixOperation::MMMul ( CDMatrix pMatrix,
CDMatrix pMatrixOperand,
CDMatrix pResult 
)
static

Matrix and matrix multiple operation.

Parameters
pMatrixMatrix class pointer that want to operation
pMatrixOperandMatrix class pointer that want to operation
pResultMatrix class pointer that saving operation result

Definition at line 2824 of file MatrixOperation.cpp.

References CComplex::Add(), CMatrixOperation::CDMatrix::BuildMatrixFirst(), CMatrixOperation::CDMatrix::GetColumnCount(), CMatrixOperation::CDMatrix::GetElement(), CMatrixOperation::CDMatrix::GetRowCount(), CComplex::MulltiplyComplex(), and CMatrixOperation::CDMatrix::SetElement().

Referenced by CHamiltonianBuilder::BuildACCANeighborFor10Band(), CHamiltonianBuilder::FillMatrixFor10Band(), and CGeometricShape::RotateMatrix().

2825 {
2826  int i, j, k;
2827  int nRow, nColumn, nL;
2828  if (pMatrix->GetColumnCount() != pMatrixOperand->GetRowCount())
2829  return;
2830 
2831  pResult->BuildMatrixFirst(pMatrix->GetRowCount(), pMatrixOperand->GetColumnCount());
2832 
2833  nL = pMatrixOperand->GetColumnCount();
2834  nRow = pMatrix->GetRowCount();
2835  nColumn = pMatrix->GetColumnCount();
2836  for (k = 0; k < nL; ++k)
2837  {
2838  for (i = 0; i < nRow; ++i)
2839  {
2840  CComplex result;
2841  for (j = 0; j < nColumn; ++j)
2842  {
2843  result.Add(CComplex::MulltiplyComplex(pMatrix->GetElement(i, j), pMatrixOperand->GetElement(j, k)));
2844  }
2845  pResult->SetElement(i, k, result);
2846  }
2847  }
2848 }
static CComplex MulltiplyComplex(CComplex complex1, CComplex complex2)
Multiple operation between complex numbers.
Definition: Complex.cpp:126
void Add(CComplex complex)
Adding operation to this class.
Definition: Complex.cpp:67
This class for complex operation and saving value.
Definition: Complex.h:16

Here is the call graph for this function:

Here is the caller graph for this function:

void CMatrixOperation::MVMul ( CCSR pAMatrix,
CVector pVector,
CVector pResult,
int  nLBIndex 
)
static

Matrix and vector multiple operation.

Parameters
pAMatrixMatrix class pointer that want to operation
pVectorVector class pointer that want to operation
pResultVector class pointer that saving operation result

Definition at line 2187 of file MatrixOperation.cpp.

References ERROR_WRONG_ORDER_OPERATION, CMatrixOperation::CCSR::GetColumnCount(), CMatrixOperation::CCSR::GetRowCount(), CMatrixOperation::CCSR::m_vectColumn, CMatrixOperation::CCSR::m_vectRow, CMatrixOperation::CVector::m_vectValueImaginaryBuffer, CMatrixOperation::CCSR::m_vectValueImaginaryBuffer, CMatrixOperation::CVector::m_vectValueRealBuffer, CMatrixOperation::CCSR::m_vectValueRealBuffer, CMPIManager::MergeVector(), and CMatrixOperation::CVector::SetSize().

Referenced by CLanczosResultAudit::AuditResult_EV(), CLanczosMethod::DoResidualCheck(), CLanczosMethod::MergeDegeneratedEigenvalues(), IGeometricUnitCellInfo::RotateAxis(), IGeometricUnitCellInfo::RotateNeighbor(), and CHamiltonianBuilder::RotateTransMatrixFor10Band().

2188 {
2189  unsigned int i, j, nSize = pAMatrix->GetColumnCount();
2190  CVector *pOperandVector = NULL, VOperand;
2191  double *pMatrixReal = NULL, *pMatrixImaginary = NULL;
2192  double *pVectorReal = NULL, *pVectorImaginary = NULL;
2193  double *pResultReal = NULL, *pResultImaginary = NULL;
2194  unsigned int *pMatrixRow = NULL, *pMatrixColumn = NULL;
2195 
2196  VOperand = *pVector;
2197  pOperandVector = &VOperand;
2198 
2199 #ifndef DISABLE_MPI_ROUTINE
2200 
2201  VOperand.SetSize(pAMatrix->GetColumnCount());
2202  CMPIManager::MergeVector(pVector, &VOperand, pAMatrix->GetColumnCount(), nLBIndex);
2203  pOperandVector = &VOperand;
2204 #else
2205  pOperandVector = pVector;
2206 #endif
2207 
2208  if (nSize != pOperandVector->GetSize())
2209  {
2211  return;
2212  }
2213 
2214  nSize = pAMatrix->GetRowCount();
2215  pMatrixReal = pAMatrix->m_vectValueRealBuffer.data();
2216  pMatrixImaginary = pAMatrix->m_vectValueImaginaryBuffer.data();
2217  pMatrixRow = pAMatrix->m_vectRow.data();
2218  pMatrixColumn = pAMatrix->m_vectColumn.data();
2219  pVectorReal = pOperandVector->m_vectValueRealBuffer.data();
2220  pVectorImaginary = pOperandVector->m_vectValueImaginaryBuffer.data();
2221  pResultReal = pResult->m_vectValueRealBuffer.data();
2222  pResultImaginary = pResult->m_vectValueImaginaryBuffer.data();
2223 
2224  unsigned int input_real_size = pOperandVector->m_vectValueRealBuffer.size();
2225  unsigned int input_imaginary_size = pOperandVector->m_vectValueImaginaryBuffer.size();
2226  unsigned int output_real_size = pResult->m_vectValueRealBuffer.size();
2227  unsigned int output_imaginary_size = pResult->m_vectValueImaginaryBuffer.size();
2228 
2229  #pragma omp parallel for
2230  for ( i = 0; i < nSize; i++)
2231  {
2232  double real_sum = 0.0;
2233  double imaginary_sum = 0.0;
2234  const unsigned int nSubStart = pMatrixRow[i];
2235  const unsigned int nSubEnd = pMatrixRow[i + 1];
2236 
2237 
2238  for ( j = nSubStart; j < nSubEnd; j++)
2239  {
2240  const unsigned int nColIndex = pMatrixColumn[j];
2241  const double m_real = pMatrixReal[j];
2242  const double m_imaginary = pMatrixImaginary[j];
2243  const double v_real = pVectorReal[nColIndex];
2244  const double v_imaginary = pVectorImaginary[nColIndex];
2245 
2246  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2247  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2248  }
2249 
2250  pResultReal[i] = real_sum;
2251  pResultImaginary[i] = imaginary_sum;
2252  }
2253 #ifndef DISABLE_MPI_ROUTINE
2254  VOperand.Finalize();
2255 #endif //DISABLE_MPI_ROUTINE
2256 }
static void MergeVector(CMatrixOperation::CVector *pVector, CMatrixOperation::CVector *pResultVector, unsigned int nMergeSize, int nLBIndex)
Merge vector to sub rank.
Definition: MPIManager.cpp:241
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: Global.h:64

Here is the call graph for this function:

Here is the caller graph for this function:

void CMatrixOperation::MVMul ( CDMatrix pMatrix,
CVector pVector,
CVector pResult 
)
static

Matrix and vector multiple operation for dense matrix.

Parameters
pAMatrixMatrix class pointer that want to operation
pVectorVector class pointer that want to operation
pResultVector class pointer that saving operation result

Definition at line 2797 of file MatrixOperation.cpp.

References CComplex::Add(), CMatrixOperation::CVector::GetAt(), CMatrixOperation::CDMatrix::GetColumnCount(), CMatrixOperation::CDMatrix::GetElement(), CMatrixOperation::CDMatrix::GetRowCount(), CMatrixOperation::CVector::GetSize(), CComplex::MulltiplyComplex(), CMatrixOperation::CVector::SetAt(), and CMatrixOperation::CVector::SetSize().

2798 {
2799  int i, j, nRow, nColumn;
2800 
2801  if (pMatrix->GetColumnCount() != pVector->GetSize())
2802  return;
2803 
2804  pResult->SetSize(pVector->GetSize());
2805 
2806  nRow = pMatrix->GetRowCount();
2807  nColumn = pMatrix->GetColumnCount();
2808  for (i = 0; i < nRow; ++i)
2809  {
2810  CComplex result;
2811  for (j = 0; j < nColumn; ++j)
2812  {
2813  result.Add(CComplex::MulltiplyComplex(pMatrix->GetElement(i, j), pVector->GetAt(j)));
2814  }
2815  pResult->SetAt(i, result);
2816  }
2817 }
static CComplex MulltiplyComplex(CComplex complex1, CComplex complex2)
Multiple operation between complex numbers.
Definition: Complex.cpp:126
void Add(CComplex complex)
Adding operation to this class.
Definition: Complex.cpp:67
This class for complex operation and saving value.
Definition: Complex.h:16

Here is the call graph for this function:

void CMatrixOperation::MVMulEx_AsyncCommWithLocalBlocks ( CMatrixOperation::CCSR mylocalblock,
CMatrixOperation::CCSR leftlocalblock,
CMatrixOperation::CCSR rightlocalblock,
CVector pVector,
CVector pResult,
double *  X,
double *  Xrt,
double *  Xlt 
)
static

Matrix and vector multiple operation using by block csr.

Parameters
pAMatrixMatrix class pointer that want to operation
pVectorVector class pointer that want to operation
pResultVector class pointer that saving operation result
Remarks
This function optimized for multiple call than MVMul

Definition at line 2264 of file MatrixOperation.cpp.

2265 {
2266 /*
2267  unsigned int nSize, B, Brt, Blt;
2268  double *pMatrixValueReal = NULL, *pOperandVectorReal = NULL, *pResultVectorReal = NULL;
2269  double *pMatrixValueImaginary = NULL, *pOperandVectorImaginary = NULL, *pResultVectorImaginary = NULL;
2270  int tag = 1002;
2271  int myrank = CMPIManager::GetCurrentRank();
2272  int ncpus = CMPIManager::GetTotalNodeCount();
2273  int left_neighbor = (myrank - 1 + ncpus) % ncpus;
2274  int right_neighbor = (myrank + 1) % ncpus;
2275  MPI_Request req_sr[2];
2276  MPI_Status stat_sr[2];
2277  // XXX jinpil: pRow, pColumn should be local in offload directives
2278  unsigned int *pRow = mylocalblock->m_vectRow.data();
2279  unsigned int *pColumn = mylocalblock->m_vectColumn.data();
2280 
2281 #ifndef _WIN32
2282  __assume_aligned(X, 64);
2283  __assume_aligned(X, 64);
2284  __assume_aligned(Xrt, 64);
2285 
2286  __assume_aligned(pMatrixValueReal, 64);
2287  __assume_aligned(pMatrixValueImaginary, 64);
2288  __assume_aligned(pOperandVectorReal, 64);
2289  __assume_aligned(pOperandVectorImaginary, 64);
2290  __assume_aligned(pResultVectorReal, 64);
2291  __assume_aligned(pResultVectorImaginary, 64);
2292  __assume_aligned(pRow, 64);
2293  __assume_aligned(pColumn, 64);
2294 #endif //_WIN32
2295 
2296  pMatrixValueReal = mylocalblock->m_vectValueRealBuffer.data();
2297  pOperandVectorReal = pVector->m_vectValueRealBuffer.data();
2298  pResultVectorReal = pResult->m_vectValueRealBuffer.data();
2299 
2300  pMatrixValueImaginary = mylocalblock->m_vectValueImaginaryBuffer.data();
2301  pOperandVectorImaginary = pVector->m_vectValueImaginaryBuffer.data();
2302  pResultVectorImaginary = pResult->m_vectValueImaginaryBuffer.data();;
2303 
2304  nSize = mylocalblock->GetRowCount();
2305 
2306  if (nSize != pVector->GetSize())
2307  {
2308  throw ERROR_WRONG_ORDER_OPERATION;
2309  return;
2310  }
2311 
2312  B = nSize;
2313  Brt = 0;
2314  Blt = 0;
2315 
2316  for (int ii = 0; ii< nSize; ii++)
2317  {
2318  X[2 * ii] = pOperandVectorReal[ii];
2319  X[2 * ii + 1] = pOperandVectorImaginary[ii];
2320  }
2321 
2322  CTimeMeasurement::MeasurementStart(CTimeMeasurement::MV_COMM);
2323 
2324  MPI_Irecv(&Brt, 1, MPI_INT, right_neighbor, tag, CMPIManager::GetMPIComm(), &req_sr[0]);
2325  MPI_Isend(&B, 1, MPI_INT, left_neighbor, tag, CMPIManager::GetMPIComm(), &req_sr[1]);
2326  MPI_Waitall(2, req_sr, stat_sr); // now Brt has B of right neighbor.
2327 
2328  MPI_Irecv(Xrt, 2 * Brt, MPI_DOUBLE, right_neighbor, tag, CMPIManager::GetMPIComm(), &req_sr[0]); // receive from bottom neighbor
2329  MPI_Isend(X, 2 * B, MPI_DOUBLE, left_neighbor, tag, CMPIManager::GetMPIComm(), &req_sr[1]); // send to top neighbor
2330 
2331  CTimeMeasurement::MeasurementEnd(CTimeMeasurement::MV_COMM);
2332 
2333  unsigned int input_size = X_largest * 2;
2334  unsigned int output_real_size = pResult->m_vectValueRealBuffer.size();
2335  unsigned int output_imaginary_size = pResult->m_vectValueImaginaryBuffer.size();
2336 
2337 
2338 #ifdef _ENABLE_PAPI
2339  long long papi_values[4];
2340  PAPI_start(papi_event_set);
2341 #endif
2342 
2343 #pragma offload target(mic:phi_tid) \
2344  nocopy(*pMatrixValueReal : REUSE) \
2345  nocopy(*pMatrixValueImaginary : REUSE) \
2346  nocopy(*pRow : REUSE) \
2347  nocopy(*pColumn : REUSE) \
2348  in(X[0:input_size] : REUSE) \
2349  nocopy(*pResultVectorReal : REUSE) \
2350  nocopy(*pResultVectorImaginary : REUSE)
2351 
2352 #pragma omp parallel for
2353  for (unsigned int i = 0; i < nSize; i++)
2354  {
2355  double real_sum = 0.0;
2356  double imaginary_sum = 0.0;
2357  const unsigned int nSubStart = pRow[i ];
2358  const unsigned int nSubEnd = pRow[i + 1];
2359  for (unsigned int j = nSubStart; j < nSubEnd; j++)
2360  {
2361  const unsigned int nColIndex = pColumn[j];
2362  const double m_real = pMatrixValueReal[j];
2363  const double m_imaginary = pMatrixValueImaginary[j];
2364  const double v_real = X[2 * nColIndex];
2365  const double v_imaginary = X[2 * nColIndex + 1];
2366 
2367  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2368  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2369  }
2370 
2371  pResultVectorReal[i] = real_sum;
2372  pResultVectorImaginary[i] = imaginary_sum;
2373  }
2374 
2375 #ifdef _ENABLE_PAPI
2376  PAPI_stop(papi_event_set, papi_values);
2377  printf("[LOCAL] L2 access = %lld | L2 miss = %lld | L2 miss rate = %g %\n", papi_values[0], papi_values[1], (papi_values[1] * 100.0) / papi_values[0]);
2378  printf("[LOCAL] L3 access = %lld | L3 miss = %lld | L3 miss rate = %g %\n", papi_values[2], papi_values[3], (papi_values[3] * 100.0) / papi_values[2]);
2379 #endif
2380 
2381  CTimeMeasurement::MeasurementStart(CTimeMeasurement::MV_COMM);
2382 
2383  MPI_Waitall(2, req_sr, stat_sr); // now Xrt has X of right neighbor.
2384 
2385  MPI_Irecv(&Blt, 1, MPI_INT, left_neighbor, tag, CMPIManager::GetMPIComm(), &req_sr[0]);
2386  MPI_Isend(&B, 1, MPI_INT, right_neighbor, tag, CMPIManager::GetMPIComm(), &req_sr[1]);
2387  MPI_Waitall(2, req_sr, stat_sr); // now Blt has B of left neighbor.
2388 
2389 
2390  MPI_Irecv(Xlt, 2 * Blt, MPI_DOUBLE, left_neighbor, tag, CMPIManager::GetMPIComm(), &req_sr[0]);
2391  MPI_Isend(X, 2 * B, MPI_DOUBLE, right_neighbor, tag, CMPIManager::GetMPIComm(), &req_sr[1]);
2392 
2393  CTimeMeasurement::MeasurementEnd(CTimeMeasurement::MV_COMM);
2394 
2395  pMatrixValueReal = rightlocalblock->m_vectValueRealBuffer.data();
2396  pMatrixValueImaginary = rightlocalblock->m_vectValueImaginaryBuffer.data();
2397  pRow = rightlocalblock->m_vectRow.data();
2398  pColumn = rightlocalblock->m_vectColumn.data();
2399 
2400 #ifdef _ENABLE_PAPI
2401  PAPI_start(papi_event_set);
2402 #endif
2403 
2404 #pragma offload target(mic:phi_tid) \
2405  nocopy(*pMatrixValueReal : REUSE) \
2406  nocopy(*pMatrixValueImaginary : REUSE) \
2407  nocopy(*pRow : REUSE) \
2408  nocopy(*pColumn : REUSE) \
2409  in(Xrt[0:input_size] : REUSE) \
2410  nocopy(*pResultVectorReal : REUSE) \
2411  nocopy(*pResultVectorImaginary : REUSE)
2412 
2413 #pragma omp parallel for
2414  for (unsigned int i = 0; i < nSize; i++)
2415  {
2416  double real_sum = 0.0;
2417  double imaginary_sum = 0.0;
2418  const unsigned int nSubStart = pRow[i ];
2419  const unsigned int nSubEnd = pRow[i + 1];
2420  for (unsigned int j = nSubStart; j < nSubEnd; j++)
2421  {
2422  const unsigned int nColIndex = pColumn[j];
2423  const double m_real = pMatrixValueReal[j];
2424  const double m_imaginary = pMatrixValueImaginary[j];
2425  const double v_real = Xrt[2 * nColIndex];
2426  const double v_imaginary = Xrt[2 * nColIndex + 1];
2427 
2428  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2429  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2430  }
2431 
2432  pResultVectorReal[i] += real_sum;
2433  pResultVectorImaginary[i] += imaginary_sum;
2434  }
2435 
2436 #ifdef _ENABLE_PAPI
2437  PAPI_stop(papi_event_set, papi_values);
2438  printf("[RIGHT] L2 access = %lld | L2 miss = %lld | L2 miss rate = %g %\n", papi_values[0], papi_values[1], (papi_values[1] * 100.0) / papi_values[0]);
2439  printf("[RIGHT] L3 access = %lld | L3 miss = %lld | L3 miss rate = %g %\n", papi_values[2], papi_values[3], (papi_values[3] * 100.0) / papi_values[2]);
2440 #endif
2441 
2442  CTimeMeasurement::MeasurementStart(CTimeMeasurement::MV_COMM);
2443  MPI_Waitall(2, req_sr, stat_sr); // now Xlt has X of left neighbor.
2444  CTimeMeasurement::MeasurementEnd(CTimeMeasurement::MV_COMM);
2445 
2446  pMatrixValueReal = leftlocalblock->m_vectValueRealBuffer.data();
2447  pMatrixValueImaginary = leftlocalblock->m_vectValueImaginaryBuffer.data();
2448  pRow = leftlocalblock->m_vectRow.data();
2449  pColumn = leftlocalblock->m_vectColumn.data();
2450 
2451 #ifdef _ENABLE_PAPI
2452  PAPI_start(papi_event_set);
2453 #endif
2454 
2455 #pragma offload target(mic:phi_tid) \
2456  nocopy(*pMatrixValueReal : REUSE) \
2457  nocopy(*pMatrixValueImaginary : REUSE) \
2458  nocopy(*pRow : REUSE) \
2459  nocopy(*pColumn : REUSE) \
2460  in(Xlt[0:input_size] : REUSE) \
2461  out(pResultVectorReal[0:output_real_size] : REUSE) \
2462  out(pResultVectorImaginary[0:output_imaginary_size] : REUSE)
2463 
2464 #pragma omp parallel for
2465  for (unsigned int i = 0; i < nSize; i++)
2466  {
2467  double real_sum = 0.0;
2468  double imaginary_sum = 0.0;
2469  const unsigned int nSubStart = pRow[i ];
2470  const unsigned int nSubEnd = pRow[i + 1];
2471  for (unsigned int j = nSubStart; j < nSubEnd; j++)
2472  {
2473  const unsigned int nColIndex = pColumn[j];
2474  const double m_real = pMatrixValueReal[j];
2475  const double m_imaginary = pMatrixValueImaginary[j];
2476  const double v_real = Xlt[2 * nColIndex];
2477  const double v_imaginary = Xlt[2 * nColIndex + 1];
2478 
2479  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2480  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2481  }
2482 
2483  pResultVectorReal[i] += real_sum;
2484  pResultVectorImaginary[i] += imaginary_sum;
2485  }
2486 
2487 #ifdef _ENABLE_PAPI
2488  PAPI_stop(papi_event_set, papi_values);
2489  printf("[LEFT] L2 access = %lld | L2 miss = %lld | L2 miss rate = %g %\n", papi_values[0], papi_values[1], (papi_values[1] * 100.0) / papi_values[0]);
2490  printf("[LEFT] L3 access = %lld | L3 miss = %lld | L3 miss rate = %g %\n", papi_values[2], papi_values[3], (papi_values[3] * 100.0) / papi_values[2]);
2491 #endif
2492 */
2493 }
void CMatrixOperation::MVMulEx_Optimal ( CCSR pAMatrix,
CVector pVector,
CVector pResult,
unsigned int  nSizeFromPrevRank,
unsigned int  nSizeFromNextRank,
CVector VTemp,
int  nSizePHI,
int  nLBIndex 
)
static

Matrix and vector multiple operation for 1 layer exchanging communication.

Parameters
pAMatrixMatrix class pointer that want to operation
pVectorVector class pointer that want to operation
pResultVector class pointer that saving operation result
nSizeFromPrevRankExchanging size with previous node
nSizeFromNextRankExchanging size with next node
VTempMering buffer MVMul vector operand
nSizePHIRatio for MIC operation

Definition at line 2504 of file MatrixOperation.cpp.

References ERROR_WRONG_ORDER_OPERATION, CMatrixOperation::CCSR::GetColumnCount(), CMatrixOperation::CCSR::GetRowCount(), CMPIManager::GetTotalNodeCount(), CMatrixOperation::CCSR::m_fFirstRowIndex, CMatrixOperation::CCSR::m_vectColumn, CMatrixOperation::CCSR::m_vectRow, CMatrixOperation::CVector::m_vectValueImaginaryBuffer, CMatrixOperation::CCSR::m_vectValueImaginaryBuffer, CMatrixOperation::CVector::m_vectValueRealBuffer, CMatrixOperation::CCSR::m_vectValueRealBuffer, CMPIManager::MergeVectorEx_Optimal(), CMatrixOperation::CCSR::nComponentsFirstUnitCell, and CMatrixOperation::CCSR::nComponentsLastUnitCell.

Referenced by CLanczosMethod::LanczosIterationLoop().

2505 {
2506  unsigned int nSize = pAMatrix->GetColumnCount();
2507  CVector *pOperandVector = NULL;
2508  unsigned int offsettmp[3];
2509 
2510  double *pMatrixReal = NULL, *pMatrixImaginary = NULL;
2511  double *pVectorReal = NULL, *pVectorImaginary = NULL;
2512  double *pResultReal = NULL, *pResultImaginary = NULL;
2513  unsigned int *pMatrixRow = NULL, *pMatrixColumn = NULL;
2514 
2515 #ifdef USE_XEONPHI
2516  char phi_sigval;
2517  unsigned int phi_input_offset1, phi_input_offset2, phi_input_offset3;
2518  unsigned int phi_input_size1, phi_input_size2, phi_input_size3;
2519  unsigned int phi_output_size, phi_output_offset;
2520 #endif //USE_XEONPHI
2521 
2522 #ifndef DISABLE_MPI_ROUTINE
2523  pOperandVector = VTemp;
2524  CMPIManager::MergeVectorEx_Optimal(pVector, pOperandVector, pAMatrix->GetColumnCount(), pAMatrix->m_fFirstRowIndex, nSizeFromPrevRank, nSizeFromNextRank, pAMatrix->nComponentsFirstUnitCell, pAMatrix->nComponentsLastUnitCell, offsettmp, nLBIndex);
2525 #else
2526  pOperandVector = pVector;
2527 #endif
2528 
2529  if (nSize != pOperandVector->GetSize())
2530  {
2532  return;
2533  }
2534 
2535  pVectorReal = pOperandVector->m_vectValueRealBuffer.data();
2536  pVectorImaginary = pOperandVector->m_vectValueImaginaryBuffer.data();
2537  pMatrixReal = pAMatrix->m_vectValueRealBuffer.data();
2538  pMatrixImaginary = pAMatrix->m_vectValueImaginaryBuffer.data();
2539  pMatrixRow = pAMatrix->m_vectRow.data();
2540  pMatrixColumn = pAMatrix->m_vectColumn.data();
2541  pResultReal = pResult->m_vectValueRealBuffer.data();
2542  pResultImaginary = pResult->m_vectValueImaginaryBuffer.data();
2543 
2544  nSize = pAMatrix->GetRowCount();
2545 
2546 #ifdef USE_XEONPHI
2547  if (CMPIManager::GetTotalNodeCount() <= 3)
2548  {
2549  phi_input_size1 = pOperandVector->m_vectValueRealBuffer.size();
2550  phi_input_offset1 = 0;
2551 
2552 #pragma offload_transfer target(mic:phi_tid) in(pVectorReal[phi_input_offset1:phi_input_size1] : REUSE)
2553 #pragma offload_transfer target(mic:phi_tid) in(pVectorImaginary[phi_input_offset1:phi_input_size1] : REUSE)
2554  }
2555  else
2556  {
2557  phi_input_size1 = nSizeFromPrevRank;
2558  phi_input_size2 = nSize;
2559  phi_input_size3 = nSizeFromNextRank;
2560  phi_input_offset1 = offsettmp[0];
2561  phi_input_offset2 = offsettmp[1];
2562  phi_input_offset3 = offsettmp[2];
2563 
2564 #pragma offload_transfer target(mic:phi_tid) in(pVectorReal[phi_input_offset1:phi_input_size1] : REUSE)
2565 #pragma offload_transfer target(mic:phi_tid) in(pVectorImaginary[phi_input_offset1:phi_input_size1] : REUSE)
2566 #pragma offload_transfer target(mic:phi_tid) in(pVectorReal[phi_input_offset2:phi_input_size2] : REUSE)
2567 #pragma offload_transfer target(mic:phi_tid) in(pVectorImaginary[phi_input_offset2:phi_input_size2] : REUSE)
2568 #pragma offload_transfer target(mic:phi_tid) in(pVectorReal[phi_input_offset3:phi_input_size3] : REUSE)
2569 #pragma offload_transfer target(mic:phi_tid) in(pVectorImaginary[phi_input_offset3:phi_input_size3] : REUSE)
2570  }
2571 
2572  phi_output_size = nSizePHI;
2573  phi_output_offset = 0;
2574 
2575  // FIXME jinpil:
2576  // nocopy(pMatrixReal : REUSE)
2577  // correct directive syntax, but segmentation fault without *
2578  // Xeon Phi device cannot find the correct pointer value
2579  // compiler bug?
2580  // FIXME allocate pVectorReal, pVectorImaginary outside the Lanczos loop
2582 
2583 #pragma offload target(mic:phi_tid) \
2584  nocopy(*pMatrixReal : REUSE) \
2585  nocopy(*pMatrixImaginary : REUSE) \
2586  nocopy(*pMatrixRow : REUSE) \
2587  nocopy(*pMatrixColumn : REUSE) \
2588  nocopy(*pVectorReal : REUSE) \
2589  nocopy(*pVectorImaginary : REUSE) \
2590  out(pResultReal[phi_output_offset:phi_output_size] : REUSE) \
2591  out(pResultImaginary[phi_output_offset:phi_output_size] : REUSE) \
2592  signal(&phi_sigval)
2593  //*/
2594 
2595 #pragma omp parallel for
2596  for (unsigned int i = 0; i < nSizePHI; i++)
2597  {
2598  double real_sum = 0.0;
2599  double imaginary_sum = 0.0;
2600  const unsigned int nSubStart = pMatrixRow[i];
2601  const unsigned int nSubEnd = pMatrixRow[i + 1];
2602 
2603 
2604  for (unsigned int j = nSubStart; j < nSubEnd; j++)
2605  {
2606  const unsigned int nColIndex = pMatrixColumn[j];
2607  const double m_real = pMatrixReal[j];
2608  const double m_imaginary = pMatrixImaginary[j];
2609  const double v_real = pVectorReal[nColIndex];
2610  const double v_imaginary = pVectorImaginary[nColIndex];
2611 
2612  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2613  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2614  }
2615 
2616  pResultReal[i] = real_sum;
2617  pResultImaginary[i] = imaginary_sum;
2618  }
2619 #endif // USE_XEONPHI
2620 
2621 
2622 #pragma omp parallel for
2623  for (unsigned int i = nSizePHI; i < nSize; i++)
2624  {
2625  double real_sum = 0.0;
2626  double imaginary_sum = 0.0;
2627  const unsigned int nSubStart = pMatrixRow[i];
2628  const unsigned int nSubEnd = pMatrixRow[i + 1];
2629 
2630 
2631  for (unsigned int j = nSubStart; j < nSubEnd; j++)
2632  {
2633  const unsigned int nColIndex = pMatrixColumn[j];
2634  const double m_real = pMatrixReal[j];
2635  const double m_imaginary = pMatrixImaginary[j];
2636  const double v_real = pVectorReal[nColIndex];
2637  const double v_imaginary = pVectorImaginary[nColIndex];
2638 
2639  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2640  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2641  }
2642 
2643  pResultReal[i] = real_sum;
2644  pResultImaginary[i] = imaginary_sum;
2645  }
2646 
2647 #ifdef USE_XEONPHI
2648 #pragma offload_wait target(mic:phi_tid) wait(&phi_sigval)
2649 #endif // USE_XEONPHI
2650 
2651 }
static int GetTotalNodeCount()
Definition: MPIManager.h:42
static void MergeVectorEx_Optimal(CMatrixOperation::CVector *pVector, CMatrixOperation::CVector *pResultVector, unsigned int nMergeSize, double fFirstIndex, unsigned int nSizeFromPrevRank, unsigned int nSizeFromNextRank, unsigned int nSizetoPrevRank, unsigned int nSizetoNextRank, unsigned int *mPos, int nLBIndex)
Merge vector for 1 layer exchanging.
Definition: MPIManager.cpp:320
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: Global.h:64

Here is the call graph for this function:

Here is the caller graph for this function:

void CMatrixOperation::MVMulOptimal ( CCSR pAMatrix,
CVector pVector,
CVector pResult,
int  nLBIndex 
)
static

Matrix and vector multiple operation for multiple call.

Parameters
pAMatrixMatrix class pointer that want to operation
pVectorVector class pointer that want to operation
pResultVector class pointer that saving operation result

Definition at line 2658 of file MatrixOperation.cpp.

References ERROR_WRONG_ORDER_OPERATION, CMatrixOperation::CVector::Finalize(), CMatrixOperation::CCSR::GetColumnCount(), CMatrixOperation::CCSR::GetRowCount(), CMatrixOperation::CCSR::m_fFirstRowIndex, CMatrixOperation::CCSR::m_vectColumn, CMatrixOperation::CCSR::m_vectRow, CMatrixOperation::CVector::m_vectValueImaginaryBuffer, CMatrixOperation::CCSR::m_vectValueImaginaryBuffer, CMatrixOperation::CVector::m_vectValueRealBuffer, CMatrixOperation::CCSR::m_vectValueRealBuffer, CMPIManager::MergeVectorOptimal(), and CMatrixOperation::CVector::SetSize().

Referenced by CLanczosMethod::LanczosIterationLoop().

2659 {
2660  unsigned int i, j, nSize = pAMatrix->GetColumnCount();
2661  CVector *pOperandVector = NULL;
2662  double *pMatrixReal = NULL, *pMatrixImaginary = NULL;
2663  double *pVectorReal = NULL, *pVectorImaginary = NULL;
2664  double *pResultReal = NULL, *pResultImaginary = NULL;
2665  unsigned int *pMatrixRow = NULL, *pMatrixColumn = NULL;
2666 #ifndef DISABLE_MPI_ROUTINE
2667  CVector VOperand;
2668 
2669  VOperand.SetSize(pAMatrix->GetColumnCount());
2670  CMPIManager::MergeVectorOptimal(pVector, &VOperand, pAMatrix->GetColumnCount(), pAMatrix->m_fFirstRowIndex, nLBIndex);
2671  pOperandVector = &VOperand;
2672 #else
2673  pOperandVector = pVector;
2674 #endif
2675 
2676  if (nSize != pOperandVector->GetSize())
2677  {
2679  return;
2680  }
2681 
2682  nSize = pAMatrix->GetRowCount();
2683  pMatrixReal = pAMatrix->m_vectValueRealBuffer.data();
2684  pMatrixImaginary = pAMatrix->m_vectValueImaginaryBuffer.data();
2685  pMatrixRow = pAMatrix->m_vectRow.data();
2686  pMatrixColumn = pAMatrix->m_vectColumn.data();
2687  pVectorReal = pOperandVector->m_vectValueRealBuffer.data();
2688  pVectorImaginary = pOperandVector->m_vectValueImaginaryBuffer.data();
2689  pResultReal = pResult->m_vectValueRealBuffer.data();
2690  pResultImaginary = pResult->m_vectValueImaginaryBuffer.data();
2691 
2692 #ifdef USE_XEONPHI
2693  unsigned int input_real_size = pOperandVector->m_vectValueRealBuffer.size();
2694  unsigned int input_imaginary_size = pOperandVector->m_vectValueImaginaryBuffer.size();
2695  unsigned int output_real_size = pResult->m_vectValueRealBuffer.size();
2696  unsigned int output_imaginary_size = pResult->m_vectValueImaginaryBuffer.size();
2697 #endif
2698 
2699 // FIXME jinpil:
2700 // nocopy(pMatrixReal : REUSE)
2701 // correct directive syntax, but segmentation fault without *
2702 // Xeon Phi device cannot find the correct pointer value
2703 // compiler bug?
2704 // FIXME allocate pVectorReal, pVectorImaginary outside the Lanczos loop
2706 
2707 #ifdef USE_XEONPHI
2708 
2709 #pragma offload target(mic:phi_tid) \
2710  nocopy(*pMatrixReal : REUSE) \
2711  nocopy(*pMatrixImaginary : REUSE) \
2712  nocopy(*pMatrixRow : REUSE) \
2713  nocopy(*pMatrixColumn : REUSE) \
2714  in(pVectorReal[0:input_real_size] : LOCAL) \
2715  in(pVectorImaginary[0:input_imaginary_size] : LOCAL) \
2716  out(pResultReal[0:output_real_size] : REUSE) \
2717  out(pResultImaginary[0:output_imaginary_size] : REUSE)
2718 //*/
2719 
2720 #endif
2721 
2722 #pragma omp parallel for
2723  for ( i = 0; i < nSize; i++)
2724  {
2725  double real_sum = 0.0;
2726  double imaginary_sum = 0.0;
2727  const unsigned int nSubStart = pMatrixRow[i];
2728  const unsigned int nSubEnd = pMatrixRow[i + 1];
2729 
2730 
2731  for ( j = nSubStart; j < nSubEnd; j++)
2732  {
2733  const unsigned int nColIndex = pMatrixColumn[j];
2734  const double m_real = pMatrixReal[j];
2735  const double m_imaginary = pMatrixImaginary[j];
2736  const double v_real = pVectorReal[nColIndex];
2737  const double v_imaginary = pVectorImaginary[nColIndex];
2738 
2739  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2740  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2741  }
2742 
2743  pResultReal[i] = real_sum;
2744  pResultImaginary[i] = imaginary_sum;
2745  }
2746 #ifndef DISABLE_MPI_ROUTINE
2747  VOperand.Finalize();
2748 #endif //DISABLE_MPI_ROUTINE
2749 }
static void MergeVectorOptimal(CMatrixOperation::CVector *pSrcVector, CMatrixOperation::CVector *pResultVector, unsigned int nMergeSize, double fFirstIndex, int nLBIndex)
Merge vector to sub rank, operated without vector class member function call.
Definition: MPIManager.cpp:392
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: Global.h:64

Here is the call graph for this function:

Here is the caller graph for this function:

void CMatrixOperation::ScalarMulVectors ( double  fValue,
CVector pVector1,
CVector pResult 
)
static

Added by jhkang end.

Definition at line 3325 of file MatrixOperation.cpp.

References CMatrixOperation::CVector::GetAt(), CComplex::GetImaginaryNumber(), CComplex::GetRealNumber(), CMatrixOperation::CVector::GetSize(), and CMatrixOperation::CVector::SetAt().

3326 {
3327  unsigned int nSize = pVector1->GetSize();
3328 
3329  for (unsigned int i = 0; i < nSize; i++)
3330  {
3331  pResult->SetAt(i, fValue * pVector1->GetAt(i).GetRealNumber(), fValue * pVector1->GetAt(i).GetImaginaryNumber());
3332  }
3333 }

Here is the call graph for this function:

void CMatrixOperation::SubstractVectors ( CVector pVector1,
CVector pVector2,
CVector pResult 
)
static

Definition at line 3311 of file MatrixOperation.cpp.

References ERROR_WRONG_ORDER_OPERATION, CMatrixOperation::CVector::GetAt(), CMatrixOperation::CVector::GetSize(), and CMatrixOperation::CVector::SetAt().

3312 {
3313  unsigned int nSize = pVector1->GetSize();
3314  if (nSize != pVector2->GetSize())
3315  {
3317  }
3318 
3319  for (unsigned int i = 0; i < nSize; i++)
3320  {
3321  pResult->SetAt(i, pVector1->GetAt(i) - pVector2->GetAt(i));
3322  }
3323 }
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: Global.h:64

Here is the call graph for this function:

void CMatrixOperation::UpdateLocalCSR ( CMatrixOperation::CCSR source,
CMatrixOperation::CCSR mine,
CMatrixOperation::CCSR left,
CMatrixOperation::CCSR right 
)
static
Parameters
sourceCopying source CSR
mineLocal CSR buffer
leftLeft node CSR buffer
rightright node CSR buffer

Definition at line 3122 of file MatrixOperation.cpp.

References CMatrixOperation::CCSR::GetColumnCount(), CMatrixOperation::CCSR::GetFirstRowIndex(), CComplex::GetImaginaryNumber(), CComplex::GetRealNumber(), CMatrixOperation::CCSR::GetRowCount(), CMatrixOperation::CCSR::GetValue(), CMatrixOperation::CCSR::m_vectColumn, CMatrixOperation::CCSR::m_vectRow, pColumn, pRow, CMatrixOperation::CCSR::SetAt(), CComplex::SetImaginaryNumber(), and CComplex::SetRealNumber().

Referenced by CLanczosLaunching::LaunchingLanczos().

3123 {
3124  CMatrixOperation::pRow = source->m_vectRow.data();
3125  CMatrixOperation::pColumn = source->m_vectColumn.data();
3126  //CKNMemoryManager::LPVECTOR_ELEMENTS lpMatrixValueElement = NULL;
3127  CComplex *pData = NULL;
3128  unsigned int my_nnz, left_nnz, right_nnz;
3129  CComplex curval;
3130  int isthisrowfilled;
3131 
3132  //lpMatrixValueElement = source->GetValueElement();
3133 
3134  // 1. Update left block
3135 
3136  left_nnz = 0;
3137 
3138  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
3139  {
3140  isthisrowfilled = -1;
3141  unsigned int nSubStart = CMatrixOperation::pRow[ii], nSubEnd = CMatrixOperation::pRow[ii + 1];
3142  unsigned int startColIndex = (int)left->GetFirstRowIndex(), endColIndex = startColIndex + left->GetColumnCount() - 1;
3143 
3144  for (unsigned int jj = nSubStart; jj < nSubEnd; jj++)
3145  {
3146  unsigned int nColIndex = CMatrixOperation::pColumn[jj];
3147 
3148  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
3149  {
3150  isthisrowfilled = 0;
3151  left_nnz++;
3152  //curval.SetRealNumber(lpMatrixValueElement->pfReal[jj]); curval.SetImaginaryNumber(lpMatrixValueElement->pfImaginary[jj]);
3153  pData = source->GetValue(jj);
3154  curval.SetRealNumber(pData->GetRealNumber()); curval.SetImaginaryNumber(pData->GetImaginaryNumber());
3155  left->SetAt(curval, ii, nColIndex-startColIndex);
3156  }
3157  }
3158 
3159  if(isthisrowfilled == -1)
3160  {
3161  left_nnz++;
3162  curval.SetRealNumber(0.0); curval.SetImaginaryNumber(0.0);
3163  left->SetAt(curval, ii, 0);
3164  }
3165  }
3166 
3167 // if(CMPIManager::IsRootRank())
3168 // printf("Left block update completed: left_nnz = %d (computed), %d (CSR-allocated)\n", left_nnz, left->GetNoneZeroCount());
3169 
3170  // 2. Figure out nnz: right block
3171 
3172  right_nnz = 0;
3173 
3174  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
3175  {
3176  isthisrowfilled = -1;
3177  unsigned int nSubStart = CMatrixOperation::pRow[ii], nSubEnd = CMatrixOperation::pRow[ii + 1];
3178  unsigned int startColIndex = (int)right->GetFirstRowIndex(), endColIndex = startColIndex + right->GetColumnCount() - 1;
3179 
3180  for (unsigned int jj = nSubStart; jj < nSubEnd; jj++)
3181  {
3182  unsigned int nColIndex = CMatrixOperation::pColumn[jj];
3183  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
3184  {
3185  isthisrowfilled = 0;
3186  right_nnz++;
3187  //curval.SetRealNumber(lpMatrixValueElement->pfReal[jj]); curval.SetImaginaryNumber(lpMatrixValueElement->pfImaginary[jj]);
3188  pData = source->GetValue(jj);
3189  curval.SetRealNumber(pData->GetRealNumber()); curval.SetImaginaryNumber(pData->GetImaginaryNumber());
3190  right->SetAt(curval, ii, nColIndex-startColIndex);
3191  }
3192 
3193  }
3194 
3195  if(isthisrowfilled == -1)
3196  {
3197  right_nnz++;
3198  curval.SetRealNumber(0.0); curval.SetImaginaryNumber(0.0);
3199  right->SetAt(curval, ii, 0);
3200  }
3201  }
3202 
3203 // if(CMPIManager::IsRootRank())
3204 // printf("Right block update completed: right_nnz = %d (computed), %d (CSR-allocated)\n", right_nnz, right->GetNoneZeroCount());
3205 
3206  // 3. Figure out nnz: my block
3207 
3208  my_nnz = 0;
3209 
3210  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
3211  {
3212  unsigned int nSubStart = CMatrixOperation::pRow[ii], nSubEnd = CMatrixOperation::pRow[ii + 1];
3213  unsigned int startColIndex = (int)mine->GetFirstRowIndex(), endColIndex = startColIndex + mine->GetColumnCount() - 1;
3214 
3215  for(unsigned int jj = nSubStart; jj < nSubEnd; jj++)
3216  {
3217  unsigned int nColIndex = CMatrixOperation::pColumn[jj];
3218  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
3219  {
3220  my_nnz++;
3221  //curval.SetRealNumber(lpMatrixValueElement->pfReal[jj]); curval.SetImaginaryNumber(lpMatrixValueElement->pfImaginary[jj]);
3222  pData = source->GetValue(jj);
3223  curval.SetRealNumber(pData->GetRealNumber()); curval.SetImaginaryNumber(pData->GetImaginaryNumber());
3224  mine->SetAt(curval, ii, nColIndex-startColIndex);
3225  }
3226  }
3227  }
3228 
3229 // if(CMPIManager::IsRootRank())
3230 // printf("My block update completed: my_nnz = %d (computed), %d (CSR-allocated)\n", my_nnz, mine->GetNoneZeroCount());
3231 };
void SetImaginaryNumber(double fImaginaryNumber)
Set imagenary part.
Definition: Complex.h:30
unsigned int GetRowCount()
static unsigned int * pColumn
For MPI Optimized operation using.
void SetRealNumber(double fRealNumber)
Set real part.
Definition: Complex.h:29
CComplex * GetValue(unsigned int nIndex)
Getting none zero element value by index.
unsigned int GetColumnCount()
Getting row size of matrix.
bool SetAt(CComplex number, unsigned int nRow, unsigned int nColumn)
Set element to specific index.
This class for complex operation and saving value.
Definition: Complex.h:16
double GetFirstRowIndex()
Set first row index.
static unsigned int * pRow
For MPI Optimized operation using.
double GetImaginaryNumber() const
Get imaginary part.
Definition: Complex.h:25
uint_vector_t m_vectColumn
A member variable for saving column information.
uint_vector_t m_vectRow
A member variable for saving row information.
double GetRealNumber() const
Get real part.
Definition: Complex.h:24

Here is the call graph for this function:

Here is the caller graph for this function:

bool CMatrixOperation::VVDot ( CVector pVector1,
CVector pVector2,
CComplex pResult 
)
static

Between vectors dot product operation.

Parameters
pVector1Vector class pointer that want to operation
pVector2Vector class pointer that want to operation
pResultA result of operation
Returns
If operation success return true or return false

Definition at line 2757 of file MatrixOperation.cpp.

References CMPIManager::AllReduceComlex(), ERROR_WRONG_ORDER_OPERATION, CMatrixOperation::CVector::GetSize(), CMatrixOperation::CVector::m_vectValueImaginaryBuffer, CMatrixOperation::CVector::m_vectValueRealBuffer, CComplex::SetComplexNumber(), and CTimeMeasurement::VV_COMM.

Referenced by Gram_schmidt(), CLanczosMethod::LanczosIterationLoop(), and CLanczosMethod::MergeDegeneratedEigenvalues().

2758 {
2759  double *pOp1Real = NULL, *pOp1Imaginary = NULL;
2760  double *pOp2Real = NULL, *pOp2Imaginary = NULL;
2761  unsigned int i, nSize = pVector1->GetSize();
2762 
2763  if (nSize != pVector2->GetSize())
2764  {
2766  return false;
2767  }
2768 
2769  pOp1Real = pVector1->m_vectValueRealBuffer.data();
2770  pOp1Imaginary = pVector1->m_vectValueImaginaryBuffer.data();
2771 
2772  pOp2Real = pVector2->m_vectValueRealBuffer.data();
2773  pOp2Imaginary = pVector2->m_vectValueImaginaryBuffer.data();
2774 
2775  double fReal = 0., fImaginary = 0.;
2776 #pragma omp parallel for reduction(+:fReal, fImaginary)
2777  for (i = 0; i < nSize; i++)
2778  {
2779  /*fReal += pOp1Real[i] * pOp2Real[i] - pOp1Imaginary[i] * (-1 * pOp2Imaginary[i]);
2780  fImaginary += pOp1Real[i] * (-1 * pOp2Imaginary[i]) + pOp1Imaginary[i] * pOp2Real[i];*/
2781  fReal += pOp1Real[i] * pOp2Real[i] - (-1*pOp1Imaginary[i]) * pOp2Imaginary[i];
2782  fImaginary += pOp1Real[i] * pOp2Imaginary[i] + (-1*pOp1Imaginary[i]) * pOp2Real[i];
2783  }
2784 
2785  pResult->SetComplexNumber(fReal, fImaginary);
2787 
2788  return true;
2789 
2790 }
static void AllReduceComlex(CComplex *pNumber, CTimeMeasurement::MEASUREMENT_INDEX INDEX=CTimeMeasurement::COMM)
Do all reduce function with CKNComplex.
Definition: MPIManager.cpp:571
void SetComplexNumber(double fReal, double fImaginaray)
Set Complex number using real part and imaginary part.
Definition: Complex.cpp:58
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: Global.h:64

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

unsigned int * CMatrixOperation::pColumn = NULL
static

For MPI Optimized operation using.

Definition at line 280 of file MatrixOperation.h.

Referenced by BuildLocalCSR(), and UpdateLocalCSR().

unsigned int * CMatrixOperation::pRow = NULL
static

For MPI Optimized operation using.

Definition at line 279 of file MatrixOperation.h.

Referenced by BuildLocalCSR(), and UpdateLocalCSR().

CComplex * CMatrixOperation::pValueBuffer = NULL
static

For MPI Optimized operation using.

Definition at line 278 of file MatrixOperation.h.


The documentation for this class was generated from the following files: