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

This class includes functions for matrix debugging. More...

#include "KNMatrixDebug.h"

Collaboration diagram for CKNMatrixDebug:
Collaboration graph

Public Member Functions

 CKNMatrixDebug ()
 
 ~CKNMatrixDebug ()
 

Static Public Member Functions

static void ShowDoubleMatrix (double *pMatrix, int m, int n, int startm, int endm, int startn, int endn, char *pszDebugMsg)
 Show matrix in output debugging windows - Visual studio and Windows DebugView only. More...
 
static void ShowDoubleArray (double *vector, char *pszDebugMsg, int due)
 Show double array. More...
 
static void ShowDoubleVector (CKNMatrixOperation::CKNVector vector, char *pszDebugMsg, int due=-1)
 
static void ShowComplex (CKNComplex number, char *pszDebugMsg)
 Show vector class. More...
 
static void ShowDouble (double number, char *pszDebugMsg)
 Show one double data. More...
 
static void ShowMsg (char *pszBuffer)
 Show message. More...
 
static void SaveResult (CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, int nIndex)
 Show lanczos method result. More...
 
static void SetShow (bool bShow)
 
static void ShowCSR (CKNMatrixOperation::CKNCSR *pCSR, char *pszDebugMsg)
 Set show message or not. More...
 
static void ShowCSR (CKNMatrixOperation::CKNCSR *pCSR, int startm, int endm, int startn, int endn, char *pszDebugMsg)
 Show CSR matrix partialy. More...
 
static void ShowDenseMatrix (CKNMatrixOperation::CKNDMatrix *pMatrix, int startm, int endm, int startn, int endn, char *pszDebugMsg, bool bLineFeed=false, bool bShowImaginary=false)
 Show matrix partialy. More...
 
static void DumpCSR (CKNMatrixOperation::CKNCSR *pCSR, char *pszFileName, double fAtomIDStartIndex)
 Dump CSR to text file. More...
 
static void DumpCSRBinary (CKNMatrixOperation::CKNCSR *pCSR, char *pszFileName, double fAtomIDStartIndex)
 Dump CSR to binary file. More...
 

Static Private Attributes

static bool m_bShowMsg = false
 

Detailed Description

This class includes functions for matrix debugging.

Date
10/July/2014
Author
Kyu Nam Cho(mysto.nosp@m.us@k.nosp@m.orea..nosp@m.ac.k.nosp@m.r), Hoo Ryu(elec1.nosp@m.020@.nosp@m.gmail.nosp@m..com)

Definition at line 17 of file KNMatrixDebug.h.

Constructor & Destructor Documentation

CKNMatrixDebug::CKNMatrixDebug ( )

Definition at line 24 of file KNMatrixDebug.cpp.

25 {
26 }
CKNMatrixDebug::~CKNMatrixDebug ( )

Definition at line 28 of file KNMatrixDebug.cpp.

29 {
30 }

Member Function Documentation

void CKNMatrixDebug::DumpCSR ( CKNMatrixOperation::CKNCSR pCSR,
char *  pszFileName,
double  fAtomIDStartIndex 
)
static

Dump CSR to text file.

Definition at line 340 of file KNMatrixDebug.cpp.

References CKNMPIManager::GetCurrentRank(), CKNMatrixOperation::CKNCSR::GetRowCount(), CKNMPIManager::GetTotalNodeCount(), CKNMPIManager::IsRootRank(), CKNMatrixOperation::CKNCSR::m_vectColumn, CKNMatrixOperation::CKNCSR::m_vectRow, CKNMPIManager::ReceiveDoubleBufferSync(), and CKNMPIManager::SendDoubleBufferSync().

