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

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

#include "KNMatrixOperation.h"

Collaboration diagram for CKNMatrixOperation:
Collaboration graph

Classes

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

Public Types

typedef std::vector< double,
boost::alignment::aligned_allocator
< double, 64 > > 
double_vector_t
 
typedef std::vector< unsigned
int,
boost::alignment::aligned_allocator
< unsigned int, 64 > > 
uint_vector_t
 
typedef struct
CKNMatrixOperation::CSR_ELEMENT_DATA
LPCSR_ELEMENT_DATA
 
typedef struct
CKNMatrixOperation::FILL_MATRIX_DATA
LPFILL_MATRIX_DATA
 

Public Member Functions

 CKNMatrixOperation ()
 Constructor. More...
 
 ~CKNMatrixOperation ()
 Destructor. More...
 

Static Public Member Functions

static CKNMatrixOperation::CKNCSRBuildCSRFromOneDimArray (double *pReal, double *pImaginary, unsigned int nRowOrder, unsigned int nColumnOrder)
 Building CSR from one dimension array. More...
 
static CKNMatrixOperation::CKNCSRBuildCSRFromFileTemp (FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
 Building CSR from file using double, double, double, double order. More...
 
static CKNMatrixOperation::CKNCSRBuildCSRFromFile_ (FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
 Building CSR from file using int, int, double, double order. More...
 
static CKNMatrixOperation::CKNCSRBuildCSRFromFileUnsortdata (FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
 uilding CSR form file and before building CSR sorting data More...
 
static void FreeCSR (CKNMatrixOperation::CKNCSR *pCSR)
 Deallocating CSR memory. More...
 
static void DumpCSR (CKNMatrixOperation::CKNCSR *pCSR, const char *pstrFileName)
 For dubugging save CSR information into file. More...
 
static void AllocateLocalCSR (CKNMatrixOperation::CKNCSR **mine, CKNMatrixOperation::CKNCSR **left, CKNMatrixOperation::CKNCSR **right)
 
static void FreeLocalCSR (CKNMatrixOperation::CKNCSR *mine, CKNMatrixOperation::CKNCSR *left, CKNMatrixOperation::CKNCSR *right)
 
static void BuildLocalCSR (CKNMatrixOperation::CKNCSR *source, CKNMatrixOperation::CKNCSR *mine, CKNMatrixOperation::CKNCSR *left, CKNMatrixOperation::CKNCSR *right)
 
static void UpdateLocalCSR (CKNMatrixOperation::CKNCSR *source, CKNMatrixOperation::CKNCSR *mine, CKNMatrixOperation::CKNCSR *left, CKNMatrixOperation::CKNCSR *right)
 
static int Compare (const void *pA, const void *pB)
 For qick sort compare operation. More...
 
static void MVMulEx_AsyncCommWithLocalBlocks (CKNMatrixOperation::CKNCSR *mylocalblock, CKNMatrixOperation::CKNCSR *leftlocalblock, CKNMatrixOperation::CKNCSR *rightlocalblock, CKNVector *pVector, CKNVector *pResult, double *X, double *Xrt, double *Xlt)
 Matrix and vector multiple operation using by block csr. More...
 
static void MVMulOptimal (CKNCSR *pAMatrix, CKNVector *pVector, CKNVector *pResult)
 Matrix and vector multiple operation for multiple call. More...
 
static void MVMulEx_Optimal (CKNCSR *pAMatrix, CKNVector *pVector, CKNVector *pResult, unsigned int, unsigned int, CKNVector *, int)
 Matrix and vector multiple operation for 1 layer exchanging communication. More...
 
static void MVMul (CKNCSR *pAMatrix, CKNVector *pVector, CKNVector *pResult)
 Matrix and vector multiple operation. More...
 
static bool VVDot (CKNVector *pVector1, CKNVector *pVector2, CKNComplex *pResult)
 Between vectors dot product operation. More...
 
static void MVMul (CKNDMatrix *pMatrix, CKNVector *pVector, CKNVector *pResult)
 Matrix and vector multiple operation for dense matrix. More...
 
static void MMMul (CKNDMatrix *pMatrix, CKNDMatrix *pMatrixOperand, CKNDMatrix *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 (CKNComplex operand1, CKNComplex operand2, double tol)
 Compare two vectors with tolerance. More...
 
static bool IsSame (CKNVector *pVector1, CKNVector *pVector2)
 Compare two vectors with general tolerance(1e-8) More...
 
static int Gram_schmidt (CKNVector *pVect1, CKNVector *pVect2)
 Doing gam schmidt orthogonalization. More...
 

Static Public Attributes

static CKNComplexpValueBuffer = 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
Author
Kyu Nam Cho(mysto.nosp@m.us@k.nosp@m.orea..nosp@m.ac.k.nosp@m.r), Hoon Ryu(elec1.nosp@m.020@.nosp@m.gmail.nosp@m..com)

Definition at line 25 of file KNMatrixOperation.h.

Member Typedef Documentation

typedef std::vector<double, boost::alignment::aligned_allocator<double, 64> > CKNMatrixOperation::double_vector_t

Definition at line 29 of file KNMatrixOperation.h.

typedef std::vector<unsigned int, boost::alignment::aligned_allocator<unsigned int, 64> > CKNMatrixOperation::uint_vector_t

Definition at line 32 of file KNMatrixOperation.h.

Constructor & Destructor Documentation

CKNMatrixOperation::CKNMatrixOperation ( )

Constructor.


        CKNCSR Class member function - End

        CKNMatrixOperation Class member function - End

Definition at line 1802 of file KNMatrixOperation.cpp.

1803 {
1804 }
CKNMatrixOperation::~CKNMatrixOperation ( )

Destructor.

Definition at line 1806 of file KNMatrixOperation.cpp.

1807 {
1808 }

Member Function Documentation

void CKNMatrixOperation::AllocateLocalCSR ( CKNMatrixOperation::CKNCSR **  mine,
CKNMatrixOperation::CKNCSR **  left,
CKNMatrixOperation::CKNCSR **  right 
)
static

        CKNMatrixOperation Class member function - End

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

Definition at line 2874 of file KNMatrixOperation.cpp.

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

Referenced by CKNLanczosLaunching::LaunchingLanczos().

2875 {
2876  unsigned int nRowCount, nColumnCount;
2877  int myrank = CKNMPIManager::GetCurrentRank();
2878  int ncpus = CKNMPIManager::GetTotalNodeCount();
2879  int left_neighbor = (myrank-1+ncpus)%ncpus; // top neighbor
2880  int right_neighbor = (myrank+1)%ncpus; // bottom neighbor
2881  unsigned int temp;
2882 
2883  nRowCount = CKNMPIManager::GetLoadBalanceCount(myrank);
2884  *mine = NULL; *left = NULL; *right = NULL;
2885 
2886  // Allocate mine
2887  *mine = new CKNMatrixOperation::CKNCSR();
2888  if (*mine == NULL)
2889  throw ERROR_MALLOC;
2890  nColumnCount = CKNMPIManager::GetLoadBalanceCount(myrank);
2891  (*mine)->SetRowCount(nRowCount);
2892  (*mine)->SetColumnCount(nColumnCount);
2893  (*mine)->BuildDataBuffer(); temp = 0;
2894  for (int jj=0; jj<myrank; jj++)
2896  (*mine)->SetFirstRowIndex((double)temp); // FirstRowIndex will be used in a bit different way: Starting "column" index.
2897 
2898 // printf("%d %d %d %d %d %d\n", myrank, left_neighbor, right_neighbor, (int)(*mine)->GetFirstRowIndex(), (*mine)->GetColumnCount(), (*mine)->GetNoneZeroCount());
2899 
2900  // Allocate left
2901  *left = new CKNMatrixOperation::CKNCSR();
2902  if (*left == NULL)
2903  throw ERROR_MALLOC;
2904  nColumnCount = CKNMPIManager::GetLoadBalanceCount(left_neighbor);
2905  (*left)->SetRowCount(nRowCount);
2906  (*left)->SetColumnCount(nColumnCount);
2907  (*left)->BuildDataBuffer(); temp = 0;
2908  for (int jj=0; jj<left_neighbor; jj++)
2910  (*left)->SetFirstRowIndex((double)temp); // FirstRowIndex will be used in a bit different way: Starting "column" index.
2911 
2912  //Allocate right
2913  *right = new CKNMatrixOperation::CKNCSR();
2914  if (*right == NULL)
2915  throw ERROR_MALLOC;
2916  nColumnCount = CKNMPIManager::GetLoadBalanceCount(right_neighbor);
2917  (*right)->SetRowCount(nRowCount);
2918  (*right)->SetColumnCount(nColumnCount);
2919  (*right)->BuildDataBuffer(); temp = 0;
2920  for(int jj=0; jj<right_neighbor; jj++)
2922  (*right)->SetFirstRowIndex((double)temp); // FirstRowIndex will be used in a bit different way: Starting "column" index.
2923 
2924  MPI_Barrier(CKNMPIManager::GetMPIComm());
2925 }
static MPI_Comm GetMPIComm()
Definition: KNMPIManager.h:67
Data and operation representation of CSR(Compressed Sparse Row)
static int GetTotalNodeCount()
Definition: KNMPIManager.h:44
static int GetLoadBalanceCount(int nRank)
static int GetCurrentRank()
Definition: KNMPIManager.h:42
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: CKNGlobal.h:62

Here is the call graph for this function:

Here is the caller graph for this function:

CKNMatrixOperation::CKNCSR * CKNMatrixOperation::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 1851 of file KNMatrixOperation.cpp.

References CKNMatrixOperation::CKNCSR::BuildDataBuffer(), CKNMatrixOperation::CKNCSR::FinishPush(), CKNMatrixOperation::CKNCSR::PushNoneZeroValue(), REPEAT_COUNT, CKNMatrixOperation::CKNCSR::SetColumnCount(), and CKNMatrixOperation::CKNCSR::SetRowCount().

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

Here is the call graph for this function:

CKNMatrixOperation::CKNCSR * CKNMatrixOperation::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 1819 of file KNMatrixOperation.cpp.

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

Referenced by CKNLanczosTest::LargeCSRBuildingViaFileForMPI().

1820 {
1822  size_t readSize;
1823  unsigned int i;
1825 
1826  if (NULL == pCSR)
1827  return pCSR;
1828 
1829  pCSR->SetRowCount(nRowOrder);
1830  pCSR->SetColumnCount(nColumnOrder);
1831  pCSR->BuildDataBuffer();
1832 
1833  while (0 != (readSize = fread(Data, sizeof(CSR_ELEMENT_DATA), REPEAT_COUNT, fDataFile)))
1834  {
1835  for (i = 0; i < readSize; i++)
1836  pCSR->PushNoneZeroValue(Data[i].fReal, Data[i].fImaginary, (unsigned int)Data[i].nRow - 1, (unsigned int)Data[i].nColumn - 1);
1837  }
1838 
1839  pCSR->FinishPush();
1840 
1841  return pCSR;
1842 }
Data and operation representation of CSR(Compressed Sparse Row)
void BuildDataBuffer()
Allocating memory for class member variable.
void PushNoneZeroValue(double fRealValue, double fImaginaryValue, unsigned int nRow, unsigned int nCol)
Saving none zero value.
void FinishPush()
Insert end index of none zero value index.
void SetRowCount(unsigned int nRow)
Settting row size of matrix.
void SetColumnCount(unsigned int nColumn)
Settting column size of matrix.
#define REPEAT_COUNT

Here is the call graph for this function:

Here is the caller graph for this function:

CKNMatrixOperation::CKNCSR * CKNMatrixOperation::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 1917 of file KNMatrixOperation.cpp.

References CKNMatrixOperation::CKNCSR::BuildDataBuffer(), Compare(), CKNMatrixOperation::CKNCSR::FinishPush(), CKNMatrixOperation::CKNCSR::PushNoneZeroValue(), CKNMatrixOperation::CKNCSR::SetColumnCount(), and CKNMatrixOperation::CKNCSR::SetRowCount().

1918 {
1919  LPCSR_ELEMENT_DATA lpData = (LPCSR_ELEMENT_DATA)malloc(sizeof(CSR_ELEMENT_DATA)* nDataCount);
1921  int i;
1922 
1923  if (lpData == NULL)
1924  return pCSR;
1925 
1926  for (i = 0; i < nDataCount; i++)
1927  {
1928  fread(&lpData[i], sizeof(CSR_ELEMENT_DATA), 1, fDataFile);
1929  }
1930 
1931  pCSR->SetRowCount(nRowOrder);
1932  pCSR->SetColumnCount(nColumnOrder);
1933  pCSR->BuildDataBuffer();
1934 
1935  qsort(lpData, nDataCount, sizeof(CSR_ELEMENT_DATA), CKNMatrixOperation::Compare);
1936 
1937  for (i = 0; i < nDataCount; i++)
1938  {
1939  pCSR->PushNoneZeroValue(lpData[i].fReal, lpData[i].fImaginary, (unsigned int)lpData[i].nRow - 1, (unsigned int)lpData[i].nColumn - 1);
1940  }
1941  pCSR->FinishPush();
1942 
1943  return pCSR;
1944 
1945 }
Data and operation representation of CSR(Compressed Sparse Row)
void BuildDataBuffer()
Allocating memory for class member variable.
static int Compare(const void *pA, const void *pB)
For qick sort compare operation.
void PushNoneZeroValue(double fRealValue, double fImaginaryValue, unsigned int nRow, unsigned int nCol)
Saving none zero value.
void FinishPush()
Insert end index of none zero value index.
void SetRowCount(unsigned int nRow)
Settting row size of matrix.
void SetColumnCount(unsigned int nColumn)
Settting column size of matrix.
struct CKNMatrixOperation::CSR_ELEMENT_DATA * LPCSR_ELEMENT_DATA

Here is the call graph for this function:

CKNMatrixOperation::CKNCSR * CKNMatrixOperation::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 1953 of file KNMatrixOperation.cpp.

References CKNMatrixOperation::CKNCSR::BuildDataBuffer(), CKNMatrixOperation::CKNCSR::FinishPush(), CKNMatrixOperation::CKNCSR::PushNoneZeroValue(), CKNMatrixOperation::CKNCSR::SetColumnCount(), and CKNMatrixOperation::CKNCSR::SetRowCount().

Referenced by CKNLanczosTest::TestCSRBuildingViaArray(), CKNLanczosTest::TestCSRBuildingViaFileLoad(), CKNLanczosTest::TestCSRBuildingViaFileLoad_(), and CKNLanczosTest::TestCSRBuildingViaFileLoadOrigin().

1954 {
1955  unsigned int row, col;
1957 
1958  if (NULL == pCSR)
1959  return pCSR;
1960 
1961  pCSR->SetRowCount(nRowOrder);
1962  pCSR->SetColumnCount(nColumnOrder);
1963  pCSR->BuildDataBuffer();
1964 
1965  unsigned int nIndex = 0;
1966  bool bPushedInRow = false;
1967  for (row = 0; row < nRowOrder; row++)
1968  {
1969  for (col = 0; col < nColumnOrder; col++)
1970  {
1971  if (0 != pReal[row*nColumnOrder + col] || 0 != pImaginary[row*nColumnOrder + col])
1972  {
1973  pCSR->PushNoneZeroValue(pReal[nIndex], pImaginary[nIndex], row, col);
1974  bPushedInRow = true;
1975  }
1976  nIndex++;
1977  }
1978  }
1979  pCSR->FinishPush();
1980 
1981  return pCSR;
1982 }
Data and operation representation of CSR(Compressed Sparse Row)
void BuildDataBuffer()
Allocating memory for class member variable.
void PushNoneZeroValue(double fRealValue, double fImaginaryValue, unsigned int nRow, unsigned int nCol)
Saving none zero value.
void FinishPush()
Insert end index of none zero value index.
void SetRowCount(unsigned int nRow)
Settting row size of matrix.
void SetColumnCount(unsigned int nColumn)
Settting column size of matrix.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 2933 of file KNMatrixOperation.cpp.

References CKNMatrixOperation::CKNCSR::FinishPush(), CKNMatrixOperation::CKNCSR::GetColumnCount(), CKNMatrixOperation::CKNCSR::GetFirstRowIndex(), CKNComplex::GetImaginaryNumber(), CKNComplex::GetRealNumber(), CKNMatrixOperation::CKNCSR::GetRowCount(), CKNMatrixOperation::CKNCSR::GetValue(), CKNMatrixOperation::CKNCSR::m_vectColumn, CKNMatrixOperation::CKNCSR::m_vectRow, pColumn, pRow, and CKNMatrixOperation::CKNCSR::PushNoneZeroValue().

Referenced by CKNLanczosLaunching::LaunchingLanczos().

2934 {
2935  CKNMatrixOperation::pRow = source->m_vectRow.data();
2936  CKNMatrixOperation::pColumn = source->m_vectColumn.data();
2937  //CKNMemoryManager::LPVECTOR_ELEMENTS lpMatrixValueElement = NULL;
2938  CKNComplex *pData = NULL;
2939  unsigned int my_nnz, left_nnz, right_nnz;
2940  int isthisrowfilled;
2941 
2942  //lpMatrixValueElement = source->GetValueElement();
2943 
2944  // 1. Build left local block.
2945 
2946  left_nnz = 0;
2947 
2948  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
2949  {
2950  isthisrowfilled = -1;
2951  unsigned int nSubStart = CKNMatrixOperation::pRow[ii], nSubEnd = CKNMatrixOperation::pRow[ii+1];
2952  unsigned int startColIndex = (int)left->GetFirstRowIndex(), endColIndex = startColIndex + left->GetColumnCount() - 1;
2953 
2954  for (unsigned int jj = nSubStart; jj < nSubEnd; jj++)
2955  {
2956  unsigned int nColIndex = CKNMatrixOperation::pColumn[jj];
2957 
2958  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
2959  {
2960  isthisrowfilled = 0;
2961  left_nnz++;
2962  pData = source->GetValue(jj);
2963  //left->PushNoneZeroValue(lpMatrixValueElement->pfReal[jj], lpMatrixValueElement->pfImaginary[jj], ii, nColIndex-startColIndex);
2964  left->PushNoneZeroValue(pData->GetRealNumber(), pData->GetImaginaryNumber(), ii, nColIndex-startColIndex);
2965  }
2966  }
2967 
2968  if(isthisrowfilled == -1)
2969  {
2970  left_nnz++;
2971  left->PushNoneZeroValue(0.0, 0.0, ii, 0);
2972  }
2973  }
2974 
2975  left->FinishPush();
2976 
2977 // if(CKNMPIManager::IsRootRank())
2978 // printf("Left block conversion completed: left_nnz = %d (computed), %d (CSR-allocated)\n", left_nnz, left->GetNoneZeroCount());
2979 
2980  // 2. Build right block
2981 
2982  right_nnz = 0;
2983 
2984  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
2985  {
2986  isthisrowfilled = -1;
2987  unsigned int nSubStart = CKNMatrixOperation::pRow[ii], nSubEnd = CKNMatrixOperation::pRow[ii+1];
2988  unsigned int startColIndex = (int)right->GetFirstRowIndex(), endColIndex = startColIndex + right->GetColumnCount() - 1;
2989 
2990  for (unsigned int jj = nSubStart; jj < nSubEnd; jj++)
2991  {
2992  unsigned int nColIndex = CKNMatrixOperation::pColumn[jj];
2993  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
2994  {
2995  isthisrowfilled = 0;
2996  right_nnz++;
2997  pData = source->GetValue(jj);
2998  //right->PushNoneZeroValue(lpMatrixValueElement->pfReal[jj], lpMatrixValueElement->pfImaginary[jj], ii, nColIndex-startColIndex);
2999  right->PushNoneZeroValue(pData->GetRealNumber(), pData->GetImaginaryNumber(), ii, nColIndex-startColIndex);
3000  }
3001  }
3002 
3003  if(isthisrowfilled == -1)
3004  {
3005  right_nnz++;
3006  right->PushNoneZeroValue(0.0, 0.0, ii, 0);
3007  }
3008  }
3009 
3010  right->FinishPush();
3011 
3012 // if(CKNMPIManager::IsRootRank())
3013 // printf("Right block conversion completed: right_nnz = %d (computed), %d (CSR-allocated)\n", right_nnz, right->GetNoneZeroCount());
3014 
3015  // 3. Build my block
3016 
3017  my_nnz = 0;
3018 
3019  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
3020  {
3021  unsigned int nSubStart = CKNMatrixOperation::pRow[ii], nSubEnd = CKNMatrixOperation::pRow[ii+1];
3022  unsigned int startColIndex = (int)mine->GetFirstRowIndex(), endColIndex = startColIndex + mine->GetColumnCount() - 1;
3023 
3024  for(unsigned int jj = nSubStart; jj < nSubEnd; jj++)
3025  {
3026  unsigned int nColIndex = CKNMatrixOperation::pColumn[jj];
3027  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
3028  {
3029  my_nnz++;
3030  pData = source->GetValue(jj);
3031  //mine->PushNoneZeroValue(lpMatrixValueElement->pfReal[jj], lpMatrixValueElement->pfImaginary[jj], ii, nColIndex-startColIndex);
3032  mine->PushNoneZeroValue(pData->GetRealNumber(), pData->GetImaginaryNumber(), ii, nColIndex-startColIndex);
3033  }
3034  }
3035  }
3036 
3037  mine->FinishPush();
3038 
3039 // if(CKNMPIManager::IsRootRank())
3040 // printf("My block conversion completed: my_nnz = %d (computed), %d (CSR-allocated)\n", my_nnz, mine->GetNoneZeroCount());
3041 
3042 }
double GetImaginaryNumber() const
Get imaginary part.
Definition: KNComplex.h:27
static unsigned int * pRow
For MPI Optimized operation using.
double GetRealNumber() const
Get real part.
Definition: KNComplex.h:26
unsigned int GetColumnCount()
Getting row size of matrix.
uint_vector_t m_vectColumn
A member variable for saving column information.
void PushNoneZeroValue(double fRealValue, double fImaginaryValue, unsigned int nRow, unsigned int nCol)
Saving none zero value.
double GetFirstRowIndex()
Set first row index.
CKNComplex * GetValue(unsigned int nIndex)
Getting none zero element value by index.
static unsigned int * pColumn
For MPI Optimized operation using.
This class for complex operation and saving value.
Definition: KNComplex.h:18
void FinishPush()
Insert end index of none zero value index.
uint_vector_t m_vectRow
A member variable for saving row information.

Here is the call graph for this function:

Here is the caller graph for this function:

int CKNMatrixOperation::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 1887 of file KNMatrixOperation.cpp.

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

Referenced by BuildCSRFromFileUnsortdata().

1888 {
1891 
1892  if (lpA->nRow > lpB->nRow)
1893  return 1;
1894  else if (lpA->nRow < lpB->nRow)
1895  return -1;
1896 
1897  if (lpA->nRow == lpB->nRow)
1898  {
1899  if (lpA->nColumn > lpB->nColumn)
1900  return 1;
1901  else if (lpA->nColumn < lpB->nColumn)
1902  return -1;
1903  else if (lpB->nColumn == lpB->nColumn)
1904  return 0;
1905  }
1906 
1907  return -1;
1908 }
struct CKNMatrixOperation::CSR_ELEMENT_DATA * LPCSR_ELEMENT_DATA

Here is the caller graph for this function:

static void CKNMatrixOperation::DumpCSR ( CKNMatrixOperation::CKNCSR pCSR,
const char *  pstrFileName 
)
inlinestatic

For dubugging save CSR information into file.

Definition at line 243 of file KNMatrixOperation.h.

References CKNMatrixOperation::CKNCSR::DumpCSR().

Referenced by CKNLanczosTest::TestCSRBuilding().

Here is the call graph for this function:

Here is the caller graph for this function:

void CKNMatrixOperation::FreeCSR ( CKNMatrixOperation::CKNCSR pCSR)
static

Deallocating CSR memory.

Parameters
pCSRCSR class pointer that want to deallocating memeory

Definition at line 2085 of file KNMatrixOperation.cpp.

References CKNMatrixOperation::CKNCSR::Finalize().

Referenced by CKNLanczosTest::CompareWithMatLabSeOrth(), CKNLanczosTest::COmpareWIthMatLabSeOrthMPI(), CKNTBMS_Solver::FinalEvn(), FreeLocalCSR(), CKNLanczosTest::LanczosThread(), CKNLanczosTest::LargeSizeMatrixMPI(), CKNLanczosTest::SolvingLargeSizeHamlitonian(), CKNLanczosTest::TestCSRBuilding(), CKNLanczosTest::TestCSRBuildingViaFileLoad_(), CKNLanczosTest::TestLanczos(), and CKNLanczosTest::TestSimpleLanczos().

2086 {
2087  if (NULL == pCSR)
2088  return;
2089 
2090  pCSR->Finalize();
2091 
2092  delete pCSR;
2093  pCSR = NULL;
2094 }
void Finalize()
Deallocating memory for member variable.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 3166 of file KNMatrixOperation.cpp.

References FreeCSR().

Referenced by CKNLanczosLaunching::LaunchingLanczos().

3167 {
3168  if (mine != NULL)
3169  {
3171  mine = NULL;
3172  }
3173  if (left != NULL)
3174  {
3176  left = NULL;
3177  }
3178  if (right != NULL)
3179  {
3181  right = NULL;
3182  }
3183 }
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.

Here is the call graph for this function:

Here is the caller graph for this function:

int CKNMatrixOperation::Gram_schmidt ( CKNVector pVect1,
CKNVector pVect2 
)
static

Doing gam schmidt orthogonalization.

Parameters
pVect1Orthogonalization standard
pVect2Orthogonalization target

Definition at line 2814 of file KNMatrixOperation.cpp.

References GENERAL_TOLERANCE, CKNComplex::GetRealNumber(), IsSameA(), CKNMatrixOperation::CKNVector::MinusVector(), CKNMatrixOperation::CKNVector::Normalize(), CKNMatrixOperation::CKNVector::ScalarMultiple(), and VVDot().

Referenced by CKNLanczosMethod::MergeDegeneratedEigenvalues().

2815 {
2816  CKNComplex result;
2817  CKNVector tempVector;
2818 
2819  CKNMatrixOperation::VVDot(pVect1, pVect2, &result);
2820  if( IsSameA(result.GetRealNumber(), 0, GENERAL_TOLERANCE ))
2821  return 1;
2822 
2823  tempVector = *pVect1;
2824  tempVector.Normalize(true);
2825  pVect2->Normalize(true);
2826 
2827  CKNMatrixOperation::VVDot(&tempVector, pVect2, &result);
2828  tempVector.ScalarMultiple(result);
2829 
2830  pVect2->MinusVector(&tempVector);
2831  pVect2->Normalize(true);
2832 
2833  CKNMatrixOperation::VVDot(pVect1, pVect2, &result);
2834  if( IsSameA(result.GetRealNumber(), 0, GENERAL_TOLERANCE ))
2835  return 1;
2836  else
2837  return 0;
2838 
2839 
2840 }
double GetRealNumber() const
Get real part.
Definition: KNComplex.h:26
#define GENERAL_TOLERANCE
General tolerance definition.
Definition: CKNGlobal.h:48
static bool IsSameA(double operand1, double operand2, double tol)
Compare two double variable.
This class for complex operation and saving value.
Definition: KNComplex.h:18
static bool VVDot(CKNVector *pVector1, CKNVector *pVector2, CKNComplex *pResult)
Between vectors dot product operation.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Compare two double variable.

Parameters
operand1First operand
operand2Second operand
tolDifference tolerance

Definition at line 2789 of file KNMatrixOperation.cpp.

Referenced by CKNLanczosTest::AuditResult(), CKNLanczosTest::AuditResult_Seorth(), CKNLanczosMethod::DoResidualCheck(), CKNLanczosMethod::IntegrateEigenvalues(), CKNLanczosMethod::IntegrateEigenvaluesEx(), IsSame(), and CKNLanczosMethod::MergeDegeneratedEigenvalues().

2790 {
2791  if (fabs(operand1 - operand2) > tol)
2792  return false;
2793  else
2794  return true;
2795 }

Here is the caller graph for this function:

bool CKNMatrixOperation::IsSame ( CKNComplex  operand1,
CKNComplex  operand2,
double  tol 
)
static

Compare two vectors with tolerance.

Parameters
operand1Comparing operand 1
operand2Comparing operand 2
Returns
Comparing result

Definition at line 3190 of file KNMatrixOperation.cpp.

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

3191 {
3192  if( fabs(fabs(operand1.GetRealNumber()) - fabs(operand2.GetRealNumber())) > tol )
3193  return false;
3194 
3195  if( fabs(fabs(operand1.GetImaginaryNumber()) - fabs(operand2.GetImaginaryNumber())) > tol )
3196  return false;
3197  else
3198  return true;
3199 }
double GetImaginaryNumber() const
Get imaginary part.
Definition: KNComplex.h:27
double GetRealNumber() const
Get real part.
Definition: KNComplex.h:26

Here is the call graph for this function:

bool CKNMatrixOperation::IsSame ( CKNVector pVector1,
CKNVector pVector2 
)
static

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

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

Definition at line 3206 of file KNMatrixOperation.cpp.

References GENERAL_TOLERANCE, CKNMatrixOperation::CKNVector::GetNorm(), IsSame(), and CKNMatrixOperation::CKNVector::MinusVector().

3207 {
3208  CKNVector vectorTemp = *pVector1;
3209  double fNorm = 1.0;
3210 
3211  vectorTemp.MinusVector(pVector2);
3212 #ifndef DISABLE_MPI_ROUTINE
3213  fNorm = vectorTemp.GetNorm(true);
3214 #else //DISABLE_MPI_ROUTINE
3215  fNorm = vectorTemp.GetNorm();
3216 #endif //DISABLE_MPI_ROUTINE
3217 
3218  if (IsSame(fNorm, 0.0, GENERAL_TOLERANCE))
3219  return true;
3220  else
3221  return false;
3222 }
#define GENERAL_TOLERANCE
General tolerance definition.
Definition: CKNGlobal.h:48
static bool IsSame(double operand1, double operand2, double tol)
Compare two double variable.

Here is the call graph for this function:

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

Compare two double variable.

Parameters
operand1First operand
operand2Second operand
tolDifference tolerance

Definition at line 2802 of file KNMatrixOperation.cpp.

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

2803 {
2804  if (fabs(fabs(operand1) - fabs(operand2)) > tol)
2805  return false;
2806  else
2807  return true;
2808 }

Here is the caller graph for this function:

void CKNMatrixOperation::MMMul ( CKNDMatrix pMatrix,
CKNDMatrix pMatrixOperand,
CKNDMatrix 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 2758 of file KNMatrixOperation.cpp.

References CKNComplex::Add(), CKNMatrixOperation::CKNDMatrix::BuildMatrixFirst(), CKNMatrixOperation::CKNDMatrix::GetColumnCount(), CKNMatrixOperation::CKNDMatrix::GetElement(), CKNMatrixOperation::CKNDMatrix::GetRowCount(), CKNComplex::MulltiplyComplex(), and CKNMatrixOperation::CKNDMatrix::SetElement().

Referenced by CKNHamiltonianBuilder::BuildACCANeighborFor10Band(), CKNHamiltonianBuilder::FillMatrixFor10Band(), and CKNGeometricShape::RotateMatrix().

2759 {
2760  int i, j, k;
2761  int nRow, nColumn, nL;
2762  if (pMatrix->GetColumnCount() != pMatrixOperand->GetRowCount())
2763  return;
2764 
2765  pResult->BuildMatrixFirst(pMatrix->GetRowCount(), pMatrixOperand->GetColumnCount());
2766 
2767  nL = pMatrixOperand->GetColumnCount();
2768  nRow = pMatrix->GetRowCount();
2769  nColumn = pMatrix->GetColumnCount();
2770  for (k = 0; k < nL; ++k)
2771  {
2772  for (i = 0; i < nRow; ++i)
2773  {
2774  CKNComplex result;
2775  for (j = 0; j < nColumn; ++j)
2776  {
2777  result.Add(CKNComplex::MulltiplyComplex(pMatrix->GetElement(i, j), pMatrixOperand->GetElement(j, k)));
2778  }
2779  pResult->SetElement(i, k, result);
2780  }
2781  }
2782 }
void Add(CKNComplex complex)
Adding operation to this class.
Definition: KNComplex.cpp:68
This class for complex operation and saving value.
Definition: KNComplex.h:18
static CKNComplex MulltiplyComplex(CKNComplex complex1, CKNComplex complex2)
Multiple operation between complex numbers.
Definition: KNComplex.cpp:127

Here is the call graph for this function:

Here is the caller graph for this function:

void CKNMatrixOperation::MVMul ( CKNCSR pAMatrix,
CKNVector pVector,
CKNVector pResult 
)
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 2134 of file KNMatrixOperation.cpp.

References ERROR_WRONG_ORDER_OPERATION, CKNMatrixOperation::CKNCSR::GetColumnCount(), CKNMatrixOperation::CKNCSR::GetRowCount(), CKNMatrixOperation::CKNCSR::m_vectColumn, CKNMatrixOperation::CKNCSR::m_vectRow, CKNMatrixOperation::CKNVector::m_vectValueImaginaryBuffer, CKNMatrixOperation::CKNCSR::m_vectValueImaginaryBuffer, CKNMatrixOperation::CKNVector::m_vectValueRealBuffer, CKNMatrixOperation::CKNCSR::m_vectValueRealBuffer, CKNMPIManager::MergeVector(), and CKNMatrixOperation::CKNVector::SetSize().

Referenced by CKNLanczosResultAudit::AuditResult_EV(), CKNLanczosMethod::DoResidualCheck(), CKNLanczosMethod::MergeDegeneratedEigenvalues(), IKNGeometricUnitCellInfo::RotateAxis(), IKNGeometricUnitCellInfo::RotateNeighbor(), and CKNHamiltonianBuilder::RotateTransMatrixFor10Band().

2135 {
2136  unsigned int i, j, nSize = pAMatrix->GetColumnCount();
2137  CKNVector *pOperandVector = NULL, VOperand;
2138  double *pMatrixReal = NULL, *pMatrixImaginary = NULL;
2139  double *pVectorReal = NULL, *pVectorImaginary = NULL;
2140  double *pResultReal = NULL, *pResultImaginary = NULL;
2141  unsigned int *pMatrixRow = NULL, *pMatrixColumn = NULL;
2142 
2143  VOperand = *pVector;
2144  pOperandVector = &VOperand;
2145 
2146 #ifndef DISABLE_MPI_ROUTINE
2147 
2148  VOperand.SetSize(pAMatrix->GetColumnCount());
2149  CKNMPIManager::MergeVector(pVector, &VOperand, pAMatrix->GetColumnCount());
2150  pOperandVector = &VOperand;
2151 #else
2152  pOperandVector = pVector;
2153 #endif
2154 
2155  if (nSize != pOperandVector->GetSize())
2156  {
2158  return;
2159  }
2160 
2161  nSize = pAMatrix->GetRowCount();
2162  pMatrixReal = pAMatrix->m_vectValueRealBuffer.data();
2163  pMatrixImaginary = pAMatrix->m_vectValueImaginaryBuffer.data();
2164  pMatrixRow = pAMatrix->m_vectRow.data();
2165  pMatrixColumn = pAMatrix->m_vectColumn.data();
2166  pVectorReal = pOperandVector->m_vectValueRealBuffer.data();
2167  pVectorImaginary = pOperandVector->m_vectValueImaginaryBuffer.data();
2168  pResultReal = pResult->m_vectValueRealBuffer.data();
2169  pResultImaginary = pResult->m_vectValueImaginaryBuffer.data();
2170 
2171  unsigned int input_real_size = pOperandVector->m_vectValueRealBuffer.size();
2172  unsigned int input_imaginary_size = pOperandVector->m_vectValueImaginaryBuffer.size();
2173  unsigned int output_real_size = pResult->m_vectValueRealBuffer.size();
2174  unsigned int output_imaginary_size = pResult->m_vectValueImaginaryBuffer.size();
2175 
2176  #pragma omp parallel for
2177  for ( i = 0; i < nSize; i++)
2178  {
2179  double real_sum = 0.0;
2180  double imaginary_sum = 0.0;
2181  const unsigned int nSubStart = pMatrixRow[i];
2182  const unsigned int nSubEnd = pMatrixRow[i + 1];
2183 
2184 
2185  for ( j = nSubStart; j < nSubEnd; j++)
2186  {
2187  const unsigned int nColIndex = pMatrixColumn[j];
2188  const double m_real = pMatrixReal[j];
2189  const double m_imaginary = pMatrixImaginary[j];
2190  const double v_real = pVectorReal[nColIndex];
2191  const double v_imaginary = pVectorImaginary[nColIndex];
2192 
2193  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2194  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2195  }
2196 
2197  pResultReal[i] = real_sum;
2198  pResultImaginary[i] = imaginary_sum;
2199  }
2200 #ifndef DISABLE_MPI_ROUTINE
2201  VOperand.Finalize();
2202 #endif //DISABLE_MPI_ROUTINE
2203 }
static void MergeVector(CKNMatrixOperation::CKNVector *pVector, CKNMatrixOperation::CKNVector *pResultVector, unsigned int nMergeSize)
Merge vector to sub rank.
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: CKNGlobal.h:64

Here is the call graph for this function:

Here is the caller graph for this function:

void CKNMatrixOperation::MVMul ( CKNDMatrix pMatrix,
CKNVector pVector,
CKNVector 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 2731 of file KNMatrixOperation.cpp.

References CKNComplex::Add(), CKNMatrixOperation::CKNVector::GetAt(), CKNMatrixOperation::CKNDMatrix::GetColumnCount(), CKNMatrixOperation::CKNDMatrix::GetElement(), CKNMatrixOperation::CKNDMatrix::GetRowCount(), CKNMatrixOperation::CKNVector::GetSize(), CKNComplex::MulltiplyComplex(), CKNMatrixOperation::CKNVector::SetAt(), and CKNMatrixOperation::CKNVector::SetSize().

2732 {
2733  int i, j, nRow, nColumn;
2734 
2735  if (pMatrix->GetColumnCount() != pVector->GetSize())
2736  return;
2737 
2738  pResult->SetSize(pVector->GetSize());
2739 
2740  nRow = pMatrix->GetRowCount();
2741  nColumn = pMatrix->GetColumnCount();
2742  for (i = 0; i < nRow; ++i)
2743  {
2744  CKNComplex result;
2745  for (j = 0; j < nColumn; ++j)
2746  {
2747  result.Add(CKNComplex::MulltiplyComplex(pMatrix->GetElement(i, j), pVector->GetAt(j)));
2748  }
2749  pResult->SetAt(i, result);
2750  }
2751 }
void Add(CKNComplex complex)
Adding operation to this class.
Definition: KNComplex.cpp:68
This class for complex operation and saving value.
Definition: KNComplex.h:18
static CKNComplex MulltiplyComplex(CKNComplex complex1, CKNComplex complex2)
Multiple operation between complex numbers.
Definition: KNComplex.cpp:127

Here is the call graph for this function:

void CKNMatrixOperation::MVMulEx_AsyncCommWithLocalBlocks ( CKNMatrixOperation::CKNCSR mylocalblock,
CKNMatrixOperation::CKNCSR leftlocalblock,
CKNMatrixOperation::CKNCSR rightlocalblock,
CKNVector pVector,
CKNVector 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 2211 of file KNMatrixOperation.cpp.

References ERROR_WRONG_ORDER_OPERATION, CKNMPIManager::GetCurrentRank(), CKNMPIManager::GetMPIComm(), CKNMatrixOperation::CKNCSR::GetRowCount(), CKNMatrixOperation::CKNVector::GetSize(), CKNMPIManager::GetTotalNodeCount(), CKNMatrixOperation::CKNCSR::m_vectColumn, CKNMatrixOperation::CKNCSR::m_vectRow, CKNMatrixOperation::CKNVector::m_vectValueImaginaryBuffer, CKNMatrixOperation::CKNCSR::m_vectValueImaginaryBuffer, CKNMatrixOperation::CKNVector::m_vectValueRealBuffer, CKNMatrixOperation::CKNCSR::m_vectValueRealBuffer, CKNTimeMeasurement::MeasurementEnd(), CKNTimeMeasurement::MeasurementStart(), CKNTimeMeasurement::MV_COMM, pColumn, pRow, and X_largest.

2212 {
2213  unsigned int nSize, B, Brt, Blt;
2214  double *pMatrixValueReal = NULL, *pOperandVectorReal = NULL, *pResultVectorReal = NULL;
2215  double *pMatrixValueImaginary = NULL, *pOperandVectorImaginary = NULL, *pResultVectorImaginary = NULL;
2216  int tag = 1002;
2217  int myrank = CKNMPIManager::GetCurrentRank();
2218  int ncpus = CKNMPIManager::GetTotalNodeCount();
2219  int left_neighbor = (myrank - 1 + ncpus) % ncpus;
2220  int right_neighbor = (myrank + 1) % ncpus;
2221  MPI_Request req_sr[2];
2222  MPI_Status stat_sr[2];
2223  // XXX jinpil: pRow, pColumn should be local in offload directives
2224  unsigned int *pRow = mylocalblock->m_vectRow.data();
2225  unsigned int *pColumn = mylocalblock->m_vectColumn.data();
2226 
2227 #ifndef _WIN32
2228  __assume_aligned(X, 64);
2229  __assume_aligned(X, 64);
2230  __assume_aligned(Xrt, 64);
2231 
2232  __assume_aligned(pMatrixValueReal, 64);
2233  __assume_aligned(pMatrixValueImaginary, 64);
2234  __assume_aligned(pOperandVectorReal, 64);
2235  __assume_aligned(pOperandVectorImaginary, 64);
2236  __assume_aligned(pResultVectorReal, 64);
2237  __assume_aligned(pResultVectorImaginary, 64);
2238  __assume_aligned(pRow, 64);
2239  __assume_aligned(pColumn, 64);
2240 #endif //_WIN32
2241 
2242  pMatrixValueReal = mylocalblock->m_vectValueRealBuffer.data();
2243  pOperandVectorReal = pVector->m_vectValueRealBuffer.data();
2244  pResultVectorReal = pResult->m_vectValueRealBuffer.data();
2245 
2246  pMatrixValueImaginary = mylocalblock->m_vectValueImaginaryBuffer.data();
2247  pOperandVectorImaginary = pVector->m_vectValueImaginaryBuffer.data();
2248  pResultVectorImaginary = pResult->m_vectValueImaginaryBuffer.data();;
2249 
2250  nSize = mylocalblock->GetRowCount();
2251 
2252  if (nSize != pVector->GetSize())
2253  {
2255  return;
2256  }
2257 
2258  B = nSize;
2259  Brt = 0;
2260  Blt = 0;
2261 
2262  for (int ii = 0; ii< nSize; ii++)
2263  {
2264  X[2 * ii] = pOperandVectorReal[ii];
2265  X[2 * ii + 1] = pOperandVectorImaginary[ii];
2266  }
2267 
2269 
2270  MPI_Irecv(&Brt, 1, MPI_INT, right_neighbor, tag, CKNMPIManager::GetMPIComm(), &req_sr[0]);
2271  MPI_Isend(&B, 1, MPI_INT, left_neighbor, tag, CKNMPIManager::GetMPIComm(), &req_sr[1]);
2272  MPI_Waitall(2, req_sr, stat_sr); // now Brt has B of right neighbor.
2273 
2274  MPI_Irecv(Xrt, 2 * Brt, MPI_DOUBLE, right_neighbor, tag, CKNMPIManager::GetMPIComm(), &req_sr[0]); // receive from bottom neighbor
2275  MPI_Isend(X, 2 * B, MPI_DOUBLE, left_neighbor, tag, CKNMPIManager::GetMPIComm(), &req_sr[1]); // send to top neighbor
2276 
2278 
2279  unsigned int input_size = X_largest * 2;
2280  unsigned int output_real_size = pResult->m_vectValueRealBuffer.size();
2281  unsigned int output_imaginary_size = pResult->m_vectValueImaginaryBuffer.size();
2282 
2283 
2284 #ifdef _ENABLE_PAPI
2285  long long papi_values[4];
2286  PAPI_start(papi_event_set);
2287 #endif
2288 
2290 #pragma offload target(mic:phi_tid) \
2291  nocopy(*pMatrixValueReal : REUSE) \
2292  nocopy(*pMatrixValueImaginary : REUSE) \
2293  nocopy(*pRow : REUSE) \
2294  nocopy(*pColumn : REUSE) \
2295  in(X[0:input_size] : REUSE) \
2296  nocopy(*pResultVectorReal : REUSE) \
2297  nocopy(*pResultVectorImaginary : REUSE)
2298  //*/
2299 #pragma omp parallel for
2300  for (unsigned int i = 0; i < nSize; i++)
2301  {
2302  double real_sum = 0.0;
2303  double imaginary_sum = 0.0;
2304  const unsigned int nSubStart = pRow[i ];
2305  const unsigned int nSubEnd = pRow[i + 1];
2306  for (unsigned int j = nSubStart; j < nSubEnd; j++)
2307  {
2308  const unsigned int nColIndex = pColumn[j];
2309  const double m_real = pMatrixValueReal[j];
2310  const double m_imaginary = pMatrixValueImaginary[j];
2311  const double v_real = X[2 * nColIndex];
2312  const double v_imaginary = X[2 * nColIndex + 1];
2313 
2314  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2315  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2316  }
2317 
2318  pResultVectorReal[i] = real_sum;
2319  pResultVectorImaginary[i] = imaginary_sum;
2320  }
2321 
2322 #ifdef _ENABLE_PAPI
2323  PAPI_stop(papi_event_set, papi_values);
2324  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]);
2325  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]);
2326 #endif
2327 
2329 
2330  MPI_Waitall(2, req_sr, stat_sr); // now Xrt has X of right neighbor.
2331 
2332  MPI_Irecv(&Blt, 1, MPI_INT, left_neighbor, tag, CKNMPIManager::GetMPIComm(), &req_sr[0]);
2333  MPI_Isend(&B, 1, MPI_INT, right_neighbor, tag, CKNMPIManager::GetMPIComm(), &req_sr[1]);
2334  MPI_Waitall(2, req_sr, stat_sr); // now Blt has B of left neighbor.
2335 
2336 
2337  MPI_Irecv(Xlt, 2 * Blt, MPI_DOUBLE, left_neighbor, tag, CKNMPIManager::GetMPIComm(), &req_sr[0]);
2338  MPI_Isend(X, 2 * B, MPI_DOUBLE, right_neighbor, tag, CKNMPIManager::GetMPIComm(), &req_sr[1]);
2339 
2341 
2342  pMatrixValueReal = rightlocalblock->m_vectValueRealBuffer.data();
2343  pMatrixValueImaginary = rightlocalblock->m_vectValueImaginaryBuffer.data();
2344  pRow = rightlocalblock->m_vectRow.data();
2345  pColumn = rightlocalblock->m_vectColumn.data();
2346 
2347 #ifdef _ENABLE_PAPI
2348  PAPI_start(papi_event_set);
2349 #endif
2350 
2352 #pragma offload target(mic:phi_tid) \
2353  nocopy(*pMatrixValueReal : REUSE) \
2354  nocopy(*pMatrixValueImaginary : REUSE) \
2355  nocopy(*pRow : REUSE) \
2356  nocopy(*pColumn : REUSE) \
2357  in(Xrt[0:input_size] : REUSE) \
2358  nocopy(*pResultVectorReal : REUSE) \
2359  nocopy(*pResultVectorImaginary : REUSE)
2360  //*/
2361 #pragma omp parallel for
2362  for (unsigned int i = 0; i < nSize; i++)
2363  {
2364  double real_sum = 0.0;
2365  double imaginary_sum = 0.0;
2366  const unsigned int nSubStart = pRow[i ];
2367  const unsigned int nSubEnd = pRow[i + 1];
2368  for (unsigned int j = nSubStart; j < nSubEnd; j++)
2369  {
2370  const unsigned int nColIndex = pColumn[j];
2371  const double m_real = pMatrixValueReal[j];
2372  const double m_imaginary = pMatrixValueImaginary[j];
2373  const double v_real = Xrt[2 * nColIndex];
2374  const double v_imaginary = Xrt[2 * nColIndex + 1];
2375 
2376  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2377  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2378  }
2379 
2380  pResultVectorReal[i] += real_sum;
2381  pResultVectorImaginary[i] += imaginary_sum;
2382  }
2383 
2384 #ifdef _ENABLE_PAPI
2385  PAPI_stop(papi_event_set, papi_values);
2386  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]);
2387  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]);
2388 #endif
2389 
2391  MPI_Waitall(2, req_sr, stat_sr); // now Xlt has X of left neighbor.
2393 
2394  pMatrixValueReal = leftlocalblock->m_vectValueRealBuffer.data();
2395  pMatrixValueImaginary = leftlocalblock->m_vectValueImaginaryBuffer.data();
2396  pRow = leftlocalblock->m_vectRow.data();
2397  pColumn = leftlocalblock->m_vectColumn.data();
2398 
2399 #ifdef _ENABLE_PAPI
2400  PAPI_start(papi_event_set);
2401 #endif
2402 
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(Xlt[0:input_size] : REUSE) \
2410  out(pResultVectorReal[0:output_real_size] : REUSE) \
2411  out(pResultVectorImaginary[0:output_imaginary_size] : 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 = Xlt[2 * nColIndex];
2426  const double v_imaginary = Xlt[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("[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]);
2439  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]);
2440 #endif
2441 }
static MPI_Comm GetMPIComm()
Definition: KNMPIManager.h:67
unsigned int X_largest
static unsigned int * pRow
For MPI Optimized operation using.
double_vector_t m_vectValueRealBuffer
A member variable for saving none zero elements.
static void MeasurementEnd(MEASUREMENT_INDEX index)
Measurement end for part.
double_vector_t m_vectValueImaginaryBuffer
A member variable for saving none zero elements.
static int GetTotalNodeCount()
Definition: KNMPIManager.h:44
uint_vector_t m_vectColumn
A member variable for saving column information.
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: CKNGlobal.h:64
static int GetCurrentRank()
Definition: KNMPIManager.h:42
static unsigned int * pColumn
For MPI Optimized operation using.
static void MeasurementStart(MEASUREMENT_INDEX index)
Measurement start for part.
uint_vector_t m_vectRow
A member variable for saving row information.

