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

#include "KNLanczosTest.h"

Collaboration diagram for CKNLanczosTest:
Collaboration graph

Public Member Functions

 CKNLanczosTest ()
 
 ~CKNLanczosTest ()
 
void * LanczosThread (void *pParam)
 
void * LanczosThreadForMPI (void *pParam)
 

Static Public Member Functions

static void TestCSRBuilding ()
 
static void TestSimpleLanczos ()
 
static void TestLanczos (int nIteration, int nInterval, int nEigCount, bool bCalcuVector)
 
static void CompareWithMatLabSeOrth (int nIteration, int nInterval, int nEigCount, bool bSelect, bool bCalcuVector)
 
static void CompareWithMatLabSeOrth_ (int nIteration, int nInterval, int nEigCount, bool bSelect, bool bCalcuVector)
 
static void COmpareWIthMatLabSeOrthMPI (int nRowCount, int nIteration, int nInterval, int nEigCount, bool bSelect, bool bCalcuVector, int nFileIndex)
 
static void LargeSizeMatrixMPI (int nRowCount, int nIteration, int nInterval, int nEigCount, bool bSelect, bool bCalcuVector, bool bWaveFunction)
 
static void SaveResult (CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, unsigned int nMatrixSize, bool bCalcuEigenvalue, bool bWaveFunction)
 
static void SaveResultCVS ()
 
static void SolvingLargeSizeHamlitonian (int nIteration, int nInterval, int nEigCount, bool bSelect, bool bCalcuVector, bool bWaveFunction)
 
static void AuditResult (int nIndex, int nFindEigenValue, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fMin, double fMax)
 
static void AuditResult_Seorth (int nIndex, int nFindEigenValue, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fMin, double fMax)
 
static void AuditResult_EV (CKNMatrixOperation::CKNCSR *pCSR, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fTolerance)
 
static void AuditResult_WF (CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fTolerance, unsigned int nWaveFunctionSize)
 
static void ShowMsg (char *pszBuffer)
 
static void StopLanczos ()
 
static CKNMatrixOperation::CKNCSRTestCSRBuildingViaFileLoadOrigin (char *pszFileName, int nMatrixSize)
 
static CKNMatrixOperation::CKNCSRTestCSRBuildingViaFileLoad (char *pszFileName, int nMatrixSize)
 
static CKNMatrixOperation::CKNCSRTestCSRBuildingViaFileLoad_ (char *pszFileName, int nMatrixSize)
 
static CKNMatrixOperation::CKNCSRLargeCSRBuildingViaFileForMPI (char *pszFileName, int nMatrixSize)
 
static CKNMatrixOperation::CKNCSRTestCSRBuildingViaArray ()
 

Static Public Attributes

static CKNLanczosMethodm_pCurrentLanczosInstance = NULL
 

Detailed Description

Definition at line 6 of file KNLanczosTest.h.

Constructor & Destructor Documentation

CKNLanczosTest::CKNLanczosTest ( )

Definition at line 51 of file KNLanczosTest.cpp.

52 {
53 }
CKNLanczosTest::~CKNLanczosTest ( )

Definition at line 56 of file KNLanczosTest.cpp.

57 {
58 }

Member Function Documentation

void CKNLanczosTest::AuditResult ( int  nIndex,
int  nFindEigenValue,
CKNLanczosMethod::LPEIGENVALUE_RESULT  lpResult,
double  fMin,
double  fMax 
)
static

Definition at line 619 of file KNLanczosTest.cpp.

References FREE_MEM, CKNMatrixOperation::IsSame(), CKNLanczosMethod::EIGENVALUE_RESULT::nEigenValueCount, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenValues, and CKNMatrixDebug::ShowMsg().

620 {
621  char szBuffer[1024];
622  FILE *fpMatlabAnswer = NULL;
623  unsigned int nMatlabAnswerCount = 0;
624  int nReadIndex = 0;
625  double *pMatlabAnswer = (double*)malloc(sizeof(double)*nFindEigenValue);
626  unsigned int i, j;
627  double fMisAnswer[1024];
628  unsigned int nMisAnswer = 0;
629  double fWrongAnwser[1024];
630  unsigned int nWrongAnwser = 0;
631  double fCorrectAnwser[1024];
632  unsigned int nCorrectAnwser = 0;
633 
634  if (NULL == pMatlabAnswer)
635  return;
636 
637  if (NULL == lpResult)
638  return;
639 
640  sprintf(szBuffer, "data\\Matlab_result_%d_%d.dat", nFindEigenValue, nIndex);
641  if (NULL != (fpMatlabAnswer = fopen(szBuffer, "rb")))
642  {
643  double temp;
644  while (0 != fread(&temp, sizeof(double), 1, fpMatlabAnswer))
645  {
646  if (temp >= fMin && temp <= fMax)
647  pMatlabAnswer[nMatlabAnswerCount++] = temp;
648  }
649  fclose(fpMatlabAnswer);
650 
651  bool bExist = false;
652 #ifdef _WIN32
653  for (i = 0; i < (unsigned int)min((int)lpResult->nEigenValueCount, (int)nFindEigenValue); i++)
654 #else //_WIN32
655  for (i = 0; i < (unsigned int)std::min((int)lpResult->nEigenValueCount, (int)nFindEigenValue); i++)
656 #endif
657  {
658  bExist = false;
659  for (j = 0; j < nMatlabAnswerCount; j++)
660  {
661  if (CKNMatrixOperation::IsSame(lpResult->pEigenValues[i], pMatlabAnswer[j], 1.e-7))
662  {
663  fCorrectAnwser[nCorrectAnwser++] = pMatlabAnswer[j];
664  bExist = true;
665  break;
666  }
667  }
668 
669  if (!bExist)
670  fWrongAnwser[nWrongAnwser++] = lpResult->pEigenValues[i];
671  }
672 
673  for (i = 0; i < nMatlabAnswerCount; i++)
674  {
675  bExist = false;
676 #ifdef _WIN32
677  for (j = 0; j < (unsigned int)min((int)lpResult->nEigenValueCount, (int)nFindEigenValue); j++)
678 #else //_WIN32
679  for (j = 0; j < (unsigned int)std::min((int)lpResult->nEigenValueCount, (int)nFindEigenValue); j++)
680 #endif //_WIN32
681  {
682  if (CKNMatrixOperation::IsSame(lpResult->pEigenValues[j], pMatlabAnswer[i], 1.e-7))
683  {
684  bExist = true;
685  break;
686  }
687  }
688 
689  if (!bExist)
690  fMisAnswer[nMisAnswer++] = pMatlabAnswer[i];
691  }
692 
693 
694  sprintf(szBuffer, "\n%d result\n------------------------------\nFind eigenvalues: %d\nMiss eigenvalues: %d\nWrong eigenvalues: %d\n", nIndex, nCorrectAnwser, nMisAnswer, nWrongAnwser);
695  CKNMatrixDebug::ShowMsg(szBuffer);
696 
697  strcpy(szBuffer, "\nFinding eigenvalues:\n");
698  for (i = 0; i < nCorrectAnwser; i++)
699  sprintf(szBuffer, "%s%d: %f\n", szBuffer, i, fCorrectAnwser[i]);
700  CKNMatrixDebug::ShowMsg(szBuffer);
701 
702  if (nMisAnswer)
703  {
704  strcpy(szBuffer, "\nMissing eigenvalues:\n");
705  for (i = 0; i < nMisAnswer; i++)
706  sprintf(szBuffer, "%s%d: %f\n", szBuffer, i, fMisAnswer[i]);
707  CKNMatrixDebug::ShowMsg(szBuffer);
708  }
709 
710  if (nWrongAnwser)
711  {
712  strcpy(szBuffer, "\nWrong eigenvalues:\n");
713  for (i = 0; i < nWrongAnwser; i++)
714  sprintf(szBuffer, "%s%d: %f\n", szBuffer, i, fWrongAnwser[i]);
715 
716  sprintf(szBuffer, "%s\n", szBuffer);
717  CKNMatrixDebug::ShowMsg(szBuffer);
718  }
719  }
720  else
721  {
722  sprintf(szBuffer, "Can't find audi file %s\n", szBuffer);
723  CKNMatrixDebug::ShowMsg(szBuffer);
724  }
725 
726  FREE_MEM(pMatlabAnswer);
727 }
static void ShowMsg(char *pszBuffer)
Show message.
#define FREE_MEM(pointer)
Macro for memory allocation and assign null value.
Definition: CKNGlobal.h:20
static bool IsSame(double operand1, double operand2, double tol)
Compare two double variable.

Here is the call graph for this function:

void CKNLanczosTest::AuditResult_EV ( CKNMatrixOperation::CKNCSR pCSR,
CKNLanczosMethod::LPEIGENVALUE_RESULT  lpResult,
double  fTolerance 
)
static

Definition at line 472 of file KNLanczosTest.cpp.

References CKNMatrixOperation::CKNVector::Finalize(), CKNMatrixOperation::CKNCSR::GetColumnCount(), CKNMatrixOperation::CKNVector::GetNorm(), CKNMatrixOperation::CKNVector::MinusVector(), CKNLanczosMethod::EIGENVALUE_RESULT::nEigenValueCount, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenValues, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenVectorsForAMatrix, CKNMatrixOperation::CKNVector::ScalarMultiple(), CKNMatrixOperation::CKNVector::SetSize(), and CKNMatrixDebug::ShowMsg().

473 {
474  unsigned int i;
475  char szBuffer[1024];
476  bool bPass;
477 
478  if (NULL == lpResult || NULL == lpResult->pEigenVectorsForAMatrix)
479  return;
480 
481  CKNMatrixDebug::ShowMsg("\n------------------------------\nEV Result\n");
482 
483  for (i = 0; i < lpResult->nEigenValueCount; i++)
484  {
485  bPass = false;
486  CKNMatrixOperation::CKNVector VAX, VRamdaX;
487 
488  VAX.SetSize(pCSR->GetColumnCount());
489  VRamdaX.SetSize(pCSR->GetColumnCount());
490  CKNMatrixOperation::MVMul_(pCSR, &lpResult->pEigenVectorsForAMatrix[i], &VAX);
491  VRamdaX = lpResult->pEigenVectorsForAMatrix[i];
492  VRamdaX.ScalarMultiple(lpResult->pEigenValues[i]);
493 
494  VAX.MinusVector(&VRamdaX);
495  double fResult = VAX.GetNorm();
496  if (fabs(fResult) < fTolerance)
497  bPass = true;
498 
499  sprintf(szBuffer, "EV[%d] [AX - ramdaX: %20.20f] %s \n", i, fResult, bPass ? "OK" : "NG");
500  CKNMatrixDebug::ShowMsg(szBuffer);
501 
502  VAX.Finalize();
503  VRamdaX.Finalize();
504  }
505 }
void SetSize(unsigned int nSize)
Set Vector elements size.
void ScalarMultiple(CKNComplex Scalar)
Scalar multiple operation.
CKNMatrixOperation::CKNVector * pEigenVectorsForAMatrix
unsigned int GetColumnCount()
Getting row size of matrix.
void MinusVector(CKNVector *vector)
Do minus operation between vectors.
void Finalize()
Free allocated memory for vector elements.
static void ShowMsg(char *pszBuffer)
Show message.
double GetNorm(bool bMPI=false)
Getting norm of vector.
This class for describing vector for Lanczos method.