341 {
342  unsigned int i, j, nSize;
343  FILE *out;
344  char szMsg[1024];
345  char szFileName[1024];
346 
347 #ifdef _WIN32
348  _mkdir("result");
349  sprintf(szFileName, "result\\%s", pszFileName);
350 #else
351  mkdir("result", 0777);
352  sprintf(szFileName, "result/%s", pszFileName);
353 #endif
354 
355 #ifdef DISABLE_MPI_ROUTINE
356  out = fopen(szFileName, "wt");
357 #else //DISABLE_MPI_ROUTINE
358  MPI_Request req;
359  double fTemp = 1;
360 
362  out = fopen(szFileName, "wt");
363  else
364  {
366  out = fopen(szFileName, "at");
367  }
368 #endif //DISABLE_MPI_ROUTINE
369 
370  if( NULL == out )
371  return;
372 
373  nSize = pCSR->GetRowCount();
374  for(i = 0; i < nSize ; ++ i)
375  {
376  unsigned int nSubStart = pCSR->m_vectRow[i], nSubEnd = pCSR->m_vectRow[i + 1];
377 
378  for (j = nSubStart; j < nSubEnd; ++ j)
379  {
380  sprintf(szMsg, "%05d\t%05d\t%40.30f\t%40.30f\n", i + (int)(fAtomIDStartIndex*10) + 1,
381  pCSR->m_vectColumn[j] + 1,
382  pCSR->m_vectValueBuffer[j].GetRealNumber(),
383  pCSR->m_vectValueBuffer[j].GetImaginaryNumber());
384  fputs(szMsg, out);
385  }
386  }
387  fclose(out);
388 
389 #ifndef DISABLE_MPI_ROUTINE
392 #endif //DISABLE_MPI_ROUTINE
393 }
static int GetTotalNodeCount()
Definition: KNMPIManager.h:44
uint_vector_t m_vectColumn
A member variable for saving column information.
static int GetCurrentRank()
Definition: KNMPIManager.h:42
static bool IsRootRank()
Get Total node count.
uint_vector_t m_vectRow
A member variable for saving row information.
static void SendDoubleBufferSync(int nTargetRank, double *pBuffer, int nSize, MPI_Request *req, MPI_Comm commWorld=MPI_COMM_NULL)
Sending buffer for double data array with sync.
static void ReceiveDoubleBufferSync(int nSourceRank, double *pBuffer, int nSize, MPI_Request *req, MPI_Comm commWorld=MPI_COMM_NULL)
Receivinging buffer for double data array with sync.

Here is the call graph for this function:

void CKNMatrixDebug::DumpCSRBinary ( CKNMatrixOperation::CKNCSR pCSR,
char *  pszFileName,
double  fAtomIDStartIndex 
)
static

Dump CSR to binary file.

Definition at line 292 of file KNMatrixDebug.cpp.

References CKNMPIManager::GetCurrentRank(), CKNMatrixOperation::CKNCSR::GetRowCount(), CKNMPIManager::GetTotalNodeCount(), CKNMPIManager::IsRootRank(), CKNMatrixOperation::CKNCSR::m_vectColumn, CKNMatrixOperation::CKNCSR::m_vectRow, CKNMPIManager::ReceiveDoubleBufferSync(), and CKNMPIManager::SendDoubleBufferSync().

293 {
294  unsigned int i, j, nSize;
295  FILE *out;
296 
297 #ifdef DISABLE_MPI_ROUTINE
298  out = fopen(pszFileName, "wb");
299 #else //DISABLE_MPI_ROUTINE
300  MPI_Request req;
301  double fTemp = 1;
302 
304  out = fopen(pszFileName, "wb");
305  else
306  {
308  out = fopen(pszFileName, "ab");
309  }
310 #endif //DISABLE_MPI_ROUTINE
311 
312  if (NULL == out)
313  return;
314 
315  nSize = pCSR->GetRowCount();
316  for (i = 0; i < nSize; ++i)
317  {
318  unsigned int nSubStart = pCSR->m_vectRow[i], nSubEnd = pCSR->m_vectRow[i + 1];
319 
320  for (j = nSubStart; j < nSubEnd; ++j)
321  {
322  double fTemp;
323  int nTemp = i + (int)(fAtomIDStartIndex * 10);
324  fwrite(&nTemp, sizeof(int), 1, out);
325  fwrite(&pCSR->m_vectColumn[j], sizeof(int), 1, out);
326  fTemp = pCSR->m_vectValueBuffer[j].GetRealNumber();
327  fwrite(&fTemp, sizeof(double), 1, out);
328  fTemp = pCSR->m_vectValueBuffer[j].GetImaginaryNumber();
329  fwrite(&fTemp, sizeof(double), 1, out);
330  }
331  }
332  fclose(out);
333 
334 #ifndef DISABLE_MPI_ROUTINE
337 #endif //DISABLE_MPI_ROUTINE
338 }
static int GetTotalNodeCount()
Definition: KNMPIManager.h:44
uint_vector_t m_vectColumn
A member variable for saving column information.
static int GetCurrentRank()
Definition: KNMPIManager.h:42
static bool IsRootRank()
Get Total node count.
uint_vector_t m_vectRow
A member variable for saving row information.
static void SendDoubleBufferSync(int nTargetRank, double *pBuffer, int nSize, MPI_Request *req, MPI_Comm commWorld=MPI_COMM_NULL)
Sending buffer for double data array with sync.
static void ReceiveDoubleBufferSync(int nSourceRank, double *pBuffer, int nSize, MPI_Request *req, MPI_Comm commWorld=MPI_COMM_NULL)
Receivinging buffer for double data array with sync.