Here is the call graph for this function:

void CKNMatrixOperation::MVMulEx_Optimal ( CKNCSR pAMatrix,
CKNVector pVector,
CKNVector pResult,
unsigned int  nSizeFromPrevRank,
unsigned int  nSizeFromNextRank,
CKNVector VTemp,
int  nSizePHI 
)
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 2452 of file KNMatrixOperation.cpp.

References ERROR_WRONG_ORDER_OPERATION, CKNMatrixOperation::CKNCSR::GetColumnCount(), CKNMatrixOperation::CKNCSR::GetRowCount(), CKNMPIManager::GetTotalNodeCount(), CKNMatrixOperation::CKNCSR::m_fFirstRowIndex, CKNMatrixOperation::CKNCSR::m_vectColumn, CKNMatrixOperation::CKNCSR::m_vectRow, CKNMatrixOperation::CKNVector::m_vectValueImaginaryBuffer, CKNMatrixOperation::CKNCSR::m_vectValueImaginaryBuffer, CKNMatrixOperation::CKNVector::m_vectValueRealBuffer, CKNMatrixOperation::CKNCSR::m_vectValueRealBuffer, CKNMPIManager::MergeVectorEx_Optimal(), CKNMatrixOperation::CKNCSR::nComponentsFirstUnitCell, and CKNMatrixOperation::CKNCSR::nComponentsLastUnitCell.