Here is the call graph for this function:

void CKNLanczosTest::AuditResult_Seorth ( int  nIndex,
int  nFindEigenValue,
CKNLanczosMethod::LPEIGENVALUE_RESULT  lpResult,
double  fMin,
double  fMax 
)
static

Definition at line 507 of file KNLanczosTest.cpp.

References CKNMatrixOperation::IsSame(), MATLAB_SEORTH_RESULT_FILE, CKNLanczosMethod::EIGENVALUE_RESULT::nEigenValueCount, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenValues, and CKNMatrixDebug::ShowMsg().

508 {
509  char szBuffer[1024];
510  FILE *fpMatlabAnswer = NULL;
511  unsigned int nMatlabAnswerCount = 0;
512  int nReadIndex = 0;
513  //double *pMatlabAnswer = (double*)malloc(sizeof(double)*nFindEigenValue);
514  double fMatlabAnswer[1024];
515  unsigned int i, j;
516  double fMisAnswer[1024];
517  unsigned int nMisAnswer = 0;
518  double fWrongAnwser[1024];
519  unsigned int nWrongAnwser = 0;
520  double fCorrectAnwser[1024];
521  unsigned int nCorrectAnwser = 0;
522 
523  if (NULL == lpResult)
524  return;
525 
526 
527  if (NULL != (fpMatlabAnswer = fopen(MATLAB_SEORTH_RESULT_FILE, "rb")))
528  {
529  double temp;
530  fseek(fpMatlabAnswer, (10 * sizeof(double))*(nIndex - 1), SEEK_SET);
531  for (i = 0; i < 10; i++)
532  {
533  fread(&temp, sizeof(double), 1, fpMatlabAnswer);
534  if (temp >= fMin && temp <= fMax)
535  {
536  fMatlabAnswer[nMatlabAnswerCount++] = temp;
537  }
538  }
539  fclose(fpMatlabAnswer);
540 
541 
542  bool bExist = false;
543 #ifdef _WIN32
544  for (i = 0; i < (unsigned int)min((int)lpResult->nEigenValueCount, (int)nFindEigenValue); i++)
545 #else
546  for (i = 0; i < (unsigned int)std::min((int)lpResult->nEigenValueCount, (int)nFindEigenValue); i++)
547 #endif //_WIN32
548  {
549  bExist = false;
550  for (j = 0; j < nMatlabAnswerCount; j++)
551  {
552  if (CKNMatrixOperation::IsSame(lpResult->pEigenValues[i], fMatlabAnswer[j], 1.e-7))
553  {
554  fCorrectAnwser[nCorrectAnwser++] = fMatlabAnswer[j];
555  bExist = true;
556  break;
557  }
558  }
559 
560  if (!bExist)
561  fWrongAnwser[nWrongAnwser++] = lpResult->pEigenValues[i];
562  }
563 
564  for (i = 0; i < nMatlabAnswerCount; i++)
565  {
566  bExist = false;
567 #ifdef _WIN32
568  for (j = 0; j < (unsigned int)min((int)lpResult->nEigenValueCount, (int)nFindEigenValue); j++)
569 #else //_WIN32
570  for (j = 0; j < (unsigned int)std::min((int)lpResult->nEigenValueCount, (int)nFindEigenValue); j++)
571 #endif //_WIN32
572  {
573  if (CKNMatrixOperation::IsSame(lpResult->pEigenValues[j], fMatlabAnswer[i], 1.e-7))
574  {
575  bExist = true;
576  break;
577  }
578  }
579 
580  if (!bExist)
581  fMisAnswer[nMisAnswer++] = fMatlabAnswer[i];
582  }
583 
584 
585  sprintf(szBuffer, "\n%d result(s)\n------------------------------\nFind eigenvalues: %d\nMiss eigenvalues: %d\nWrong eigenvalues: %d\n", nIndex, nCorrectAnwser, nMisAnswer, nWrongAnwser);
586  CKNMatrixDebug::ShowMsg(szBuffer);
587 
588  strcpy(szBuffer, "\nFinding eigenvalues:\n");
589  for (i = 0; i < nCorrectAnwser; i++)
590  sprintf(szBuffer, "%s%d: %f\n", szBuffer, i, fCorrectAnwser[i]);
591  CKNMatrixDebug::ShowMsg(szBuffer);
592 
593  if (nMisAnswer)
594  {
595  strcpy(szBuffer, "\nMissing eigenvalues:\n");
596  for (i = 0; i < nMisAnswer; i++)
597  sprintf(szBuffer, "%s%d: %f\n", szBuffer, i, fMisAnswer[i]);
598  CKNMatrixDebug::ShowMsg(szBuffer);
599  }
600 
601  if (nWrongAnwser)
602  {
603  strcpy(szBuffer, "\nWrong eigenvalues:\n");
604  for (i = 0; i < nWrongAnwser; i++)
605  sprintf(szBuffer, "%s%d: %f\n", szBuffer, i, fWrongAnwser[i]);
606 
607  sprintf(szBuffer, "%s\n", szBuffer);
608  CKNMatrixDebug::ShowMsg(szBuffer);
609  }
610  }
611  else
612  {
613  sprintf(szBuffer, "Can't find audi file %s\n", szBuffer);
614  CKNMatrixDebug::ShowMsg(szBuffer);
615  }
616 
617 }
#define MATLAB_SEORTH_RESULT_FILE
static void ShowMsg(char *pszBuffer)
Show message.
static bool IsSame(double operand1, double operand2, double tol)
Compare two double variable.

Here is the call graph for this function:

void CKNLanczosTest::AuditResult_WF ( CKNLanczosMethod::LPEIGENVALUE_RESULT  lpResult,
double  fTolerance,
unsigned int  nWaveFunctionSize 
)
static

Definition at line 1018 of file KNLanczosTest.cpp.

References CKNMatrixOperation::CKNVector::GetAt(), CKNComplex::GetNorm(), CKNLanczosMethod::EIGENVALUE_RESULT::nEigenValueCount, CKNLanczosMethod::EIGENVALUE_RESULT::pWaveFunctions, CKNComplex::SetComplexNumber(), and CKNMatrixDebug::ShowMsg().

1019 {
1020  unsigned int i, j;
1021  char szBuffer[1024];
1022  bool bPass;
1023  CKNComplex tempResult;
1024 
1025  if (NULL == lpResult || NULL == lpResult->pWaveFunctions)
1026  return;
1027 
1028  CKNMatrixDebug::ShowMsg("\n------------------------------\nWavefunction Result\n");
1029 
1030  for (i = 0; i < lpResult->nEigenValueCount; i++)
1031  {
1032  bPass = false;
1033 
1034  tempResult.SetComplexNumber(0,0);
1035  for( j = 0 ; j < nWaveFunctionSize; j ++ )
1036  {
1037  tempResult = tempResult + lpResult->pWaveFunctions[i].GetAt(j);
1038  }
1039 
1040  if (fabs(1-tempResult.GetNorm()) < fTolerance)
1041  bPass = true;
1042 
1043  sprintf(szBuffer, "WaveFunction[%d] sum: [ %20.20f ] %s\n", i, tempResult.GetNorm(), bPass ? "OK" : "NG");
1044  CKNMatrixDebug::ShowMsg(szBuffer);
1045  }
1046 }
CKNMatrixOperation::CKNVector * pWaveFunctions
double GetNorm()
Get norm of complex number.
Definition: KNComplex.h:34
CKNComplex GetAt(unsigned int nIndex)
Get element value from specific index.
static void ShowMsg(char *pszBuffer)
Show message.
This class for complex operation and saving value.
Definition: KNComplex.h:18
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:

void CKNLanczosTest::CompareWithMatLabSeOrth ( int  nIteration,
int  nInterval,
int  nEigCount,
bool  bSelect,
bool  bCalcuVector 
)
static

H00, H01 ÆÄÀÏ Loading

Definition at line 757 of file KNLanczosTest.cpp.

References CKNLanczosMethod::DoLanczosMethod(), ERROR_MALLOC, ERROR_OUT_OF_RANGE, CKNMatrixOperation::FreeCSR(), CKNLanczosMethod::EIGENVALUE_RESULT::pEigenVectorsForAMatrix, CKNLanczosMethod::ReleaseResult(), and CKNMatrixDebug::ShowMsg().

758 {
759  CKNMatrixOperation::CKNCSR *pA_Matrix = NULL;
760  int nEigenValueCount = 0;
761  int nFindEigenvalueCount = 10;
763 
764  try
765  {
766  char szBuffer[1024];
767  CKNLanczosMethod lanczos;
768 
769  for (int i = 1; i <= 41; i++)
770  {
771  sprintf(szBuffer, "\n\n-Start %dth Lanczos eigenvalues solver", i);
772  CKNMatrixDebug::ShowMsg(szBuffer);
773  sprintf(szBuffer, "./data/Matlab_%d.dat", i);
774  pA_Matrix = TestCSRBuildingViaFileLoad(szBuffer, 2000);
775 
776  if (NULL == pA_Matrix)
777  {
778  CKNMatrixDebug::ShowMsg("Error while Loading Matlab file");
779  continue;
780  }
781 
782  lpResult = lanczos.DoLanczosMethod(pA_Matrix, nIteration, nInterval, nEigCount, 1.2, 2.3, 1e-8, bSelect, bCalcuVector, false);
783  AuditResult_Seorth(i, nFindEigenvalueCount, lpResult, 1.2, 2.3);
784  if( lpResult && lpResult->pEigenVectorsForAMatrix && bCalcuVector)
785  AuditResult_EV(pA_Matrix, lpResult, 1e-8);
786 
787  CKNLanczosMethod::ReleaseResult(lpResult, true);
788  CKNMatrixOperation::FreeCSR(pA_Matrix);
789  CKNMatrixDebug::ShowMsg("-Finish Lanczos eigenvalue solver");
790  }
791  }
792  catch (unsigned long dwError)
793  {
794  switch (dwError)
795  {
796  case ERROR_MALLOC:
797  CKNMatrixDebug::ShowMsg("Can't alloc memory!");
798  break;
799  case ERROR_OUT_OF_RANGE:
800  CKNMatrixDebug::ShowMsg("Row or Column index going out of range!");
801  break;
802  }
803  }
804  catch (...)
805  {
806  }
807 }
static void AuditResult_EV(CKNMatrixOperation::CKNCSR *pCSR, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fTolerance)
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.
CKNMatrixOperation::CKNVector * pEigenVectorsForAMatrix
Data and operation representation of CSR(Compressed Sparse Row)
This class for doing Lanczos method.
static void AuditResult_Seorth(int nIndex, int nFindEigenValue, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fMin, double fMax)
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaFileLoad(char *pszFileName, int nMatrixSize)
const unsigned long ERROR_OUT_OF_RANGE
Error code that means during access vector or matrix input index out of range.
Definition: CKNGlobal.h:63
Structure for engienvalue computing.
LPEIGENVALUE_RESULT DoLanczosMethod(CKNMatrixOperation::CKNCSR *pAMatrix, unsigned int nIterationCount, unsigned int nEigenValueCheckInterval, unsigned int nEigenValueCount, double fEigenvalueMin, double fEignevalueMax, double fConvergenceTolerance, bool bReorthogonalization, bool bCalcuEigVector, bool bWaveFunction, double load_in_MIC, CKNMatrixOperation::CKNCSR *pmylocalblock=NULL, CKNMatrixOperation::CKNCSR *leftlocalblock=NULL, CKNMatrixOperation::CKNCSR *rightlocalblock=NULL)
Doing lanczos method.
static void ShowMsg(char *pszBuffer)
Show message.
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: CKNGlobal.h:62
static void ReleaseResult(LPEIGENVALUE_RESULT lpResult, bool bReleaseStruct)
Release memory for lanczos method result.