Here is the call graph for this function:

void CKNMatrixDebug::SaveResult ( CKNLanczosMethod::LPEIGENVALUE_RESULT  lpResult,
int  nIndex 
)
static

Show lanczos method result.

Parameters
lpResultCalculated eigenvalue result
nIndexThe index that want to save result

Definition at line 274 of file KNMatrixDebug.cpp.

References CKNLanczosMethod::EIGENVALUE_RESULT::nEigenValueCount, and CKNLanczosMethod::EIGENVALUE_RESULT::pEigenValues.

Referenced by CKNLanczosTest::TestLanczos().

275 {
276  char szBuffer[1024];
277  FILE *fpResult;
278  unsigned int i;
279 
280  sprintf(szBuffer, "lanczosresult_%d.txt", nIndex);
281  if (NULL != (fpResult = fopen(szBuffer, "wt")))
282  {
283  for (i = 0; i < lpResult->nEigenValueCount; i++)
284  {
285  sprintf(szBuffer, "%f\n", lpResult->pEigenValues[i]);
286  fputs(szBuffer, fpResult);
287  }
288  fclose(fpResult);
289  }
290 }

Here is the caller graph for this function:

static void CKNMatrixDebug::SetShow ( bool  bShow)
inlinestatic

Definition at line 30 of file KNMatrixDebug.h.

References m_bShowMsg.

30 { m_bShowMsg = bShow; };
static bool m_bShowMsg
Definition: KNMatrixDebug.h:38
void CKNMatrixDebug::ShowComplex ( CKNComplex  number,
char *  pszDebugMsg 
)
static

Show vector class.

Show complex class

Parameters
numberThe complex number that was wanted to show
pszDebugMsgText that was show first at matrix display

Definition at line 244 of file KNMatrixDebug.cpp.

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

245 {
246  char szDebug[1024];
247 
248  sprintf(szDebug, " %20.20f + %20.20f i\n", number.GetRealNumber(), number.GetImaginaryNumber());
249 
250  ShowMsg(pszDebugMsg);
251  ShowMsg("\n");
252  ShowMsg(szDebug);
253 }
double GetImaginaryNumber() const
Get imaginary part.
Definition: KNComplex.h:27
double GetRealNumber() const
Get real part.
Definition: KNComplex.h:26
static void ShowMsg(char *pszBuffer)
Show message.

Here is the call graph for this function:

void CKNMatrixDebug::ShowCSR ( CKNMatrixOperation::CKNCSR pCSR,
char *  pszDebugMsg 
)
static

Set show message or not.

Show CSR matrix partialy

Parameters
pCSRThe matrix that was wanted to show
pszDebugMsgText that was show first at matrix display

Definition at line 159 of file KNMatrixDebug.cpp.

References DUMY_STRING_FOR_COMPLEX_SHOWING, CKNMatrixOperation::CKNCSR::GetColumnCount(), CKNMatrixOperation::CKNCSR::GetElement(), CKNComplex::GetImaginaryNumber(), CKNComplex::GetRealNumber(), and CKNMatrixOperation::CKNCSR::GetRowCount().