Referenced by CKNLanczosMethod::LanczosIterationLoop().

2453 {
2454  unsigned int nSize = pAMatrix->GetColumnCount();
2455  CKNVector *pOperandVector = NULL;
2456  double *pMatrixReal = NULL, *pMatrixImaginary = NULL;
2457  double *pVectorReal = NULL, *pVectorImaginary = NULL;
2458  double *pResultReal = NULL, *pResultImaginary = NULL;
2459  unsigned int *pMatrixRow = NULL, *pMatrixColumn = NULL;
2460  char sigval;
2461  unsigned int input_size1, input_size2, input_size3;
2462  unsigned int input_offset1, input_offset2, input_offset3, offsettmp[3];
2463  unsigned int output_size, output_offset;
2464 
2465 #ifndef DISABLE_MPI_ROUTINE
2466  pOperandVector = VTemp;
2467  pVectorReal = pOperandVector->m_vectValueRealBuffer.data();
2468  pVectorImaginary = pOperandVector->m_vectValueImaginaryBuffer.data();
2469 
2470  // memset(pVectorReal, 0, sizeof(double)*pOperandVector->GetSize());
2471  // memset(pVectorImaginary, 0, sizeof(double)*pOperandVector->GetSize());
2472 
2473  CKNMPIManager::MergeVectorEx_Optimal(pVector, pOperandVector, pAMatrix->GetColumnCount(), pAMatrix->m_fFirstRowIndex, nSizeFromPrevRank, nSizeFromNextRank, pAMatrix->nComponentsFirstUnitCell, pAMatrix->nComponentsLastUnitCell, offsettmp);
2474 
2475 #else
2476  pOperandVector = pVector;
2477 #endif
2478 
2479  if (nSize != pOperandVector->GetSize())
2480  {
2482  return;
2483  }
2484 
2485  pMatrixReal = pAMatrix->m_vectValueRealBuffer.data();
2486  pMatrixImaginary = pAMatrix->m_vectValueImaginaryBuffer.data();
2487  pMatrixRow = pAMatrix->m_vectRow.data();
2488  pMatrixColumn = pAMatrix->m_vectColumn.data();
2489  pResultReal = pResult->m_vectValueRealBuffer.data();
2490  pResultImaginary = pResult->m_vectValueImaginaryBuffer.data();
2491  nSize = pAMatrix->GetRowCount();
2492 
2494  {
2495  input_size1 = pOperandVector->m_vectValueRealBuffer.size();
2496  input_offset1 = 0;
2497 
2498 #pragma offload_transfer target(mic:phi_tid) in(pVectorReal[input_offset1:input_size1] : REUSE)
2499 #pragma offload_transfer target(mic:phi_tid) in(pVectorImaginary[input_offset1:input_size1] : REUSE)
2500  }
2501  else
2502  {
2503  input_size1 = nSizeFromPrevRank;
2504  input_size2 = nSize;
2505  input_size3 = nSizeFromNextRank;
2506  input_offset1 = offsettmp[0];
2507  input_offset2 = offsettmp[1];
2508  input_offset3 = offsettmp[2];
2509 
2510 #pragma offload_transfer target(mic:phi_tid) in(pVectorReal[input_offset1:input_size1] : REUSE)
2511 #pragma offload_transfer target(mic:phi_tid) in(pVectorImaginary[input_offset1:input_size1] : REUSE)
2512 #pragma offload_transfer target(mic:phi_tid) in(pVectorReal[input_offset2:input_size2] : REUSE)
2513 #pragma offload_transfer target(mic:phi_tid) in(pVectorImaginary[input_offset2:input_size2] : REUSE)
2514 #pragma offload_transfer target(mic:phi_tid) in(pVectorReal[input_offset3:input_size3] : REUSE)
2515 #pragma offload_transfer target(mic:phi_tid) in(pVectorImaginary[input_offset3:input_size3] : REUSE)
2516  }
2517 
2518  output_size = nSizePHI;
2519  output_offset = 0;
2520 
2521  // FIXME jinpil:
2522  // nocopy(pMatrixReal : REUSE)
2523  // correct directive syntax, but segmentation fault without *
2524  // Xeon Phi device cannot find the correct pointer value
2525  // compiler bug?
2526  // FIXME allocate pVectorReal, pVectorImaginary outside the Lanczos loop
2528 
2529 #pragma offload target(mic:phi_tid) \
2530  nocopy(*pMatrixReal : REUSE) \
2531  nocopy(*pMatrixImaginary : REUSE) \
2532  nocopy(*pMatrixRow : REUSE) \
2533  nocopy(*pMatrixColumn : REUSE) \
2534  nocopy(*pVectorReal : REUSE) \
2535  nocopy(*pVectorImaginary : REUSE) \
2536  out(pResultReal[output_offset:output_size] : REUSE) \
2537  out(pResultImaginary[output_offset:output_size] : REUSE) \
2538  signal(&sigval)
2539  //*/
2540 
2541 #pragma omp parallel for
2542  for (unsigned int i = 0; i < nSizePHI; i++)
2543  {
2544  double real_sum = 0.0;
2545  double imaginary_sum = 0.0;
2546  const unsigned int nSubStart = pMatrixRow[i];
2547  const unsigned int nSubEnd = pMatrixRow[i + 1];
2548 
2549 
2550  for (unsigned int j = nSubStart; j < nSubEnd; j++)
2551  {
2552  const unsigned int nColIndex = pMatrixColumn[j];
2553  const double m_real = pMatrixReal[j];
2554  const double m_imaginary = pMatrixImaginary[j];
2555  const double v_real = pVectorReal[nColIndex];
2556  const double v_imaginary = pVectorImaginary[nColIndex];
2557 
2558  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2559  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2560  }
2561 
2562  pResultReal[i] = real_sum;
2563  pResultImaginary[i] = imaginary_sum;
2564  }
2565 
2566 #pragma omp parallel for
2567  for (unsigned int i = nSizePHI; i < nSize; i++)
2568  {
2569  double real_sum = 0.0;
2570  double imaginary_sum = 0.0;
2571  const unsigned int nSubStart = pMatrixRow[i];
2572  const unsigned int nSubEnd = pMatrixRow[i + 1];
2573 
2574 
2575  for (unsigned int j = nSubStart; j < nSubEnd; j++)
2576  {
2577  const unsigned int nColIndex = pMatrixColumn[j];
2578  const double m_real = pMatrixReal[j];
2579  const double m_imaginary = pMatrixImaginary[j];
2580  const double v_real = pVectorReal[nColIndex];
2581  const double v_imaginary = pVectorImaginary[nColIndex];
2582 
2583  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2584  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2585  }
2586 
2587  pResultReal[i] = real_sum;
2588  pResultImaginary[i] = imaginary_sum;
2589  }
2590 
2591 #pragma offload_wait target(mic:phi_tid) wait(&sigval)
2592 
2593 }
static int GetTotalNodeCount()
Definition: KNMPIManager.h:44
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: CKNGlobal.h:64
static void MergeVectorEx_Optimal(CKNMatrixOperation::CKNVector *pVector, CKNMatrixOperation::CKNVector *pResultVector, unsigned int nMergeSize, double fFirstIndex, unsigned int nSizeFromPrevRank, unsigned int nSizeFromNextRank, unsigned int nSizetoPrevRank, unsigned int nSizetoNextRank, unsigned int *)
Merge vector for 1 layer exchanging.