Here is the call graph for this function:

void CKNLanczosTest::CompareWithMatLabSeOrth_ ( int  nIteration,
int  nInterval,
int  nEigCount,
bool  bSelect,
bool  bCalcuVector 
)
static

Definition at line 1238 of file KNLanczosTest.cpp.

References _tag::bCalcuVector, _tag::bSelect, LanczosThread(), _tag::nEigCount, _tag::nInterval, and _tag::nIteration.

1239 {
1240  LPLANCZOS_PARAM lpParam = (LPLANCZOS_PARAM)malloc(sizeof(LANCZOS_PARAM));
1241 
1242  lpParam->bSelect = bSelect;
1243  lpParam->nEigCount = nEigCount;
1244  lpParam->nInterval = nInterval;
1245  lpParam->nIteration = nIteration;
1246  lpParam->bCalcuVector = bCalcuVector;
1247 
1248 #ifdef _WIN32
1249 #if _MFC_VER == 0x0C00
1250  m_pLanczosThread = AfxBeginThread(CKNLanczosTest::LanczosThread, lpParam);
1251 #endif /_MFC_VER == 0x0C00
1252 #else //_WIN32
1253 #endif //_WIN32
1254 }
bool bCalcuVector
void * LanczosThread(void *pParam)
int nIteration
int nInterval
struct _tag * LPLANCZOS_PARAM
int nEigCount
bool bSelect

Here is the call graph for this function:

void CKNLanczosTest::COmpareWIthMatLabSeOrthMPI ( int  nRowCount,
int  nIteration,
int  nInterval,
int  nEigCount,
bool  bSelect,
bool  bCalcuVector,
int  nFileIndex 
)
static

Definition at line 809 of file KNLanczosTest.cpp.

References CKNLanczosMethod::DoLanczosMethod(), ERROR_MALLOC, ERROR_OUT_OF_RANGE, CKNMPIManager::FinalizeManager(), CKNMatrixOperation::FreeCSR(), CKNMPIManager::InitCommunicationBufferMetric(), CKNTimeMeasurement::InitTimer(), CKNMPIManager::IsRootRank(), CKNMPIManager::LoadBlancingForLanczos(), CKNLanczosMethod::EIGENVALUE_RESULT::pEigenVectorsForAMatrix, CKNLanczosMethod::ReleaseResult(), CKNMPIManager::SetMPIEnviroment(), and CKNMatrixDebug::ShowMsg().

810 {
811  char szFileName[1024];
812  CKNMatrixOperation::CKNCSR *pA_Matrix = NULL;
813  CKNLanczosMethod lanczos;
814  int nFindEigenvalueCount = 10;
816 #ifdef _MFC_VER == 0x0C00
817  sprintf(szFileName, "D:\\git\\data\\Matlab_%d.dat", nFileIndex);
818 #else
819  sprintf(szFileName, "./data/Matlab_%d.dat", nFileIndex);
820 #endif
821 
822  try
823  {
824  MPI_Init(NULL, NULL);
825 
826  int world_size;
827  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
828 
829  int rank;
830  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
831 
832  CKNMPIManager::SetMPIEnviroment(rank, world_size);
835 #ifdef DOING_MEASUREMENT
837 #endif
838 
839  pA_Matrix = TestCSRBuildingViaFileLoad_(szFileName, 2000);
840  lpResult = lanczos.DoLanczosMethod(pA_Matrix, nIteration, nInterval, nEigCount, 1.2, 2.3, 1e-8, bSelect, bCalcuVector, bCalcuVector);
841 
843  AuditResult_Seorth(nFileIndex, nFindEigenvalueCount, lpResult, 1.2, 2.3);
844 
845  if (lpResult && lpResult->pEigenVectorsForAMatrix && CKNMPIManager::IsRootRank() && bCalcuVector)
846  {
847  CKNMatrixOperation::FreeCSR(pA_Matrix);
849  pA_Matrix = TestCSRBuildingViaFileLoadOrigin(szFileName, 2000);
850  AuditResult_EV(pA_Matrix, lpResult, 1e-8);
851 
852  AuditResult_WF(lpResult, 1e-8, 200);
853  }
854 
855 
856 
858  CKNMatrixOperation::FreeCSR(pA_Matrix);
859  CKNLanczosMethod::ReleaseResult(lpResult, true);
860 
861  MPI_Finalize();
862  }
863  catch (unsigned long dwError)
864  {
865  switch (dwError)
866  {
867  case ERROR_MALLOC:
868  CKNMatrixDebug::ShowMsg("Can't alloc memory!");
869  break;
870  case ERROR_OUT_OF_RANGE:
871  CKNMatrixDebug::ShowMsg("Row or Column index going out of range!");
872  break;
873  }
874  }
875  catch (...)
876  {
877  }
878 }
static void AuditResult_EV(CKNMatrixOperation::CKNCSR *pCSR, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fTolerance)
static void InitCommunicationBufferMetric()
Initializing MPI Communication buffer for MVMul.
static void FinalizeManager()
Get Root rank.
static void SetMPIEnviroment(int nRank, int nTotalNode)
Set MPI Enviroment.
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaFileLoadOrigin(char *pszFileName, int nMatrixSize)
CKNMatrixOperation::CKNVector * pEigenVectorsForAMatrix
Data and operation representation of CSR(Compressed Sparse Row)
This class for doing Lanczos method.
static void AuditResult_Seorth(int nIndex, int nFindEigenValue, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fMin, double fMax)
const unsigned long ERROR_OUT_OF_RANGE
Error code that means during access vector or matrix input index out of range.
Definition: CKNGlobal.h:63
Structure for engienvalue computing.
LPEIGENVALUE_RESULT DoLanczosMethod(CKNMatrixOperation::CKNCSR *pAMatrix, unsigned int nIterationCount, unsigned int nEigenValueCheckInterval, unsigned int nEigenValueCount, double fEigenvalueMin, double fEignevalueMax, double fConvergenceTolerance, bool bReorthogonalization, bool bCalcuEigVector, bool bWaveFunction, double load_in_MIC, CKNMatrixOperation::CKNCSR *pmylocalblock=NULL, CKNMatrixOperation::CKNCSR *leftlocalblock=NULL, CKNMatrixOperation::CKNCSR *rightlocalblock=NULL)
Doing lanczos method.
static void ShowMsg(char *pszBuffer)
Show message.
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaFileLoad_(char *pszFileName, int nMatrixSize)
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: CKNGlobal.h:62
static void AuditResult_WF(CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fTolerance, unsigned int nWaveFunctionSize)
static void ReleaseResult(LPEIGENVALUE_RESULT lpResult, bool bReleaseStruct)
Release memory for lanczos method result.
static void LoadBlancingForLanczos(int nRowCount)
Load blancing for MPI, this function only for lanczos solving without geometric constrcution.
static bool IsRootRank()
Get Total node count.
static void InitTimer()
Init time related variable.

Here is the call graph for this function:

void * CKNLanczosTest::LanczosThread ( void *  pParam)

H00, H01 ÆÄÀÏ Loading

Definition at line 1263 of file KNLanczosTest.cpp.

References _tag::bCalcuVector, _tag::bSelect, CKNLanczosMethod::DoLanczosMethod(), ERROR_MALLOC, ERROR_OUT_OF_RANGE, FREE_MEM, CKNMatrixOperation::FreeCSR(), CKNLanczosMethod::IsAbort(), m_pCurrentLanczosInstance, _tag::nEigCount, _tag::nInterval, _tag::nIteration, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenVectorsForAMatrix, CKNLanczosMethod::ReleaseResult(), and CKNMatrixDebug::ShowMsg().

Referenced by CompareWithMatLabSeOrth_().

1265 {
1266  CKNMatrixOperation::CKNCSR *pA_Matrix = NULL;
1267  int nEigenValueCount = 0;
1268  int nFindEigenvalueCount = 10;
1269  CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult = NULL;
1270  LPLANCZOS_PARAM lpParam = (LPLANCZOS_PARAM)pParam;
1271 
1272  try
1273  {
1274  char szBuffer[1024];
1275  CKNLanczosMethod lanczos;
1276 
1278 
1279  for (int i = 1; i <= 1; i++)
1280  {
1281  sprintf(szBuffer, "\n\n-Start %dth Lanczos eigenvalues solver", i);
1282  CKNMatrixDebug::ShowMsg(szBuffer);
1283  sprintf(szBuffer, "./data/Matlab_%d.dat", i);
1284  //sprintf(szBuffer, "%s", LARGE_SIZE_MATRIX_FILE);
1285  pA_Matrix = TestCSRBuildingViaFileLoad(szBuffer, 2000);
1286 
1287  if (NULL == pA_Matrix)
1288  {
1289  CKNMatrixDebug::ShowMsg("Error while Loading Matlab file");
1290  continue;
1291  }
1292 
1293  lpResult = lanczos.DoLanczosMethod(pA_Matrix, lpParam->nIteration, lpParam->nInterval, lpParam->nEigCount, 1.2, 2.3, 1e-8, lpParam->bSelect, lpParam->bCalcuVector, false);
1294 
1295  AuditResult_Seorth(i, nFindEigenvalueCount, lpResult, 1.2, 2.3);
1296  if (lpResult && lpResult->pEigenVectorsForAMatrix && lpParam->bCalcuVector)
1297  AuditResult_EV(pA_Matrix, lpResult, 1e-8);
1298 
1299 
1300  CKNLanczosMethod::ReleaseResult(lpResult, true);
1301  CKNMatrixOperation::FreeCSR(pA_Matrix);
1302 
1303  if (lanczos.IsAbort())
1304  {
1305  CKNMatrixDebug::ShowMsg("\n-Aborting Lanczos eigenvalue solver");
1306  break;
1307  }
1308 
1309  CKNMatrixDebug::ShowMsg("-Finish Lanczos eigenvalue solver");
1310  }
1311  }
1312  catch (unsigned long dwError)
1313  {
1314  switch (dwError)
1315  {
1316  case ERROR_MALLOC:
1317  CKNMatrixDebug::ShowMsg("Can't alloc memory!");
1318  break;
1319  case ERROR_OUT_OF_RANGE:
1320  CKNMatrixDebug::ShowMsg("Row or Column index going out of range!");
1321  break;
1322  }
1323  }
1324  catch (...)
1325  {
1326  }
1327 
1329  FREE_MEM(lpParam);
1330 
1331 #ifdef _WIN32
1332 #if _MFC_VER == 0x0C00
1333  m_pLanczosThread = NULL;
1334  return 0;
1335 #else
1336  return NULL;
1337 #endif //_MFC_VER == 0x0C00
1338 #else //_WIN32
1339  return NULL;
1340 #endif //_WIN32
1341 }
static void AuditResult_EV(CKNMatrixOperation::CKNCSR *pCSR, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fTolerance)
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.
CKNMatrixOperation::CKNVector * pEigenVectorsForAMatrix
Data and operation representation of CSR(Compressed Sparse Row)
This class for doing Lanczos method.
bool bCalcuVector
int nIteration
static void AuditResult_Seorth(int nIndex, int nFindEigenValue, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fMin, double fMax)
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaFileLoad(char *pszFileName, int nMatrixSize)
int nInterval
const unsigned long ERROR_OUT_OF_RANGE
Error code that means during access vector or matrix input index out of range.
Definition: CKNGlobal.h:63
struct _tag * LPLANCZOS_PARAM
static CKNLanczosMethod * m_pCurrentLanczosInstance
Definition: KNLanczosTest.h:37
Structure for engienvalue computing.
int nEigCount
LPEIGENVALUE_RESULT DoLanczosMethod(CKNMatrixOperation::CKNCSR *pAMatrix, unsigned int nIterationCount, unsigned int nEigenValueCheckInterval, unsigned int nEigenValueCount, double fEigenvalueMin, double fEignevalueMax, double fConvergenceTolerance, bool bReorthogonalization, bool bCalcuEigVector, bool bWaveFunction, double load_in_MIC, CKNMatrixOperation::CKNCSR *pmylocalblock=NULL, CKNMatrixOperation::CKNCSR *leftlocalblock=NULL, CKNMatrixOperation::CKNCSR *rightlocalblock=NULL)
Doing lanczos method.
static void ShowMsg(char *pszBuffer)
Show message.
static bool IsAbort()
#define FREE_MEM(pointer)
Macro for memory allocation and assign null value.
Definition: CKNGlobal.h:20
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: CKNGlobal.h:62
static void ReleaseResult(LPEIGENVALUE_RESULT lpResult, bool bReleaseStruct)
Release memory for lanczos method result.
bool bSelect