Referenced by CKNLanczosTest::TestCSRBuilding().

160 {
161  bool bExisted;
162  unsigned int iMax, jMax;
163 
164 #ifdef _WIN32
165  iMax = min(10, pCSR->GetRowCount());
166  jMax = min(10, pCSR->GetColumnCount());
167 #else
168  iMax = std::min(10, (int)pCSR->GetRowCount());
169  jMax = std::min(10, (int)pCSR->GetColumnCount());
170 #endif
171 
172  ShowMsg(pszDebugMsg);
173  ShowMsg("\n");
174  ShowMsg("\n");
175 
176  for (unsigned int i = 0; i < iMax; i++)
177  {
178  char szRow[1024] = "";
179  for (unsigned int j = 0; j < jMax; j++)
180  {
181  char szCol[1024];
182  CKNComplex element = pCSR->GetElement(i, j, bExisted);
183 
184  if (bExisted)
185  sprintf(szCol, "%3.3f:%3.3f |\t\t", element.GetRealNumber(), element.GetImaginaryNumber());
186  else
187  sprintf(szCol, "%s |\t\t", DUMY_STRING_FOR_COMPLEX_SHOWING);
188  strcat(szRow, szCol);
189  }
190  strcat(szRow, "\n");
191  ShowMsg(szRow);
192  }
193 }
double GetImaginaryNumber() const
Get imaginary part.
Definition: KNComplex.h:27
double GetRealNumber() const
Get real part.
Definition: KNComplex.h:26
unsigned int GetColumnCount()
Getting row size of matrix.
static void ShowMsg(char *pszBuffer)
Show message.
CKNComplex GetElement(unsigned int nRow, unsigned int nColumn, bool &bResult)
Get Element by index.
This class for complex operation and saving value.
Definition: KNComplex.h:18
#define DUMY_STRING_FOR_COMPLEX_SHOWING

Here is the call graph for this function:

Here is the caller graph for this function:

void CKNMatrixDebug::ShowCSR ( CKNMatrixOperation::CKNCSR pCSR,
int  startm,
int  endm,
int  startn,
int  endn,
char *  pszDebugMsg 
)
static

Show CSR matrix partialy.

Parameters
pCSRThe matrix that was wanted to show
pszDebugMsgText that was show first at matrix display
startmStart row index that was wanted to show
endmEnd row index that was wanted to show
startnStart column index that was wanted to show
endnEnd column index that was wanted to show

Definition at line 128 of file KNMatrixDebug.cpp.

References DUMY_STRING_FOR_COMPLEX_SHOWING, CKNMatrixOperation::CKNCSR::GetElement(), CKNComplex::GetImaginaryNumber(), and CKNComplex::GetRealNumber().

129 {
130  bool bExisted;
131 
132  ShowMsg(pszDebugMsg);
133  ShowMsg("\n");
134  ShowMsg("\n");
135 
136  for (unsigned int i = startm; i <= (unsigned int)endm; i++)
137  {
138  char szRow[1024] = "";
139  for (unsigned int j = startn; j <= (unsigned int)endn; j++)
140  {
141  char szCol[1024];
142  CKNComplex element = pCSR->GetElement(i, j, bExisted);
143 
144  if (bExisted)
145  sprintf(szCol, "%3.3f:%3.3f |\t\t", element.GetRealNumber(), element.GetImaginaryNumber());
146  else
147  sprintf(szCol, "%s |\t\t", DUMY_STRING_FOR_COMPLEX_SHOWING);
148  strcat(szRow, szCol);
149  }
150  strcat(szRow, "\n");
151  ShowMsg(szRow);
152  }
153 }
double GetImaginaryNumber() const
Get imaginary part.
Definition: KNComplex.h:27
double GetRealNumber() const
Get real part.
Definition: KNComplex.h:26
static void ShowMsg(char *pszBuffer)
Show message.
CKNComplex GetElement(unsigned int nRow, unsigned int nColumn, bool &bResult)
Get Element by index.
This class for complex operation and saving value.
Definition: KNComplex.h:18
#define DUMY_STRING_FOR_COMPLEX_SHOWING