Here is the call graph for this function:

Here is the caller graph for this function:

void CKNMatrixOperation::MVMulOptimal ( CKNCSR pAMatrix,
CKNVector pVector,
CKNVector pResult 
)
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 2600 of file KNMatrixOperation.cpp.

References ERROR_WRONG_ORDER_OPERATION, CKNMatrixOperation::CKNVector::Finalize(), CKNMatrixOperation::CKNCSR::GetColumnCount(), CKNMatrixOperation::CKNCSR::GetRowCount(), CKNMatrixOperation::CKNCSR::m_fFirstRowIndex, CKNMatrixOperation::CKNCSR::m_vectColumn, CKNMatrixOperation::CKNCSR::m_vectRow, CKNMatrixOperation::CKNVector::m_vectValueImaginaryBuffer, CKNMatrixOperation::CKNCSR::m_vectValueImaginaryBuffer, CKNMatrixOperation::CKNVector::m_vectValueRealBuffer, CKNMatrixOperation::CKNCSR::m_vectValueRealBuffer, CKNMPIManager::MergeVectorOptimal(), and CKNMatrixOperation::CKNVector::SetSize().

Referenced by CKNLanczosMethod::LanczosIterationLoop().

2601 {
2602  unsigned int i, j, nSize = pAMatrix->GetColumnCount();
2603  CKNVector *pOperandVector = NULL;
2604  double *pMatrixReal = NULL, *pMatrixImaginary = NULL;
2605  double *pVectorReal = NULL, *pVectorImaginary = NULL;
2606  double *pResultReal = NULL, *pResultImaginary = NULL;
2607  unsigned int *pMatrixRow = NULL, *pMatrixColumn = NULL;
2608 #ifndef DISABLE_MPI_ROUTINE
2609  CKNVector VOperand;
2610 
2611  VOperand.SetSize(pAMatrix->GetColumnCount());
2612  CKNMPIManager::MergeVectorOptimal(pVector, &VOperand, pAMatrix->GetColumnCount(), pAMatrix->m_fFirstRowIndex);
2613  pOperandVector = &VOperand;
2614 #else
2615  pOperandVector = pVector;
2616 #endif
2617 
2618  if (nSize != pOperandVector->GetSize())
2619  {
2621  return;
2622  }
2623 
2624  nSize = pAMatrix->GetRowCount();
2625  pMatrixReal = pAMatrix->m_vectValueRealBuffer.data();
2626  pMatrixImaginary = pAMatrix->m_vectValueImaginaryBuffer.data();
2627  pMatrixRow = pAMatrix->m_vectRow.data();
2628  pMatrixColumn = pAMatrix->m_vectColumn.data();
2629  pVectorReal = pOperandVector->m_vectValueRealBuffer.data();
2630  pVectorImaginary = pOperandVector->m_vectValueImaginaryBuffer.data();
2631  pResultReal = pResult->m_vectValueRealBuffer.data();
2632  pResultImaginary = pResult->m_vectValueImaginaryBuffer.data();
2633 
2634  unsigned int input_real_size = pOperandVector->m_vectValueRealBuffer.size();
2635  unsigned int input_imaginary_size = pOperandVector->m_vectValueImaginaryBuffer.size();
2636  unsigned int output_real_size = pResult->m_vectValueRealBuffer.size();
2637  unsigned int output_imaginary_size = pResult->m_vectValueImaginaryBuffer.size();
2638 
2639 // FIXME jinpil:
2640 // nocopy(pMatrixReal : REUSE)
2641 // correct directive syntax, but segmentation fault without *
2642 // Xeon Phi device cannot find the correct pointer value
2643 // compiler bug?
2644 // FIXME allocate pVectorReal, pVectorImaginary outside the Lanczos loop
2646 #pragma offload target(mic:phi_tid) \
2647  nocopy(*pMatrixReal : REUSE) \
2648  nocopy(*pMatrixImaginary : REUSE) \
2649  nocopy(*pMatrixRow : REUSE) \
2650  nocopy(*pMatrixColumn : REUSE) \
2651  in(pVectorReal[0:input_real_size] : LOCAL) \
2652  in(pVectorImaginary[0:input_imaginary_size] : LOCAL) \
2653  out(pResultReal[0:output_real_size] : REUSE) \
2654  out(pResultImaginary[0:output_imaginary_size] : REUSE)
2655 //*/
2656 #pragma omp parallel for
2657  for ( i = 0; i < nSize; i++)
2658  {
2659  double real_sum = 0.0;
2660  double imaginary_sum = 0.0;
2661  const unsigned int nSubStart = pMatrixRow[i];
2662  const unsigned int nSubEnd = pMatrixRow[i + 1];
2663 
2664 
2665  for ( j = nSubStart; j < nSubEnd; j++)
2666  {
2667  const unsigned int nColIndex = pMatrixColumn[j];
2668  const double m_real = pMatrixReal[j];
2669  const double m_imaginary = pMatrixImaginary[j];
2670  const double v_real = pVectorReal[nColIndex];
2671  const double v_imaginary = pVectorImaginary[nColIndex];
2672 
2673  real_sum += m_real * v_real - m_imaginary * v_imaginary;
2674  imaginary_sum += m_real * v_imaginary + m_imaginary * v_real;
2675  }
2676 
2677  pResultReal[i] = real_sum;
2678  pResultImaginary[i] = imaginary_sum;
2679  }
2680 #ifndef DISABLE_MPI_ROUTINE
2681  VOperand.Finalize();
2682 #endif //DISABLE_MPI_ROUTINE
2683 }
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: CKNGlobal.h:64
static void MergeVectorOptimal(CKNMatrixOperation::CKNVector *pSrcVector, CKNMatrixOperation::CKNVector *pResultVector, unsigned int nMergeSize, double fFirstIndex)
Merge vector to sub rank, operated without vector class member function call.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 3050 of file KNMatrixOperation.cpp.