Here is the call graph for this function:

Here is the caller graph for this function:

void * CKNLanczosTest::LanczosThreadForMPI ( void *  pParam)

H00, H01 ÆÄÀÏ Loading

Definition at line 1177 of file KNLanczosTest.cpp.

References _tag::bCalcuVector, _tag::bSelect, CKNLanczosMethod::DoLanczosMethod(), ERROR_MALLOC, ERROR_OUT_OF_RANGE, CKNLanczosMethod::IsAbort(), _tag::nEigCount, _tag::nInterval, _tag::nIteration, _tag::pA_Matrix, CKNLanczosMethod::ReleaseResult(), and CKNMatrixDebug::ShowMsg().

1179 {
1180  CKNMatrixOperation::CKNCSR *pA_Matrix = NULL;
1181  int nEigenValueCount = 0;
1182  int nFindEigenvalueCount = 10;
1183  CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult = NULL;
1184  LPLANCZOS_PARAM lpParam = (LPLANCZOS_PARAM)pParam;
1185 
1186  try
1187  {
1188  CKNLanczosMethod lanczos;
1189  pA_Matrix = lpParam->pA_Matrix;
1190 
1191  if (NULL == pA_Matrix)
1192  {
1193  CKNMatrixDebug::ShowMsg("Error while Loading Matlab file");
1194  return 0;
1195  }
1196 
1197  lpResult = lanczos.DoLanczosMethod(pA_Matrix, lpParam->nIteration, lpParam->nInterval, lpParam->nEigCount, 1.2, 2.3, 1e-8, lpParam->bSelect, lpParam->bCalcuVector, false);
1198  /*if (lpResult && lpResult->pEigenVectorsForAMatrix)
1199  CKNMatrixDebug::ShowDoubleVector(lpResult->pEigenVectorsForAMatrix[0], "EV", 10);*/
1200  AuditResult_Seorth(1, nFindEigenvalueCount, lpResult, 1.2, 2.3);
1201 
1202  CKNLanczosMethod::ReleaseResult(lpResult, true);
1203 
1204  if (lanczos.IsAbort())
1205  CKNMatrixDebug::ShowMsg("\n-Aborting Lanczos eigenvalue solver");
1206 
1207  }
1208  catch (unsigned long dwError)
1209  {
1210  switch (dwError)
1211  {
1212  case ERROR_MALLOC:
1213  CKNMatrixDebug::ShowMsg("Can't alloc memory!");
1214  break;
1215  case ERROR_OUT_OF_RANGE:
1216  CKNMatrixDebug::ShowMsg("Row or Column index going out of range!");
1217  break;
1218  }
1219  }
1220  catch (...)
1221  {
1222  }
1223 
1224 
1225 
1226 #ifdef _WIN32
1227 #if _MFC_VER == 0x0C00
1228  m_pLanczosThread = NULL;
1229  return 0;
1230 #else
1231  return NULL;
1232 #endif //_MFC_VER == 0x0C00
1233 #else //_WIN32
1234  return NULL;
1235 #endif //_WIN32
1236 }
Data and operation representation of CSR(Compressed Sparse Row)
This class for doing Lanczos method.
bool bCalcuVector
int nIteration
static void AuditResult_Seorth(int nIndex, int nFindEigenValue, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fMin, double fMax)
int nInterval
const unsigned long ERROR_OUT_OF_RANGE
Error code that means during access vector or matrix input index out of range.
Definition: CKNGlobal.h:63
struct _tag * LPLANCZOS_PARAM
Structure for engienvalue computing.
int nEigCount
LPEIGENVALUE_RESULT DoLanczosMethod(CKNMatrixOperation::CKNCSR *pAMatrix, unsigned int nIterationCount, unsigned int nEigenValueCheckInterval, unsigned int nEigenValueCount, double fEigenvalueMin, double fEignevalueMax, double fConvergenceTolerance, bool bReorthogonalization, bool bCalcuEigVector, bool bWaveFunction, double load_in_MIC, CKNMatrixOperation::CKNCSR *pmylocalblock=NULL, CKNMatrixOperation::CKNCSR *leftlocalblock=NULL, CKNMatrixOperation::CKNCSR *rightlocalblock=NULL)
Doing lanczos method.
static void ShowMsg(char *pszBuffer)
Show message.
static bool IsAbort()
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: CKNGlobal.h:62
CKNMatrixOperation::CKNCSR * pA_Matrix
static void ReleaseResult(LPEIGENVALUE_RESULT lpResult, bool bReleaseStruct)
Release memory for lanczos method result.
bool bSelect

Here is the call graph for this function:

CKNMatrixOperation::CKNCSR * CKNLanczosTest::LargeCSRBuildingViaFileForMPI ( char *  pszFileName,
int  nMatrixSize 
)
static

< pCSR element size is 15445488

Definition at line 307 of file KNLanczosTest.cpp.

References CKNMatrixOperation::BuildCSRFromFileTemp(), LARGE_MATRIX_ORDER, and LARGE_MATRIX_READ_COUNT.