Here is the call graph for this function:

void CKNMatrixDebug::ShowDenseMatrix ( CKNMatrixOperation::CKNDMatrix pMatrix,
int  startm,
int  endm,
int  startn,
int  endn,
char *  pszDebugMsg,
bool  bLineFeed = false,
bool  bShowImaginary = false 
)
static

Show matrix partialy.

Parameters
pMatrixThe matrix that was wanted to show
startmStart row index that was wanted to show
endmEnd row index that was wanted to show
startnStart column index that was wanted to show
endnEnd column index that was wanted to show
pszDebugMsgText that was show first at matrix display
bLineFeedHas linefeed between row or not
bShowImaginaryDetermine show imaginary part or not

Definition at line 90 of file KNMatrixDebug.cpp.

References CKNMatrixOperation::CKNDMatrix::GetElement(), CKNComplex::GetImaginaryNumber(), and CKNComplex::GetRealNumber().

91 {
92  ShowMsg(pszDebugMsg);
93  ShowMsg("\n");
94  ShowMsg("\n");
95 
96  for (int i = startm; i <= endm; i++)
97  {
98  char szRow[1024] = "";
99  for (int j = startn; j <= endn; j++)
100  {
101  char szCol[1024];
102  CKNComplex temppNumber = pMatrix->GetElement(i, j);
103 
104  sprintf(szCol, "%10.10f ", temppNumber.GetRealNumber());
105  strcat(szRow, szCol);
106  if (bShowImaginary)
107  {
108  sprintf(szCol, "+ %10.10f i ", temppNumber.GetImaginaryNumber());
109  strcat(szRow, szCol);
110  }
111  strcat(szRow, "\t");
112  }
113  if (bLineFeed)
114  strcat(szRow, "\n");
115  strcat(szRow, "\n");
116  ShowMsg(szRow);
117  }
118 }
double GetImaginaryNumber() const
Get imaginary part.
Definition: KNComplex.h:27
double GetRealNumber() const
Get real part.
Definition: KNComplex.h:26
static void ShowMsg(char *pszBuffer)
Show message.
CKNComplex GetElement(unsigned int nRowIndex, unsigned int nColumnIndex)
Get matrix element with row, column index.
This class for complex operation and saving value.
Definition: KNComplex.h:18

Here is the call graph for this function:

void CKNMatrixDebug::ShowDouble ( double  number,
char *  pszDebugMsg 
)
static

Show one double data.

Parameters
numberThe number that was wanted to show
pszDebugMsgText that was show first at matrix display

Definition at line 259 of file KNMatrixDebug.cpp.

260 {
261  char szDebug[1024];
262 
263  sprintf(szDebug, " %20.20f \n", number);
264 
265  ShowMsg(pszDebugMsg);
266  ShowMsg("\n");
267  ShowMsg(szDebug);
268 }
static void ShowMsg(char *pszBuffer)
Show message.
void CKNMatrixDebug::ShowDoubleArray ( double *  vector,
char *  pszDebugMsg,
int  due 
)
static

Show double array.

Parameters
vectorThe vector that was wanted to show
pszDebugMsgText that was show first at matrix display
dueDebugger show vector element unti this index

Definition at line 200 of file KNMatrixDebug.cpp.

201 {
202  char szDebug[1024] = "";
203  int i;
204 
205  ShowMsg(pszDebugMsg);
206  ShowMsg("\n");
207 
208  for (i = 0; i < due; i++)
209  {
210  sprintf(szDebug, "%5d: %20.20f\n", i, vector[i]);
211  ShowMsg(szDebug);
212  }
213 }
static void ShowMsg(char *pszBuffer)
Show message.
void CKNMatrixDebug::ShowDoubleMatrix ( double *  pMatrix,
int  m,
int  n,
int  startm,
int  endm,
int  startn,
int  endn,
char *  pszDebugMsg 
)
static

Show matrix in output debugging windows - Visual studio and Windows DebugView only.