References CKNMatrixOperation::CKNCSR::GetColumnCount(), CKNMatrixOperation::CKNCSR::GetFirstRowIndex(), CKNComplex::GetImaginaryNumber(), CKNComplex::GetRealNumber(), CKNMatrixOperation::CKNCSR::GetRowCount(), CKNMatrixOperation::CKNCSR::GetValue(), CKNMatrixOperation::CKNCSR::m_vectColumn, CKNMatrixOperation::CKNCSR::m_vectRow, pColumn, pRow, CKNMatrixOperation::CKNCSR::SetAt(), CKNComplex::SetImaginaryNumber(), and CKNComplex::SetRealNumber().

Referenced by CKNLanczosLaunching::LaunchingLanczos().

3051 {
3052  CKNMatrixOperation::pRow = source->m_vectRow.data();
3053  CKNMatrixOperation::pColumn = source->m_vectColumn.data();
3054  //CKNMemoryManager::LPVECTOR_ELEMENTS lpMatrixValueElement = NULL;
3055  CKNComplex *pData = NULL;
3056  unsigned int my_nnz, left_nnz, right_nnz;
3057  CKNComplex curval;
3058  int isthisrowfilled;
3059 
3060  //lpMatrixValueElement = source->GetValueElement();
3061 
3062  // 1. Update left block
3063 
3064  left_nnz = 0;
3065 
3066  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
3067  {
3068  isthisrowfilled = -1;
3069  unsigned int nSubStart = CKNMatrixOperation::pRow[ii], nSubEnd = CKNMatrixOperation::pRow[ii+1];
3070  unsigned int startColIndex = (int)left->GetFirstRowIndex(), endColIndex = startColIndex + left->GetColumnCount() - 1;
3071 
3072  for (unsigned int jj = nSubStart; jj < nSubEnd; jj++)
3073  {
3074  unsigned int nColIndex = CKNMatrixOperation::pColumn[jj];
3075 
3076  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
3077  {
3078  isthisrowfilled = 0;
3079  left_nnz++;
3080  //curval.SetRealNumber(lpMatrixValueElement->pfReal[jj]); curval.SetImaginaryNumber(lpMatrixValueElement->pfImaginary[jj]);
3081  pData = source->GetValue(jj);
3082  curval.SetRealNumber(pData->GetRealNumber()); curval.SetImaginaryNumber(pData->GetImaginaryNumber());
3083  left->SetAt(curval, ii, nColIndex-startColIndex);
3084  }
3085  }
3086 
3087  if(isthisrowfilled == -1)
3088  {
3089  left_nnz++;
3090  curval.SetRealNumber(0.0); curval.SetImaginaryNumber(0.0);
3091  left->SetAt(curval, ii, 0);
3092  }
3093  }
3094 
3095 // if(CKNMPIManager::IsRootRank())
3096 // printf("Left block update completed: left_nnz = %d (computed), %d (CSR-allocated)\n", left_nnz, left->GetNoneZeroCount());
3097 
3098  // 2. Figure out nnz: right block
3099 
3100  right_nnz = 0;
3101 
3102  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
3103  {
3104  isthisrowfilled = -1;
3105  unsigned int nSubStart = CKNMatrixOperation::pRow[ii], nSubEnd = CKNMatrixOperation::pRow[ii+1];
3106  unsigned int startColIndex = (int)right->GetFirstRowIndex(), endColIndex = startColIndex + right->GetColumnCount() - 1;
3107 
3108  for (unsigned int jj = nSubStart; jj < nSubEnd; jj++)
3109  {
3110  unsigned int nColIndex = CKNMatrixOperation::pColumn[jj];
3111  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
3112  {
3113  isthisrowfilled = 0;
3114  right_nnz++;
3115  //curval.SetRealNumber(lpMatrixValueElement->pfReal[jj]); curval.SetImaginaryNumber(lpMatrixValueElement->pfImaginary[jj]);
3116  pData = source->GetValue(jj);
3117  curval.SetRealNumber(pData->GetRealNumber()); curval.SetImaginaryNumber(pData->GetImaginaryNumber());
3118  right->SetAt(curval, ii, nColIndex-startColIndex);
3119  }
3120 
3121  }
3122 
3123  if(isthisrowfilled == -1)
3124  {
3125  right_nnz++;
3126  curval.SetRealNumber(0.0); curval.SetImaginaryNumber(0.0);
3127  right->SetAt(curval, ii, 0);
3128  }
3129  }
3130 
3131 // if(CKNMPIManager::IsRootRank())
3132 // printf("Right block update completed: right_nnz = %d (computed), %d (CSR-allocated)\n", right_nnz, right->GetNoneZeroCount());
3133 
3134  // 3. Figure out nnz: my block
3135 
3136  my_nnz = 0;
3137 
3138  for (unsigned int ii = 0; ii < source->GetRowCount(); ii++)
3139  {
3140  unsigned int nSubStart = CKNMatrixOperation::pRow[ii], nSubEnd = CKNMatrixOperation::pRow[ii+1];
3141  unsigned int startColIndex = (int)mine->GetFirstRowIndex(), endColIndex = startColIndex + mine->GetColumnCount() - 1;
3142 
3143  for(unsigned int jj = nSubStart; jj < nSubEnd; jj++)
3144  {
3145  unsigned int nColIndex = CKNMatrixOperation::pColumn[jj];
3146  if(startColIndex <= nColIndex && nColIndex <= endColIndex)
3147  {
3148  my_nnz++;
3149  //curval.SetRealNumber(lpMatrixValueElement->pfReal[jj]); curval.SetImaginaryNumber(lpMatrixValueElement->pfImaginary[jj]);
3150  pData = source->GetValue(jj);
3151  curval.SetRealNumber(pData->GetRealNumber()); curval.SetImaginaryNumber(pData->GetImaginaryNumber());
3152  mine->SetAt(curval, ii, nColIndex-startColIndex);
3153  }
3154  }
3155  }
3156 
3157 // if(CKNMPIManager::IsRootRank())
3158 // printf("My block update completed: my_nnz = %d (computed), %d (CSR-allocated)\n", my_nnz, mine->GetNoneZeroCount());
3159 };
double GetImaginaryNumber() const
Get imaginary part.
Definition: KNComplex.h:27
static unsigned int * pRow
For MPI Optimized operation using.
double GetRealNumber() const
Get real part.
Definition: KNComplex.h:26
unsigned int GetColumnCount()
Getting row size of matrix.
uint_vector_t m_vectColumn
A member variable for saving column information.
bool SetAt(CKNComplex number, unsigned int nRow, unsigned int nColumn)
Set element to specific index.
double GetFirstRowIndex()
Set first row index.
CKNComplex * GetValue(unsigned int nIndex)
Getting none zero element value by index.
static unsigned int * pColumn
For MPI Optimized operation using.
void SetRealNumber(double fRealNumber)
Set real part.
Definition: KNComplex.h:31
This class for complex operation and saving value.
Definition: KNComplex.h:18
uint_vector_t m_vectRow
A member variable for saving row information.
void SetImaginaryNumber(double fImaginaryNumber)
Set imagenary part.
Definition: KNComplex.h:32