308 {
309  FILE *fDataFile = NULL;
310  CKNMatrixOperation::CKNCSR *pCSR = NULL;
311 
312  fDataFile = fopen(pszFileName, "rb");
313  if (NULL != fDataFile)
314  {
317 
318  fclose(fDataFile);
319  }
320 
321  return pCSR;
322 }
static CKNMatrixOperation::CKNCSR * BuildCSRFromFileTemp(FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
Building CSR from file using double, double, double, double order.
Data and operation representation of CSR(Compressed Sparse Row)
#define LARGE_MATRIX_ORDER
#define LARGE_MATRIX_READ_COUNT

Here is the call graph for this function:

void CKNLanczosTest::LargeSizeMatrixMPI ( int  nRowCount,
int  nIteration,
int  nInterval,
int  nEigCount,
bool  bSelect,
bool  bCalcuVector,
bool  bWaveFunction 
)
static

H00, H01 ÆÄÀÏ Loading

Definition at line 1049 of file KNLanczosTest.cpp.

References CKNTimeMeasurement::COMM, CKNLanczosMethod::DoLanczosMethod(), ERROR_MALLOC, ERROR_OUT_OF_RANGE, CKNTimeMeasurement::EVALUE, CKNTimeMeasurement::FILEIO, CKNMPIManager::FinalizeManager(), CKNTimeMeasurement::FREE_MEM, CKNMatrixOperation::FreeCSR(), CKNMPIManager::GetCurrentLoadBalanceCount(), CKNMPIManager::GetCurrentRank(), CKNMPIManager::GetLoadBalanceCount(), CKNTimeMeasurement::GetTakeTime(), CKNTimeMeasurement::GetTotalTakeTime(), CKNMPIManager::InitCommunicationBufferMetric(), CKNTimeMeasurement::InitTimer(), CKNMPIManager::IsRootRank(), LARGE_SIZE_MATRIX_FILE, CKNMPIManager::LoadBlancingForLanczos(), CKNTimeMeasurement::MALLOC, CKNLanczosMethod::EIGENVALUE_RESULT::nEigenValueCount, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenValues, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenVectorsForAMatrix, CKNLanczosMethod::EIGENVALUE_RESULT::pWaveFunctions, CKNLanczosMethod::ReleaseResult(), CKNMPIManager::SetMPIEnviroment(), CKNMatrixDebug::ShowMsg(), CKNMatrixOperation::CKNCSR::SplitCSR(), CKNTimeMeasurement::TotalMeasurementEnd(), and CKNTimeMeasurement::TotalMeasurementStart().

1050 {
1051  char szMsg[1024];
1052  CKNMatrixOperation::CKNCSR *pA_Matrix = NULL, *pCSRTotal = NULL;
1053  CKNLanczosMethod lanczos;
1054  int nFindEigenvalueCount = 10;
1055  CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult = NULL;
1056  unsigned int nRowStart = 0, nRowEnd, i;
1057 
1058  try
1059  {
1060  MPI_Init(NULL, NULL);
1061 
1062  int world_size;
1063  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
1064 
1065  int rank;
1066  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
1067 
1068  CKNMPIManager::SetMPIEnviroment(rank, world_size);
1071 
1073  CKNMatrixDebug::ShowMsg("\n-Start Lanczos eigenvalue solver for Large size Matrix\n");
1074  pCSRTotal = LargeCSRBuildingViaFileForMPI(LARGE_SIZE_MATRIX_FILE, nRowCount);
1075 
1076 
1077  for( i = 0 ; i < (unsigned int)CKNMPIManager::GetCurrentRank() ; i ++)
1078  nRowStart += CKNMPIManager::GetLoadBalanceCount(i);
1079 
1080  nRowEnd = nRowStart + CKNMPIManager::GetCurrentLoadBalanceCount();
1081 
1082  pA_Matrix = pCSRTotal->SplitCSR(nRowStart, nRowEnd);
1083  CKNMatrixOperation::FreeCSR(pCSRTotal);
1084 
1086  CKNMatrixDebug::ShowMsg("-Data file has been read\n");
1087 
1088  if (NULL == pA_Matrix)
1089  {
1090  CKNMatrixDebug::ShowMsg("Error while Loading Matlab file\n");
1091  return;
1092  }
1093 
1097  CKNMatrixDebug::ShowMsg("-Lanczos method start\n");
1098 
1099  lpResult = lanczos.DoLanczosMethod(pA_Matrix, nIteration, nInterval, nEigCount, -0.1, 1.63, 1e-8, bSelect, bCalcuVector, bWaveFunction);
1100 
1102  {
1103  SaveResult(lpResult, nRowCount, bCalcuVector, bWaveFunction);
1104  }
1105 
1107 
1109  {
1110  CKNMatrixDebug::ShowMsg("\n----------------------------------------\n");
1111  sprintf(szMsg, "%d nodes used\nTotal time\t[ %f\tsec ]\nCompting\t[ %lf\tsec ]\nEvalue takes\t[ %lf\tsec ]\nMPI takes\t[ %lf\tsec ]\nMem Op takes\t[ %lf\tsec ]\nResult written\t[ %lf\tsec ]\n",
1112  world_size,
1119 
1120  CKNMatrixDebug::ShowMsg(szMsg);
1121 
1122  CKNMatrixDebug::ShowMsg("\n----------------------------------------\n");
1123  for( i = 0 ;i < lpResult->nEigenValueCount ; i ++ )
1124  {
1125  sprintf(szMsg, "[ev %d] %18.16f\n", i, lpResult->pEigenValues[i]);
1126  CKNMatrixDebug::ShowMsg(szMsg);
1127  }
1128  SaveResultCVS();
1129  }
1130 
1131  if (lpResult && lpResult->pWaveFunctions && CKNMPIManager::IsRootRank() && bWaveFunction)
1132  {
1133  AuditResult_WF(lpResult, 1e-8, nRowCount/10);
1134  }
1135 
1136  if (lpResult && lpResult->pEigenVectorsForAMatrix && CKNMPIManager::IsRootRank() && bCalcuVector)
1137  {
1138  CKNMatrixOperation::FreeCSR(pA_Matrix);
1141  AuditResult_EV(pA_Matrix, lpResult, 1e-8);
1142  }
1143 
1145  CKNMatrixDebug::ShowMsg("\n-Finished Lanczos eigenvalue solver for Large size Matrix\n\n");
1146 
1148  CKNMatrixOperation::FreeCSR(pA_Matrix);
1149  CKNLanczosMethod::ReleaseResult(lpResult, true);
1150 
1151  MPI_Finalize();
1152  }
1153  catch (unsigned long dwError)
1154  {
1155  switch (dwError)
1156  {
1157  case ERROR_MALLOC:
1158  CKNMatrixDebug::ShowMsg("Can't alloc memory!");
1159  break;
1160  case ERROR_OUT_OF_RANGE:
1161  CKNMatrixDebug::ShowMsg("Row or Column index going out of range!");
1162  break;
1163  }
1164  }
1165  catch (...)
1166  {
1167  }
1168 }
static void AuditResult_EV(CKNMatrixOperation::CKNCSR *pCSR, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fTolerance)
static void InitCommunicationBufferMetric()
Initializing MPI Communication buffer for MVMul.
CKNMatrixOperation::CKNVector * pWaveFunctions
static CKNMatrixOperation::CKNCSR * LargeCSRBuildingViaFileForMPI(char *pszFileName, int nMatrixSize)
static void FinalizeManager()
Get Root rank.
CKNCSR * SplitCSR(int nStart, int nEnd)
Split CSR to MPI slave.
static void SetMPIEnviroment(int nRank, int nTotalNode)
Set MPI Enviroment.
static void SaveResult(CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, unsigned int nMatrixSize, bool bCalcuEigenvalue, bool bWaveFunction)
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.
CKNMatrixOperation::CKNVector * pEigenVectorsForAMatrix
Data and operation representation of CSR(Compressed Sparse Row)
static int GetCurrentLoadBalanceCount()
Get Current node's rank load balancing number.
This class for doing Lanczos method.
static double GetTakeTime(MEASUREMENT_INDEX index)
Get taken time for part.
static int GetLoadBalanceCount(int nRank)
const unsigned long ERROR_OUT_OF_RANGE
Error code that means during access vector or matrix input index out of range.
Definition: CKNGlobal.h:63
Structure for engienvalue computing.
LPEIGENVALUE_RESULT DoLanczosMethod(CKNMatrixOperation::CKNCSR *pAMatrix, unsigned int nIterationCount, unsigned int nEigenValueCheckInterval, unsigned int nEigenValueCount, double fEigenvalueMin, double fEignevalueMax, double fConvergenceTolerance, bool bReorthogonalization, bool bCalcuEigVector, bool bWaveFunction, double load_in_MIC, CKNMatrixOperation::CKNCSR *pmylocalblock=NULL, CKNMatrixOperation::CKNCSR *leftlocalblock=NULL, CKNMatrixOperation::CKNCSR *rightlocalblock=NULL)
Doing lanczos method.
static void ShowMsg(char *pszBuffer)
Show message.
static double GetTotalTakeTime()
static void SaveResultCVS()
static int GetCurrentRank()
Definition: KNMPIManager.h:42
#define LARGE_SIZE_MATRIX_FILE
static void TotalMeasurementEnd()
Measurement end for total taken time.
static void TotalMeasurementStart()
Measurement start for total taken time.
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: CKNGlobal.h:62
static void AuditResult_WF(CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fTolerance, unsigned int nWaveFunctionSize)
static void ReleaseResult(LPEIGENVALUE_RESULT lpResult, bool bReleaseStruct)
Release memory for lanczos method result.
static void LoadBlancingForLanczos(int nRowCount)
Load blancing for MPI, this function only for lanczos solving without geometric constrcution.
static bool IsRootRank()
Get Total node count.
static void InitTimer()
Init time related variable.

Here is the call graph for this function:

void CKNLanczosTest::SaveResult ( CKNLanczosMethod::LPEIGENVALUE_RESULT  lpResult,
unsigned int  nMatrixSize,
bool  bCalcuEigenvalue,
bool  bWaveFunction 
)
static

Definition at line 910 of file KNLanczosTest.cpp.

References CKNTimeMeasurement::FILEIO, CKNMatrixOperation::CKNVector::GetAt(), CKNComplex::GetImaginaryNumber(), CKNComplex::GetRealNumber(), CKNTimeMeasurement::MeasurementEnd(), CKNTimeMeasurement::MeasurementStart(), CKNLanczosMethod::EIGENVALUE_RESULT::nEigenValueCount, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenValues, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenVectorsForAMatrix, and CKNLanczosMethod::EIGENVALUE_RESULT::pWaveFunctions.

911 {
912  if( NULL == lpResult)
913  return;
914 
916  FILE *out;
917  char szFileName[1024], szBuffer[1024];
918  std::string writeString;
919  unsigned int i, j;
920 
921 #ifdef _WIN32
922  _mkdir("result");
923 #else
924  mkdir("result", 0777);
925 #endif
926 #ifdef _WIN32
927  if( NULL != (out = fopen("result\\eigenvalues.txt", "wt")))
928 #else _WIN32
929  if( NULL != (out = fopen("result/eigenvalues.txt", "wt")))
930 #endif //_WIN32
931  {
932  for( i = 0 ;i < lpResult->nEigenValueCount ; i ++ )
933  {
934  sprintf(szBuffer, "[ev %d] %18.16f\n", i, lpResult->pEigenValues[i]);
935  fputs(szBuffer, out);
936  }
937  fclose(out);
938  }
939 
940  if( bCalcuEigenvalue && NULL != lpResult->pEigenVectorsForAMatrix )
941  {
942  for( j = 0 ; j < lpResult->nEigenValueCount ; j ++)
943  {
944 #ifdef _WIN32
945  sprintf(szFileName, "result\\eigenvector_%02d.txt", j);
946 #else _WIN32
947  sprintf(szFileName, "result/eigenvector_%02d.txt", j);
948 #endif //_WIN32
949 
950  if( NULL != (out = fopen(szFileName, "wt")))
951  {
952  for( i = 0 ;i < nMatrixSize ; i ++ )
953  {
954  sprintf(szBuffer, "%16.16f %16.16f\n",
955  lpResult->pEigenVectorsForAMatrix[j].GetAt(i).GetRealNumber(),
957 
958  writeString += szBuffer;
959 
960  if( i % 100 )
961  {
962  fputs(writeString.c_str(), out);
963  writeString.clear();
964  }
965  }
966 
967  if( !writeString.empty() )
968  {
969  fputs(writeString.c_str(), out);
970  writeString.clear();
971  }
972 
973  fclose(out);
974  }
975  }
976  }
977 
978  if( bWaveFunction && NULL != lpResult->pWaveFunctions )
979  {
980  for( j = 0 ; j < lpResult->nEigenValueCount ; j ++)
981  {
982 #ifdef _WIN32
983  sprintf(szFileName, "result\\wavefunction_%02d.txt", j);
984 #else _WIN32
985  sprintf(szFileName, "result/wavefunction_%02d.txt", j);
986 #endif //_WIN32
987 
988  if( NULL != (out = fopen(szFileName, "wt")))
989  {
990  for( i = 0 ;i < nMatrixSize / 10 ; i ++ )
991  {
992  sprintf(szBuffer, "%16.16f\n",
993  lpResult->pWaveFunctions[j].GetAt(i).GetRealNumber());
994 
995  writeString += szBuffer;
996 
997  if( i % 100 )
998  {
999  fputs(writeString.c_str(), out);
1000  writeString.clear();
1001  }
1002  }
1003 
1004  if( !writeString.empty() )
1005  {
1006  fputs(writeString.c_str(), out);
1007  writeString.clear();
1008  }
1009  fclose(out);
1010  }
1011  }
1012  }
1013 
1014 
1016 }
CKNMatrixOperation::CKNVector * pWaveFunctions
double GetImaginaryNumber() const
Get imaginary part.
Definition: KNComplex.h:27
double GetRealNumber() const
Get real part.
Definition: KNComplex.h:26
CKNMatrixOperation::CKNVector * pEigenVectorsForAMatrix
static void MeasurementEnd(MEASUREMENT_INDEX index)
Measurement end for part.
CKNComplex GetAt(unsigned int nIndex)
Get element value from specific index.
static void MeasurementStart(MEASUREMENT_INDEX index)
Measurement start for part.

Here is the call graph for this function:

void CKNLanczosTest::SaveResultCVS ( )
static

Definition at line 880 of file KNLanczosTest.cpp.

References CKNTimeMeasurement::COMM, CKNTimeMeasurement::EVALUE, CKNTimeMeasurement::FILEIO, CKNTimeMeasurement::FREE_MEM, CKNTimeMeasurement::GetTakeTime(), CKNMPIManager::GetTotalNodeCount(), CKNTimeMeasurement::GetTotalTakeTime(), and CKNTimeMeasurement::MALLOC.

881 {
882  FILE *out;
883 
884 #ifdef _WIN32
885  _mkdir("result");
886 #else
887  mkdir("result", 0777);
888 #endif
889 #ifdef _WIN32
890  if( NULL != (out = fopen("result\\evaluation.txt", "wt")))
891 #else _WIN32
892  if( NULL != (out = fopen("result/evaluation.txt", "wt")))
893 #endif //_WIN32
894  {
895  char szTemp[1024];
896 
897  sprintf(szTemp, "%d,%f,%f,%f,%f,%f,%f\n",
905  fputs(szTemp, out);
906  fclose(out);
907  }
908 }
static double GetTakeTime(MEASUREMENT_INDEX index)
Get taken time for part.
static int GetTotalNodeCount()
Definition: KNMPIManager.h:44
static double GetTotalTakeTime()

Here is the call graph for this function:

static void CKNLanczosTest::ShowMsg ( char *  pszBuffer)
static
void CKNLanczosTest::SolvingLargeSizeHamlitonian ( int  nIteration,
int  nInterval,
int  nEigCount,
bool  bSelect,
bool  bCalcuVector,
bool  bWaveFunction 
)
static

H00, H01 ÆÄÀÏ Loading

Definition at line 324 of file KNLanczosTest.cpp.

References CKNLanczosMethod::DoLanczosMethod(), ERROR_MALLOC, ERROR_OUT_OF_RANGE, CKNMatrixOperation::FreeCSR(), LARGE_SIZE_MATRIX_FILE, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenVectorsForAMatrix, CKNLanczosMethod::ReleaseResult(), and CKNMatrixDebug::ShowMsg().

325 {
326  CKNMatrixOperation::CKNCSR *pA_Matrix = NULL;
328 
329  try
330  {
331  CKNLanczosMethod lanczos;
332 
333  CKNMatrixDebug::ShowMsg("-Start Lanczos eigenvalue solver for Large size Matrix\n");
335  CKNMatrixDebug::ShowMsg("-Data file has been read\n");
336 
337  if (NULL == pA_Matrix)
338  {
339  CKNMatrixDebug::ShowMsg("Error while Loading Matlab file\n");
340  return;
341  }
342 
343  lpResult = lanczos.DoLanczosMethod(pA_Matrix, nIteration, nInterval, nEigCount, -0.1, 1.63, 1e-8, bSelect, bCalcuVector, bWaveFunction);
344  if (lpResult && lpResult->pEigenVectorsForAMatrix && bCalcuVector)
345  AuditResult_EV(pA_Matrix, lpResult, 1e-8);
346 
347  CKNLanczosMethod::ReleaseResult(lpResult, true);
348  CKNMatrixOperation::FreeCSR(pA_Matrix);
349  CKNMatrixDebug::ShowMsg("-Finished Lanczos eigenvalue solver for Large size Matrix\n");
350  }
351  catch (unsigned long dwError)
352  {
353  switch (dwError)
354  {
355  case ERROR_MALLOC:
356  CKNMatrixDebug::ShowMsg("Can't alloc memory!");
357  break;
358  case ERROR_OUT_OF_RANGE:
359  CKNMatrixDebug::ShowMsg("Row or Column index going out of range!");
360  break;
361  }
362  }
363  catch (...)
364  {
365  }
366 }
static void AuditResult_EV(CKNMatrixOperation::CKNCSR *pCSR, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fTolerance)
static CKNMatrixOperation::CKNCSR * LargeCSRBuildingViaFileForMPI(char *pszFileName, int nMatrixSize)
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.
CKNMatrixOperation::CKNVector * pEigenVectorsForAMatrix
Data and operation representation of CSR(Compressed Sparse Row)
This class for doing Lanczos method.
const unsigned long ERROR_OUT_OF_RANGE
Error code that means during access vector or matrix input index out of range.
Definition: CKNGlobal.h:63
Structure for engienvalue computing.
LPEIGENVALUE_RESULT DoLanczosMethod(CKNMatrixOperation::CKNCSR *pAMatrix, unsigned int nIterationCount, unsigned int nEigenValueCheckInterval, unsigned int nEigenValueCount, double fEigenvalueMin, double fEignevalueMax, double fConvergenceTolerance, bool bReorthogonalization, bool bCalcuEigVector, bool bWaveFunction, double load_in_MIC, CKNMatrixOperation::CKNCSR *pmylocalblock=NULL, CKNMatrixOperation::CKNCSR *leftlocalblock=NULL, CKNMatrixOperation::CKNCSR *rightlocalblock=NULL)
Doing lanczos method.
static void ShowMsg(char *pszBuffer)
Show message.
#define LARGE_SIZE_MATRIX_FILE
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: CKNGlobal.h:62
static void ReleaseResult(LPEIGENVALUE_RESULT lpResult, bool bReleaseStruct)
Release memory for lanczos method result.

Here is the call graph for this function:

void CKNLanczosTest::StopLanczos ( )
static

Definition at line 1512 of file KNLanczosTest.cpp.

1513 {
1514  if (NULL != m_pCurrentLanczosInstance)
1516 }
static void StopIteration()
Stop lanczos iteration on going state.
static CKNLanczosMethod * m_pCurrentLanczosInstance
Definition: KNLanczosTest.h:37
void CKNLanczosTest::TestCSRBuilding ( )
static

Definition at line 1448 of file KNLanczosTest.cpp.

References CKNMatrixOperation::DumpCSR(), ERROR_MALLOC, ERROR_OUT_OF_RANGE, CKNMatrixOperation::FreeCSR(), CKNMatrixOperation::CKNCSR::InsertColumnAtEnd(), CKNMatrixOperation::CKNCSR::InsertRowAtEnd(), CKNMatrixOperation::CKNCSR::SetAt(), CKNComplex::SetComplexNumber(), CKNMatrixDebug::ShowCSR(), and CKNMatrixDebug::ShowMsg().

1449 {
1450  CKNMatrixOperation::CKNCSR *pCSR = NULL;
1451 
1452  try
1453  {
1454  CKNComplex number;
1455  pCSR = TestCSRBuildingViaArray();
1456  CKNMatrixDebug::ShowCSR(pCSR, "After building");
1457 
1458  /*number.SetComplexNumber(100, 100);
1459  pCSR->SetAt(number, 2, 1);
1460  CKNMatrixDebug::ShowCSR(pCSR, "After update element");
1461 
1462  pCSR->InsertColumnBefore(2);
1463  CKNMatrixDebug::ShowCSR(pCSR, "Insert col before 2");
1464 
1465  pCSR->InsertRowBefore(2);
1466  CKNMatrixDebug::ShowCSR(pCSR, "Insert row before 2");*/
1467 
1468  pCSR->InsertColumnAtEnd();
1469  CKNMatrixDebug::ShowCSR(pCSR, "Insert column at end");
1470 
1471  number.SetComplexNumber(777, 777);
1472  pCSR->SetAt(number, 2, 2);
1473  CKNMatrixDebug::ShowCSR(pCSR, "Set inserted row, column index");
1474 
1475  number.SetComplexNumber(222, 222);
1476  pCSR->SetAt(number, 3, 5);
1477  CKNMatrixDebug::ShowCSR(pCSR, "After Set element");
1478 
1479  /*pCSR->InsertColumnAtEnd();
1480  CKNMatrixDebug::ShowCSR(pCSR, "Insert col at end");
1481  */
1482  pCSR->InsertRowAtEnd();
1483  CKNMatrixDebug::ShowCSR(pCSR, "Insert row at end");
1484 
1485  number.SetComplexNumber(555, 555);
1486  pCSR->SetAt(number, 7, 7);
1487  CKNMatrixDebug::ShowCSR(pCSR, "After Set element");
1488 
1489  //pCSR->ExpandMatrix(7, true, true);
1490  CKNMatrixOperation::DumpCSR(pCSR, "dump_simple.txt");
1492 
1493  }
1494  catch (unsigned long dwError)
1495  {
1496  switch (dwError)
1497  {
1498  case ERROR_MALLOC:
1499  CKNMatrixDebug::ShowMsg("Can't alloc memory!");
1500  break;
1501  case ERROR_OUT_OF_RANGE:
1502  CKNMatrixDebug::ShowMsg("Row or Column index going out of range!");
1503  break;
1504  }
1505  }
1506  catch (...)
1507  {
1508  }
1509 }
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.
bool InsertRowAtEnd()
Insert row after last row.
Data and operation representation of CSR(Compressed Sparse Row)
const unsigned long ERROR_OUT_OF_RANGE
Error code that means during access vector or matrix input index out of range.
Definition: CKNGlobal.h:63
bool SetAt(CKNComplex number, unsigned int nRow, unsigned int nColumn)
Set element to specific index.
static void ShowMsg(char *pszBuffer)
Show message.
static void ShowCSR(CKNMatrixOperation::CKNCSR *pCSR, char *pszDebugMsg)
Set show message or not.
bool InsertColumnAtEnd()
Insert column after last column.
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: CKNGlobal.h:62
This class for complex operation and saving value.
Definition: KNComplex.h:18
static void DumpCSR(CKNMatrixOperation::CKNCSR *pCSR, const char *pstrFileName)
For dubugging save CSR information into file.
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaArray()
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:

CKNMatrixOperation::CKNCSR * CKNLanczosTest::TestCSRBuildingViaArray ( )
static

Definition at line 60 of file KNLanczosTest.cpp.

References CKNMatrixOperation::BuildCSRFromOneDimArray().

61 {
62  CKNMatrixOperation::CKNCSR *pCSR = NULL;
63 
64  double fSparseRowDataReal[36] = { 10, 0, 0, 0., -2, 0.,
65  3., 9, 0, 0, 0., 3,
66  0., 7, 8, 0, 0, 0,
67  3, 0., 8., 7, 5, 0,
68  0., 8., 0, 9., 9, 13,
69  0, 4, 0, 0, 0, -1 };
70 
71  double fSparseRowDataImaginary[36] = { 1, 0, 0, 0., 4, 0.,
72  3., 1, 0, 1.0, 0., 45,
73  0., 3, 4, 4.5, 0, 0,
74  0, 0., 9.1, 3, 6, 0,
75  1., 8.3, 0, 1., 10, 3.1,
76  0, 5.2, 0, 0, -22, -100 };
77 
78  pCSR = CKNMatrixOperation::BuildCSRFromOneDimArray(fSparseRowDataReal, fSparseRowDataImaginary, 6, 6);
79 
80  return pCSR;
81 }
Data and operation representation of CSR(Compressed Sparse Row)
static CKNMatrixOperation::CKNCSR * BuildCSRFromOneDimArray(double *pReal, double *pImaginary, unsigned int nRowOrder, unsigned int nColumnOrder)
Building CSR from one dimension array.

Here is the call graph for this function:

CKNMatrixOperation::CKNCSR * CKNLanczosTest::TestCSRBuildingViaFileLoad ( char *  pszFileName,
int  nMatrixSize 
)
static

< Convert nonzero base index to zero base index

< Convert nonzero base index to zero base index

Definition at line 83 of file KNLanczosTest.cpp.

References CKNMatrixOperation::BuildCSRFromOneDimArray(), ERROR_MALLOC, FREE_MEM, CKNMPIManager::GetCurrentLoadBalanceCount(), CKNMPIManager::GetCurrentRank(), CKNMPIManager::GetLoadBalanceCount(), and CKNMPIManager::IsInMPIRoutine().

84 {
85  FILE *fMatlabFile = NULL;
86  double *pfSparseRowData = NULL;
87  double *pfSparseRowData_i = NULL;
88  CKNMatrixOperation::CKNCSR *pCSR = NULL;
89  int m = 0;
90  double *pfRow = NULL, *pfColumn = NULL, *pfReal = NULL, *pfImginary = NULL;
91  int nRow, nColumn;
92  int i;
93 
94 
95  if (NULL != (fMatlabFile = fopen(pszFileName, "rb")))
96  {
97 
98 
99  pfSparseRowData = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
100  if (NULL == pfSparseRowData) throw ERROR_MALLOC;
101 
102  pfSparseRowData_i = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
103  if (NULL == pfSparseRowData_i) throw ERROR_MALLOC;
104 
105  pfRow = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
106  if (NULL == pfRow) throw ERROR_MALLOC;
107 
108  pfColumn = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
109  if (NULL == pfColumn) throw ERROR_MALLOC;
110 
111  pfReal = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
112  if (NULL == pfReal) throw ERROR_MALLOC;
113 
114  pfImginary = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
115  if (NULL == pfImginary) throw ERROR_MALLOC;
116 
117  memset(pfSparseRowData, 0, sizeof(double)* nMatrixSize * nMatrixSize);
118  memset(pfSparseRowData_i, 0, sizeof(double)* nMatrixSize * nMatrixSize);
119 
120  memset(pfRow, 0, sizeof(double)* nMatrixSize * nMatrixSize);
121  memset(pfColumn, 0, sizeof(double)* nMatrixSize * nMatrixSize);
122  memset(pfReal, 0, sizeof(double)* nMatrixSize * nMatrixSize);
123  memset(pfImginary, 0, sizeof(double)* nMatrixSize * nMatrixSize);
124 
125 
126  fseek(fMatlabFile, 0L, SEEK_END);
127  int fileLen = ftell(fMatlabFile);
128  fseek(fMatlabFile, 0L, SEEK_SET);
129 
130  int nCount = fileLen / (sizeof(double)* 4);
131 
132 
133  for (i = 0; i < nCount; i++)
134  fread(&pfRow[i], sizeof(double), 1, fMatlabFile);
135  for (i = 0; i < nCount; i++)
136  fread(&pfColumn[i], sizeof(double), 1, fMatlabFile);
137  for (i = 0; i < nCount; i++)
138  fread(&pfReal[i], sizeof(double), 1, fMatlabFile);
139  for (i = 0; i < nCount; i++)
140  fread(&pfImginary[i], sizeof(double), 1, fMatlabFile);
141 
142  for (i = 0; i < nCount; i++)
143  {
144  nRow = (int)pfRow[i] - 1;
145  nColumn = (int)pfColumn[i] - 1;
146  pfSparseRowData[nRow * nMatrixSize + nColumn] = pfReal[i];
147  pfSparseRowData_i[nRow * nMatrixSize + nColumn] = pfImginary[i];
148  }
149 
150  FREE_MEM(pfRow);
151  FREE_MEM(pfColumn);
152  FREE_MEM(pfReal);
153  FREE_MEM(pfImginary);
154 
155  fclose(fMatlabFile);
156  }
157  else
158  return NULL;
159 
160  int nStartPos = 0;
161 
162 
163  int nReadRowSize = nMatrixSize;
165  {
166  for (i = 0; i < CKNMPIManager::GetCurrentRank(); i++)
167  nStartPos += CKNMPIManager::GetLoadBalanceCount(i);
168 
170  }
171  else
172  nStartPos = 0;
173 
174 
175  pCSR = CKNMatrixOperation::BuildCSRFromOneDimArray(pfSparseRowData + nStartPos * nMatrixSize,
176  pfSparseRowData_i + nStartPos * nMatrixSize, nReadRowSize, nMatrixSize);
177 
178  if (NULL != pfSparseRowData)
179  {
180  free(pfSparseRowData);
181  pfSparseRowData = NULL;
182  }
183 
184  if (NULL != pfSparseRowData_i)
185  {
186  free(pfSparseRowData_i);
187  pfSparseRowData_i = NULL;
188  }
189 
190 
191 
192  return pCSR;
193 }
Data and operation representation of CSR(Compressed Sparse Row)
static int GetCurrentLoadBalanceCount()
Get Current node's rank load balancing number.
static CKNMatrixOperation::CKNCSR * BuildCSRFromOneDimArray(double *pReal, double *pImaginary, unsigned int nRowOrder, unsigned int nColumnOrder)
Building CSR from one dimension array.
static int GetLoadBalanceCount(int nRank)
static bool IsInMPIRoutine()
Definition: KNMPIManager.h:47
static int GetCurrentRank()
Definition: KNMPIManager.h:42
#define FREE_MEM(pointer)
Macro for memory allocation and assign null value.
Definition: CKNGlobal.h:20
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:

CKNMatrixOperation::CKNCSR * CKNLanczosTest::TestCSRBuildingViaFileLoad_ ( char *  pszFileName,
int  nMatrixSize 
)
static

< Convert nonzero base index to zero base index

< Convert nonzero base index to zero base index

Definition at line 195 of file KNLanczosTest.cpp.

References CKNMatrixOperation::BuildCSRFromOneDimArray(), ERROR_MALLOC, FREE_MEM, CKNMatrixOperation::FreeCSR(), CKNMPIManager::GetCurrentLoadBalanceCount(), CKNMPIManager::GetCurrentRank(), CKNMPIManager::GetLoadBalanceCount(), and CKNMatrixOperation::CKNCSR::SplitCSR().

196 {
197  FILE *fMatlabFile = NULL;
198  double *pfSparseRowData = NULL;
199  double *pfSparseRowData_i = NULL;
200  CKNMatrixOperation::CKNCSR *pCSR = NULL, *pCSRTotal = NULL;
201  int m = 0;
202  double *pfRow = NULL, *pfColumn = NULL, *pfReal = NULL, *pfImginary = NULL;
203  int nRow, nColumn;
204  int i;
205 
206 
207  if (NULL != (fMatlabFile = fopen(pszFileName, "rb")))
208  {
209 
210 
211  pfSparseRowData = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
212  if (NULL == pfSparseRowData) throw ERROR_MALLOC;
213 
214  pfSparseRowData_i = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
215  if (NULL == pfSparseRowData_i) throw ERROR_MALLOC;
216 
217  pfRow = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
218  if (NULL == pfRow) throw ERROR_MALLOC;
219 
220  pfColumn = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
221  if (NULL == pfColumn) throw ERROR_MALLOC;
222 
223  pfReal = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
224  if (NULL == pfReal) throw ERROR_MALLOC;
225 
226  pfImginary = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
227  if (NULL == pfImginary) throw ERROR_MALLOC;
228 
229  memset(pfSparseRowData, 0, sizeof(double)* nMatrixSize * nMatrixSize);
230  memset(pfSparseRowData_i, 0, sizeof(double)* nMatrixSize * nMatrixSize);
231 
232  memset(pfRow, 0, sizeof(double)* nMatrixSize * nMatrixSize);
233  memset(pfColumn, 0, sizeof(double)* nMatrixSize * nMatrixSize);
234  memset(pfReal, 0, sizeof(double)* nMatrixSize * nMatrixSize);
235  memset(pfImginary, 0, sizeof(double)* nMatrixSize * nMatrixSize);
236 
237 
238  fseek(fMatlabFile, 0L, SEEK_END);
239  int fileLen = ftell(fMatlabFile);
240  fseek(fMatlabFile, 0L, SEEK_SET);
241 
242  int nCount = fileLen / (sizeof(double)* 4);
243 
244 
245  for (i = 0; i < nCount; i++)
246  fread(&pfRow[i], sizeof(double), 1, fMatlabFile);
247  for (i = 0; i < nCount; i++)
248  fread(&pfColumn[i], sizeof(double), 1, fMatlabFile);
249  for (i = 0; i < nCount; i++)
250  fread(&pfReal[i], sizeof(double), 1, fMatlabFile);
251  for (i = 0; i < nCount; i++)
252  fread(&pfImginary[i], sizeof(double), 1, fMatlabFile);
253 
254  for (i = 0; i < nCount; i++)
255  {
256  nRow = (int)pfRow[i] - 1;
257  nColumn = (int)pfColumn[i] - 1;
258  pfSparseRowData[nRow * nMatrixSize + nColumn] = pfReal[i];
259  pfSparseRowData_i[nRow * nMatrixSize + nColumn] = pfImginary[i];
260  }
261 
262  FREE_MEM(pfRow);
263  FREE_MEM(pfColumn);
264  FREE_MEM(pfReal);
265  FREE_MEM(pfImginary);
266 
267  fclose(fMatlabFile);
268  }
269  else
270  return NULL;
271 
272  int nStartPos = 0;
273 
274 
275  int nReadRowSize = nMatrixSize;
276  pCSRTotal = CKNMatrixOperation::BuildCSRFromOneDimArray(pfSparseRowData, pfSparseRowData_i, nMatrixSize, nMatrixSize);
277 
278  unsigned int nRowStart = 0, nRowEnd;
279 
280  for( i = 0 ; i < CKNMPIManager::GetCurrentRank() ; i ++)
281  nRowStart += CKNMPIManager::GetLoadBalanceCount(i);
282 
283  nRowEnd = nRowStart + CKNMPIManager::GetCurrentLoadBalanceCount();
284 
285  pCSR = pCSRTotal->SplitCSR(nRowStart, nRowEnd);
286  CKNMatrixOperation::FreeCSR(pCSRTotal);
287 
288  if (NULL != pfSparseRowData)
289  {
290  free(pfSparseRowData);
291  pfSparseRowData = NULL;
292  }
293 
294  if (NULL != pfSparseRowData_i)
295  {
296  free(pfSparseRowData_i);
297  pfSparseRowData_i = NULL;
298  }
299 
300 
301 
302  return pCSR;
303 }
CKNCSR * SplitCSR(int nStart, int nEnd)
Split CSR to MPI slave.
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.
Data and operation representation of CSR(Compressed Sparse Row)
static int GetCurrentLoadBalanceCount()
Get Current node's rank load balancing number.
static CKNMatrixOperation::CKNCSR * BuildCSRFromOneDimArray(double *pReal, double *pImaginary, unsigned int nRowOrder, unsigned int nColumnOrder)
Building CSR from one dimension array.
static int GetLoadBalanceCount(int nRank)
static int GetCurrentRank()
Definition: KNMPIManager.h:42
#define FREE_MEM(pointer)
Macro for memory allocation and assign null value.
Definition: CKNGlobal.h:20
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:

CKNMatrixOperation::CKNCSR * CKNLanczosTest::TestCSRBuildingViaFileLoadOrigin ( char *  pszFileName,
int  nMatrixSize 
)
static

< Convert nonzero base index to zero base index

< Convert nonzero base index to zero base index

Definition at line 368 of file KNLanczosTest.cpp.

References CKNMatrixOperation::BuildCSRFromOneDimArray(), ERROR_MALLOC, and FREE_MEM.

369 {
370  FILE *fMatlabFile = NULL;
371  double *pfSparseRowData = NULL;
372  double *pfSparseRowData_i = NULL;
373  CKNMatrixOperation::CKNCSR *pCSR = NULL;
374  int m = 0;
375  double *pfRow = NULL, *pfColumn = NULL, *pfReal = NULL, *pfImginary = NULL;
376  int nRow, nColumn;
377  int i;
378 
379 
380  if (NULL != (fMatlabFile = fopen(pszFileName, "rb")))
381  {
382 
383 
384  pfSparseRowData = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
385  if (NULL == pfSparseRowData) throw ERROR_MALLOC;
386 
387  pfSparseRowData_i = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
388  if (NULL == pfSparseRowData_i) throw ERROR_MALLOC;
389 
390  pfRow = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
391  if (NULL == pfRow) throw ERROR_MALLOC;
392 
393  pfColumn = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
394  if (NULL == pfColumn) throw ERROR_MALLOC;
395 
396  pfReal = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
397  if (NULL == pfReal) throw ERROR_MALLOC;
398 
399  pfImginary = (double*)malloc(sizeof(double)* nMatrixSize * nMatrixSize);
400  if (NULL == pfImginary) throw ERROR_MALLOC;
401 
402  memset(pfSparseRowData, 0, sizeof(double)* nMatrixSize * nMatrixSize);
403  memset(pfSparseRowData_i, 0, sizeof(double)* nMatrixSize * nMatrixSize);
404 
405  memset(pfRow, 0, sizeof(double)* nMatrixSize * nMatrixSize);
406  memset(pfColumn, 0, sizeof(double)* nMatrixSize * nMatrixSize);
407  memset(pfReal, 0, sizeof(double)* nMatrixSize * nMatrixSize);
408  memset(pfImginary, 0, sizeof(double)* nMatrixSize * nMatrixSize);
409 
410 
411  fseek(fMatlabFile, 0L, SEEK_END);
412  int fileLen = ftell(fMatlabFile);
413  fseek(fMatlabFile, 0L, SEEK_SET);
414 
415  int nCount = fileLen / (sizeof(double)* 4);
416 
417 
418  for (i = 0; i < nCount; i++)
419  fread(&pfRow[i], sizeof(double), 1, fMatlabFile);
420  for (i = 0; i < nCount; i++)
421  fread(&pfColumn[i], sizeof(double), 1, fMatlabFile);
422  for (i = 0; i < nCount; i++)
423  fread(&pfReal[i], sizeof(double), 1, fMatlabFile);
424  for (i = 0; i < nCount; i++)
425  fread(&pfImginary[i], sizeof(double), 1, fMatlabFile);
426 
427  for (i = 0; i < nCount; i++)
428  {
429  nRow = (int)pfRow[i] - 1;
430  nColumn = (int)pfColumn[i] - 1;
431  pfSparseRowData[nRow * nMatrixSize + nColumn] = pfReal[i];
432  pfSparseRowData_i[nRow * nMatrixSize + nColumn] = pfImginary[i];
433  }
434 
435  FREE_MEM(pfRow);
436  FREE_MEM(pfColumn);
437  FREE_MEM(pfReal);
438  FREE_MEM(pfImginary);
439 
440  fclose(fMatlabFile);
441  }
442  else
443  return NULL;
444 
445  pCSR = CKNMatrixOperation::BuildCSRFromOneDimArray(pfSparseRowData, pfSparseRowData_i, nMatrixSize, nMatrixSize);
446 
447  if (NULL != pfSparseRowData)
448  {
449  free(pfSparseRowData);
450  pfSparseRowData = NULL;
451  }
452 
453  if (NULL != pfSparseRowData_i)
454  {
455  free(pfSparseRowData_i);
456  pfSparseRowData_i = NULL;
457  }
458 
459 
460 
461  return pCSR;
462 }
Data and operation representation of CSR(Compressed Sparse Row)
static CKNMatrixOperation::CKNCSR * BuildCSRFromOneDimArray(double *pReal, double *pImaginary, unsigned int nRowOrder, unsigned int nColumnOrder)
Building CSR from one dimension array.
#define FREE_MEM(pointer)
Macro for memory allocation and assign null value.
Definition: CKNGlobal.h:20
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:

void CKNLanczosTest::TestLanczos ( int  nIteration,
int  nInterval,
int  nEigCount,
bool  bCalcuVector 
)
static

H00, H01 ÆÄÀÏ Loading

Definition at line 1343 of file KNLanczosTest.cpp.

References CKNLanczosMethod::DoLanczosMethod(), ERROR_MALLOC, ERROR_OUT_OF_RANGE, CKNMatrixOperation::FreeCSR(), CKNLanczosMethod::EIGENVALUE_RESULT::nEigenValueCount, CKNLanczosMethod::EIGENVALUE_RESULT::pEigenValues, CKNLanczosMethod::ReleaseResult(), CKNMatrixDebug::SaveResult(), and CKNMatrixDebug::ShowMsg().

1344 {
1345  CKNMatrixOperation::CKNCSR *pA_Matrix = NULL;
1346  int nEigenValueCount = 0;
1347  int nFindEigenvalueCount = 60;
1348  CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult = NULL;
1349  unsigned int j;
1350 
1351  try
1352  {
1353  FILE *fpMatlabResult;
1354 
1355  fpMatlabResult = fopen("./data/Lanczosresult.csv", "w");
1356  fclose(fpMatlabResult);
1357 
1358  if (NULL != (fpMatlabResult = fopen("./data/Lanczosresult.csv", "at")))
1359  {
1360  char szBuffer[1024];
1361 
1362  for (int i = 1; i <= 41; i++)
1363  {
1364  char szBuffer2[10240] = "";
1365  //CKNMatrixDebug::ShowMsg("\n\n-Start Lanczos eigenvalue solver\n");
1366  sprintf(szBuffer, "\n\n%dth -Start Lanczos eigenvalue solver\n", i);
1367  CKNMatrixDebug::ShowMsg(szBuffer);
1368  sprintf(szBuffer, "data\\Matlab_%d.dat", i);
1369  pA_Matrix = TestCSRBuildingViaFileLoad(szBuffer, 2000);
1370 
1371  CKNLanczosMethod lanczos;
1372  lpResult = lanczos.DoLanczosMethod(pA_Matrix, nIteration, nInterval, nEigCount, 1.2, 2.3, 1e-8, false, bCalcuVector, false);
1373  //lpResult = lanczos.DoLanczosMethod(pA_Matrix, 2000, 100, 10, 1.2, 2.3, DO_NOT_CONVERGENCE_CHECKING, false);
1374  //AuditResult(i, nFindEigenvalueCount, lpResult[i - 1], 1.2, 2.3);
1375  CKNMatrixDebug::SaveResult(lpResult, i);
1376 
1377  sprintf(szBuffer2, "%d,", i);
1378  for (j = 0; j < lpResult->nEigenValueCount; j++)
1379  {
1380  sprintf(szBuffer2, "%s,%20.20f", szBuffer2, lpResult->pEigenValues[j]);
1381  }
1382 
1383  strcat(szBuffer2, "\n");
1384  fputs(szBuffer2, fpMatlabResult);
1385 
1386  CKNLanczosMethod::ReleaseResult(lpResult, true);
1387  CKNMatrixOperation::FreeCSR(pA_Matrix);
1388  CKNMatrixDebug::ShowMsg("-Finish Lanczos eigenvalue solver\n");
1389 
1390 
1391  }
1392 
1393  fclose(fpMatlabResult);
1394  }
1395 
1396  }
1397  catch (unsigned long dwError)
1398  {
1399  switch (dwError)
1400  {
1401  case ERROR_MALLOC:
1402  CKNMatrixDebug::ShowMsg("Can't alloc memory!");
1403  break;
1404  case ERROR_OUT_OF_RANGE:
1405  CKNMatrixDebug::ShowMsg("Row or Column index going out of range!");
1406  break;
1407  }
1408  }
1409  catch (...)
1410  {
1411  }
1412 }
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.
Data and operation representation of CSR(Compressed Sparse Row)
This class for doing Lanczos method.
static void SaveResult(CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, int nIndex)
Show lanczos method result.
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaFileLoad(char *pszFileName, int nMatrixSize)
const unsigned long ERROR_OUT_OF_RANGE
Error code that means during access vector or matrix input index out of range.
Definition: CKNGlobal.h:63
Structure for engienvalue computing.
LPEIGENVALUE_RESULT DoLanczosMethod(CKNMatrixOperation::CKNCSR *pAMatrix, unsigned int nIterationCount, unsigned int nEigenValueCheckInterval, unsigned int nEigenValueCount, double fEigenvalueMin, double fEignevalueMax, double fConvergenceTolerance, bool bReorthogonalization, bool bCalcuEigVector, bool bWaveFunction, double load_in_MIC, CKNMatrixOperation::CKNCSR *pmylocalblock=NULL, CKNMatrixOperation::CKNCSR *leftlocalblock=NULL, CKNMatrixOperation::CKNCSR *rightlocalblock=NULL)
Doing lanczos method.
static void ShowMsg(char *pszBuffer)
Show message.
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: CKNGlobal.h:62
static void ReleaseResult(LPEIGENVALUE_RESULT lpResult, bool bReleaseStruct)
Release memory for lanczos method result.

Here is the call graph for this function:

void CKNLanczosTest::TestSimpleLanczos ( )
static

ÀÛÀº Matrix ¿¬»ê Å×½ºÆ®

Definition at line 1414 of file KNLanczosTest.cpp.

References CKNLanczosMethod::DoLanczosMethod(), ERROR_MALLOC, ERROR_OUT_OF_RANGE, CKNMatrixOperation::FreeCSR(), CKNLanczosMethod::ReleaseResult(), and CKNMatrixDebug::ShowMsg().

1415 {
1416  CKNMatrixOperation::CKNCSR *pA_Matrix = NULL;
1417  int nEigenValueCount = 0;
1418  CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult = NULL;
1419 
1420  try
1421  {
1422  pA_Matrix = TestCSRBuildingViaArray();
1423 
1424  CKNLanczosMethod lanczos;
1425  lpResult = lanczos.DoLanczosMethod(pA_Matrix, 6, 6, 1, 1.2, 2.3, 1e-8, false, false, false);
1426 
1427  CKNLanczosMethod::ReleaseResult(lpResult, true);
1428  CKNMatrixOperation::FreeCSR(pA_Matrix);
1429  }
1430  catch (unsigned long dwError)
1431  {
1432  switch (dwError)
1433  {
1434  case ERROR_MALLOC:
1435  CKNMatrixDebug::ShowMsg("Can't alloc memory!");
1436  break;
1437  case ERROR_OUT_OF_RANGE:
1438  CKNMatrixDebug::ShowMsg("Row or Column index going out of range!");
1439  break;
1440  }
1441  }
1442  catch (...)
1443  {
1444  }
1445 }
static void FreeCSR(CKNMatrixOperation::CKNCSR *pCSR)
Deallocating CSR memory.
Data and operation representation of CSR(Compressed Sparse Row)
This class for doing Lanczos method.
const unsigned long ERROR_OUT_OF_RANGE
Error code that means during access vector or matrix input index out of range.
Definition: CKNGlobal.h:63
Structure for engienvalue computing.
LPEIGENVALUE_RESULT DoLanczosMethod(CKNMatrixOperation::CKNCSR *pAMatrix, unsigned int nIterationCount, unsigned int nEigenValueCheckInterval, unsigned int nEigenValueCount, double fEigenvalueMin, double fEignevalueMax, double fConvergenceTolerance, bool bReorthogonalization, bool bCalcuEigVector, bool bWaveFunction, double load_in_MIC, CKNMatrixOperation::CKNCSR *pmylocalblock=NULL, CKNMatrixOperation::CKNCSR *leftlocalblock=NULL, CKNMatrixOperation::CKNCSR *rightlocalblock=NULL)
Doing lanczos method.
static void ShowMsg(char *pszBuffer)
Show message.
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
Definition: CKNGlobal.h:62
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaArray()
static void ReleaseResult(LPEIGENVALUE_RESULT lpResult, bool bReleaseStruct)
Release memory for lanczos method result.

Here is the call graph for this function:

Member Data Documentation

CKNLanczosMethod * CKNLanczosTest::m_pCurrentLanczosInstance = NULL
static

Definition at line 37 of file KNLanczosTest.h.

Referenced by LanczosThread().


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