Parameters
pMatrixThe matrix that was wanted to show
mNumbers of row
nNumbers of column
startmStart row index that was wanted to show
endmEnd row index that was wanted to show
startnStart column index that was wanted to show
endnEnd column index that was wanted to show
pszDebugMsgText that was show first at matrix display

Definition at line 60 of file KNMatrixDebug.cpp.

61 {
62  ShowMsg(pszDebugMsg);
63  ShowMsg("\n");
64  ShowMsg("\n");
65 
66  for (int i = startm; i < endm; i++)
67  {
68  char szRow[1024] = "";
69  for (int j = startn; j < endn; j++)
70  {
71  char szCol[1024];
72 
73  sprintf(szCol, "%20.20f ", pMatrix[i*m + j]);
74  strcat(szRow, szCol);
75  }
76  strcat(szRow, "\n");
77  ShowMsg(szRow);
78  }
79 }
static void ShowMsg(char *pszBuffer)
Show message.
void CKNMatrixDebug::ShowDoubleVector ( CKNMatrixOperation::CKNVector  vector,
char *  pszDebugMsg,
int  due = -1 
)
static
Parameters
vectorThe vector that was wanted to show
pszDebugMsgText that was show first at matrix display
dueDebugger show vector element unti this index

Definition at line 220 of file KNMatrixDebug.cpp.

References CKNMatrixOperation::CKNVector::GetAt(), CKNComplex::GetImaginaryNumber(), CKNComplex::GetRealNumber(), and CKNMatrixOperation::CKNVector::GetSize().

221 {
222  char szDebug[1024] = "";
223  int i, nSize;
224 
225  if (-1 == due)
226  nSize = vector.GetSize();
227  else
228  nSize = due;
229 
230  ShowMsg(pszDebugMsg);
231  ShowMsg("\n");
232 
233  for (i = 0; i < nSize; i++)
234  {
235  sprintf(szDebug, "%5d: %20.20f + %20.20f i\n", i, vector.GetAt(i).GetRealNumber(), vector.GetAt(i).GetImaginaryNumber());
236  ShowMsg(szDebug);
237  }
238 }
double GetImaginaryNumber() const
Get imaginary part.
Definition: KNComplex.h:27
double GetRealNumber() const
Get real part.
Definition: KNComplex.h:26
CKNComplex GetAt(unsigned int nIndex)
Get element value from specific index.
static void ShowMsg(char *pszBuffer)
Show message.
unsigned int GetSize()
Return Vector elements size.

Here is the call graph for this function:

void CKNMatrixDebug::ShowMsg ( char *  pszBuffer)
static

Show message.

Parameters
pszBufferShowing message

Definition at line 35 of file KNMatrixDebug.cpp.

Referenced by CKNLanczosTest::AuditResult(), CKNLanczosTest::AuditResult_EV(), CKNLanczosTest::AuditResult_Seorth(), CKNLanczosTest::AuditResult_WF(), CKNLanczosTest::CompareWithMatLabSeOrth(), CKNLanczosTest::COmpareWIthMatLabSeOrthMPI(), CKNLanczosTest::LanczosThread(), CKNLanczosTest::LanczosThreadForMPI(), CKNLanczosTest::LargeSizeMatrixMPI(), CKNGeometricConstructionLaunch::LaunchingGeometricConstructionMPI(), CKNLanczosTest::SolvingLargeSizeHamlitonian(), CKNLanczosTest::TestCSRBuilding(), CKNLanczosTest::TestLanczos(), and CKNLanczosTest::TestSimpleLanczos().

36 {
37  if (false == m_bShowMsg)
38  return;
39 #ifdef _WIN32
40 #if _MFC_VER == 0x0C00
41  OutputDebugStringA(pszBuffer);
42 #else// _MFC_VER == 0x0C00
43  printf("%s", pszBuffer);
44 #endif //_MFC_VER == 0x0C00
45 #else
46  printf("%s", pszBuffer);
47 #endif
48 }
static bool m_bShowMsg
Definition: KNMatrixDebug.h:38

Here is the caller graph for this function:

Member Data Documentation

bool CKNMatrixDebug::m_bShowMsg = false
staticprivate

Definition at line 38 of file KNMatrixDebug.h.

Referenced by SetShow().


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