IPCC  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
KNLanczosMethod.cpp File Reference

Lanczos method implementation class. More...

#include "stdafx.h"
#include "KNLanczosMethod.h"
#include "KNTimeMeasurement.h"
#include <math.h>
#include <string.h>
#include <algorithm>
#include "CKNGlobal.h"
#include "KNIPCCUtility.h"
#include "KNMPIManager.h"
#include "mkl.h"
#include <sys/stat.h>
#include <sys/types.h>
#include "XeonPhi_header.h"
Include dependency graph for KNLanczosMethod.cpp:

Go to the source code of this file.

Macros

#define SET_RESULT_TO_PARAMETER(pResultValue, pResultVector, nResultCount)
 

Functions

void thomas_alg (double **T, double *initguess, double *app_evc, int iter)
 
void inverse_iter (double *alpha, double *beta, double *app_evc, int iter, double app_eva)
 

Variables

unsigned int X_largest
 

Detailed Description

Lanczos method implementation class.

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 in file KNLanczosMethod.cpp.

Macro Definition Documentation

#define SET_RESULT_TO_PARAMETER (   pResultValue,
  pResultVector,
  nResultCount 
)
Value:
pCalcuResult_Value = pResultValue; \
pCalcuResult_Vector = pResultVector; \
nCalculatedEigenValueCount = nResultCount

Definition at line 858 of file KNLanczosMethod.cpp.

Function Documentation

void inverse_iter ( double *  alpha,
double *  beta,
double *  app_evc,
int  iter,
double  app_eva 
)

Definition at line 790 of file KNLanczosMethod.cpp.

References thomas_alg().

Referenced by CKNLanczosMethod::DoEigenValueSolving().

791 { //[completed]
792  int i, j, k, iteration = 20;
793  double temp = 0, err, etol = 1e-13;
794 
795  double *initguess = (double *)malloc(sizeof(double)*iter); // Initial Guess
796  double **T = (double **)malloc(sizeof(double)* 2);
797 
798  for (i = 0; i<2; i++)
799  T[i] = (double *)malloc(sizeof(double)*iter);
800 
801  for (i = 0; i<iter; i++)
802  initguess[i] = 1 / sqrt((double)iter);
803 
804  for (k = 0; k<iteration; k++)
805  {
806  for (i = 0; i<2; i++)
807  {
808  if (i == 1)
809  {
810  for (j = 0; j<iter; j++)
811  T[i][j] = alpha[j] - app_eva;
812 
813  }
814  else
815  {
816  for (j = 0; j<iter; j++)
817  T[i][j] = beta[j];
818  }
819  }
820 
821  thomas_alg(T, initguess, app_evc, iter); // Solve (T-app_eva*I)*app_evc=initguess
822 
823  temp = 0;
824  for (i = 0; i<iter; i++)
825  temp += app_evc[i] * app_evc[i];
826 
827  for (i = 0; i<iter; i++)
828  app_evc[i] = app_evc[i] / sqrt(temp);
829 
830  temp = 0;
831  for (i = 0; i<iter; i++)
832  {
833  if (i == 0)
834  temp += app_evc[i] * (alpha[i] * app_evc[i] + beta[i] * app_evc[i + 1]);
835  else if (i == iter - 1)
836  temp += app_evc[i] * (beta[i - 1] * app_evc[i - 1] + alpha[i] * app_evc[i]);
837  else
838  temp += app_evc[i] * (beta[i - 1] * app_evc[i - 1] + alpha[i] * app_evc[i] + beta[i] * app_evc[i + 1]);
839  }
840 
841  err = app_eva - temp;
842  if (fabs(err) < etol)
843  break;
844 
845  if (k<iteration - 1)
846  {
847  for (i = 0; i<iter; i++)
848  initguess[i] = app_evc[i];
849  }
850  } // Iteration k
851 
852  for (i = 0; i<2; i++)
853  free(T[i]);
854  free(T);
855  free(initguess);
856 }
void thomas_alg(double **T, double *initguess, double *app_evc, int iter)

Here is the call graph for this function:

Here is the caller graph for this function:

void thomas_alg ( double **  T,
double *  initguess,
double *  app_evc,
int  iter 
)

Definition at line 725 of file KNLanczosMethod.cpp.

Referenced by inverse_iter().

726 { //[completed]
727 
728  int i;
729  double temp, tbeta = T[0][0];
730 
731  double *P = (double *)malloc(sizeof(double)*iter);
732 
733  //Forward Elimination
734  for (i = 0; i<iter - 1; i++)
735  {
736  if (fabs(T[1][i])>fabs(tbeta))
737  {
738  initguess[i + 1] -= initguess[i] * tbeta / T[1][i];
739  T[1][i + 1] -= T[0][i] * tbeta / T[1][i];
740  P[i] = 0;
741  tbeta = T[0][i + 1];
742  }
743  else
744  {
745  temp = initguess[i + 1];
746  initguess[i + 1] = initguess[i];
747  initguess[i] = temp;
748 
749  temp = T[1][i + 1];
750  T[1][i + 1] = T[0][i];
751  T[0][i] = temp;
752 
753  initguess[i + 1] -= initguess[i] * T[1][i] / tbeta;
754 
755  T[1][i + 1] -= T[0][i] * T[1][i] / tbeta;
756 
757  if (i != iter - 2)
758  {
759  P[i] = T[0][i + 1];
760  T[0][i + 1] = -P[i] * T[1][i] / tbeta;
761  }
762 
763  T[1][i] = tbeta;
764 
765  if (i != iter - 2)
766  tbeta = P[i];
767  }
768  }
769 
770  //Backward Substitution
771  for (i = iter - 1; i>-1; i--)
772  {
773  if (i == iter - 1)
774  app_evc[i] = initguess[i] / T[1][i];
775  else if (i == iter - 2)
776  {
777  app_evc[i] = initguess[i] - app_evc[i + 1] * T[0][i];
778  app_evc[i] = app_evc[i] / T[1][i];
779  }
780  else
781  {
782  app_evc[i] = initguess[i] - app_evc[i + 1] * T[0][i] - app_evc[i + 2] * P[i];
783  app_evc[i] = app_evc[i] / T[1][i];
784  }
785  }
786 
787  free(P);
788 }

Here is the caller graph for this function:

Variable Documentation

unsigned int X_largest