Here is the call graph for this function:

Here is the caller graph for this function:

bool CKNMatrixOperation::VVDot ( CKNVector pVector1,
CKNVector pVector2,
CKNComplex 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 2691 of file KNMatrixOperation.cpp.

References CKNMPIManager::AllReduceComlex(), ERROR_WRONG_ORDER_OPERATION, CKNMatrixOperation::CKNVector::GetSize(), CKNMatrixOperation::CKNVector::m_vectValueImaginaryBuffer, CKNMatrixOperation::CKNVector::m_vectValueRealBuffer, CKNComplex::SetComplexNumber(), and CKNTimeMeasurement::VV_COMM.

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

2692 {
2693  double *pOp1Real = NULL, *pOp1Imaginary = NULL;
2694  double *pOp2Real = NULL, *pOp2Imaginary = NULL;
2695  unsigned int i, nSize = pVector1->GetSize();
2696 
2697  if (nSize != pVector2->GetSize())
2698  {
2700  return false;
2701  }
2702 
2703  pOp1Real = pVector1->m_vectValueRealBuffer.data();
2704  pOp1Imaginary = pVector1->m_vectValueImaginaryBuffer.data();
2705 
2706  pOp2Real = pVector2->m_vectValueRealBuffer.data();
2707  pOp2Imaginary = pVector2->m_vectValueImaginaryBuffer.data();
2708 
2709  double fReal = 0., fImaginary = 0.;
2710 #pragma omp parallel for reduction(+:fReal, fImaginary)
2711  for (i = 0; i < nSize; i++)
2712  {
2713  /*fReal += pOp1Real[i] * pOp2Real[i] - pOp1Imaginary[i] * (-1 * pOp2Imaginary[i]);
2714  fImaginary += pOp1Real[i] * (-1 * pOp2Imaginary[i]) + pOp1Imaginary[i] * pOp2Real[i];*/
2715  fReal += pOp1Real[i] * pOp2Real[i] - (-1*pOp1Imaginary[i]) * pOp2Imaginary[i];
2716  fImaginary += pOp1Real[i] * pOp2Imaginary[i] + (-1*pOp1Imaginary[i]) * pOp2Real[i];
2717  }
2718 
2719  pResult->SetComplexNumber(fReal, fImaginary);
2721 
2722  return true;
2723 
2724 }
static void AllReduceComlex(CKNComplex *pNumber, CKNTimeMeasurement::MEASUREMENT_INDEX INDEX=CKNTimeMeasurement::COMM)
Do all reduce function with CKNComplex.
const unsigned long ERROR_WRONG_ORDER_OPERATION
Error code that means during operation between vector & vector, matrix & vector order don't match...
Definition: CKNGlobal.h:64
void SetComplexNumber(double fReal, double fImaginaray)
Set Complex number using real part and imaginary part.
Definition: KNComplex.cpp:59

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

unsigned int * CKNMatrixOperation::pColumn = NULL
static

For MPI Optimized operation using.

Definition at line 269 of file KNMatrixOperation.h.

Referenced by BuildLocalCSR(), MVMulEx_AsyncCommWithLocalBlocks(), and UpdateLocalCSR().

unsigned int * CKNMatrixOperation::pRow = NULL
static

For MPI Optimized operation using.

Definition at line 268 of file KNMatrixOperation.h.

Referenced by BuildLocalCSR(), MVMulEx_AsyncCommWithLocalBlocks(), and UpdateLocalCSR().

CKNComplex * CKNMatrixOperation::pValueBuffer = NULL
static

For MPI Optimized operation using.

Definition at line 266 of file KNMatrixOperation.h.


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