20 #define TEMP_MATRIX_ORDER 2000
21 #define LARGE_MATRIX_READ_COUNT 44002932
22 #define LARGE_MATRIX_ORDER 1105920
23 #ifdef _MFC_VER == 0x0C00
24 #define MATLAB_SEORTH_RESULT_FILE "D:\\git\\data\\sereoth.dat"
25 #define LARGE_SIZE_MATRIX_FILE "D:\\git\\data\\Hamiltonian_sort1.dat"
27 #define MATLAB_SEORTH_RESULT_FILE "./data/sereoth.dat"
28 #define LARGE_SIZE_MATRIX_FILE "./data/Hamiltonian_sort1.dat"
34 #if _MFC_VER == 0x0C00
35 CWinThread *CKNLanczosTest::m_pLanczosThread = NULL;
36 #endif //#if _MFC_VER == 0x0C00
64 double fSparseRowDataReal[36] = { 10, 0, 0, 0., -2, 0.,
71 double fSparseRowDataImaginary[36] = { 1, 0, 0, 0., 4, 0.,
72 3., 1, 0, 1.0, 0., 45,
75 1., 8.3, 0, 1., 10, 3.1,
76 0, 5.2, 0, 0, -22, -100 };
85 FILE *fMatlabFile = NULL;
86 double *pfSparseRowData = NULL;
87 double *pfSparseRowData_i = NULL;
90 double *pfRow = NULL, *pfColumn = NULL, *pfReal = NULL, *pfImginary = NULL;
95 if (NULL != (fMatlabFile = fopen(pszFileName,
"rb")))
99 pfSparseRowData = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
102 pfSparseRowData_i = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
105 pfRow = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
108 pfColumn = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
111 pfReal = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
114 pfImginary = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
117 memset(pfSparseRowData, 0,
sizeof(
double)* nMatrixSize * nMatrixSize);
118 memset(pfSparseRowData_i, 0,
sizeof(
double)* nMatrixSize * nMatrixSize);
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);
126 fseek(fMatlabFile, 0L, SEEK_END);
127 int fileLen = ftell(fMatlabFile);
128 fseek(fMatlabFile, 0L, SEEK_SET);
130 int nCount = fileLen / (
sizeof(double)* 4);
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);
142 for (i = 0; i < nCount; i++)
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];
163 int nReadRowSize = nMatrixSize;
176 pfSparseRowData_i + nStartPos * nMatrixSize, nReadRowSize, nMatrixSize);
178 if (NULL != pfSparseRowData)
180 free(pfSparseRowData);
181 pfSparseRowData = NULL;
184 if (NULL != pfSparseRowData_i)
186 free(pfSparseRowData_i);
187 pfSparseRowData_i = NULL;
197 FILE *fMatlabFile = NULL;
198 double *pfSparseRowData = NULL;
199 double *pfSparseRowData_i = NULL;
202 double *pfRow = NULL, *pfColumn = NULL, *pfReal = NULL, *pfImginary = NULL;
207 if (NULL != (fMatlabFile = fopen(pszFileName,
"rb")))
211 pfSparseRowData = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
214 pfSparseRowData_i = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
217 pfRow = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
220 pfColumn = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
223 pfReal = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
226 pfImginary = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
229 memset(pfSparseRowData, 0,
sizeof(
double)* nMatrixSize * nMatrixSize);
230 memset(pfSparseRowData_i, 0,
sizeof(
double)* nMatrixSize * nMatrixSize);
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);
238 fseek(fMatlabFile, 0L, SEEK_END);
239 int fileLen = ftell(fMatlabFile);
240 fseek(fMatlabFile, 0L, SEEK_SET);
242 int nCount = fileLen / (
sizeof(double)* 4);
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);
254 for (i = 0; i < nCount; i++)
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];
275 int nReadRowSize = nMatrixSize;
278 unsigned int nRowStart = 0, nRowEnd;
285 pCSR = pCSRTotal->
SplitCSR(nRowStart, nRowEnd);
288 if (NULL != pfSparseRowData)
290 free(pfSparseRowData);
291 pfSparseRowData = NULL;
294 if (NULL != pfSparseRowData_i)
296 free(pfSparseRowData_i);
297 pfSparseRowData_i = NULL;
309 FILE *fDataFile = NULL;
312 fDataFile = fopen(pszFileName,
"rb");
313 if (NULL != fDataFile)
337 if (NULL == pA_Matrix)
343 lpResult = lanczos.
DoLanczosMethod(pA_Matrix, nIteration, nInterval, nEigCount, -0.1, 1.63, 1e-8, bSelect, bCalcuVector, bWaveFunction);
345 AuditResult_EV(pA_Matrix, lpResult, 1e-8);
351 catch (
unsigned long dwError)
370 FILE *fMatlabFile = NULL;
371 double *pfSparseRowData = NULL;
372 double *pfSparseRowData_i = NULL;
375 double *pfRow = NULL, *pfColumn = NULL, *pfReal = NULL, *pfImginary = NULL;
380 if (NULL != (fMatlabFile = fopen(pszFileName,
"rb")))
384 pfSparseRowData = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
387 pfSparseRowData_i = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
390 pfRow = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
393 pfColumn = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
396 pfReal = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
399 pfImginary = (
double*)malloc(
sizeof(
double)* nMatrixSize * nMatrixSize);
402 memset(pfSparseRowData, 0,
sizeof(
double)* nMatrixSize * nMatrixSize);
403 memset(pfSparseRowData_i, 0,
sizeof(
double)* nMatrixSize * nMatrixSize);
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);
411 fseek(fMatlabFile, 0L, SEEK_END);
412 int fileLen = ftell(fMatlabFile);
413 fseek(fMatlabFile, 0L, SEEK_SET);
415 int nCount = fileLen / (
sizeof(double)* 4);
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);
427 for (i = 0; i < nCount; i++)
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];
447 if (NULL != pfSparseRowData)
449 free(pfSparseRowData);
450 pfSparseRowData = NULL;
453 if (NULL != pfSparseRowData_i)
455 free(pfSparseRowData_i);
456 pfSparseRowData_i = NULL;
495 double fResult = VAX.
GetNorm();
496 if (fabs(fResult) < fTolerance)
499 sprintf(szBuffer,
"EV[%d] [AX - ramdaX: %20.20f] %s \n", i, fResult, bPass ?
"OK" :
"NG");
510 FILE *fpMatlabAnswer = NULL;
511 unsigned int nMatlabAnswerCount = 0;
514 double fMatlabAnswer[1024];
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;
523 if (NULL == lpResult)
530 fseek(fpMatlabAnswer, (10 *
sizeof(
double))*(nIndex - 1), SEEK_SET);
531 for (i = 0; i < 10; i++)
533 fread(&temp,
sizeof(
double), 1, fpMatlabAnswer);
534 if (temp >= fMin && temp <= fMax)
536 fMatlabAnswer[nMatlabAnswerCount++] = temp;
539 fclose(fpMatlabAnswer);
544 for (i = 0; i < (
unsigned int)min((
int)lpResult->
nEigenValueCount, (
int)nFindEigenValue); i++)
546 for (i = 0; i < (
unsigned int)std::min((
int)lpResult->
nEigenValueCount, (int)nFindEigenValue); i++)
550 for (j = 0; j < nMatlabAnswerCount; j++)
554 fCorrectAnwser[nCorrectAnwser++] = fMatlabAnswer[j];
561 fWrongAnwser[nWrongAnwser++] = lpResult->
pEigenValues[i];
564 for (i = 0; i < nMatlabAnswerCount; i++)
568 for (j = 0; j < (
unsigned int)min((
int)lpResult->
nEigenValueCount, (int)nFindEigenValue); j++)
570 for (j = 0; j < (
unsigned int)std::min((
int)lpResult->
nEigenValueCount, (int)nFindEigenValue); j++)
581 fMisAnswer[nMisAnswer++] = fMatlabAnswer[i];
585 sprintf(szBuffer,
"\n%d result(s)\n------------------------------\nFind eigenvalues: %d\nMiss eigenvalues: %d\nWrong eigenvalues: %d\n", nIndex, nCorrectAnwser, nMisAnswer, nWrongAnwser);
588 strcpy(szBuffer,
"\nFinding eigenvalues:\n");
589 for (i = 0; i < nCorrectAnwser; i++)
590 sprintf(szBuffer,
"%s%d: %f\n", szBuffer, i, fCorrectAnwser[i]);
595 strcpy(szBuffer,
"\nMissing eigenvalues:\n");
596 for (i = 0; i < nMisAnswer; i++)
597 sprintf(szBuffer,
"%s%d: %f\n", szBuffer, i, fMisAnswer[i]);
603 strcpy(szBuffer,
"\nWrong eigenvalues:\n");
604 for (i = 0; i < nWrongAnwser; i++)
605 sprintf(szBuffer,
"%s%d: %f\n", szBuffer, i, fWrongAnwser[i]);
607 sprintf(szBuffer,
"%s\n", szBuffer);
613 sprintf(szBuffer,
"Can't find audi file %s\n", szBuffer);
622 FILE *fpMatlabAnswer = NULL;
623 unsigned int nMatlabAnswerCount = 0;
625 double *pMatlabAnswer = (
double*)malloc(
sizeof(
double)*nFindEigenValue);
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;
634 if (NULL == pMatlabAnswer)
637 if (NULL == lpResult)
640 sprintf(szBuffer,
"data\\Matlab_result_%d_%d.dat", nFindEigenValue, nIndex);
641 if (NULL != (fpMatlabAnswer = fopen(szBuffer,
"rb")))
644 while (0 != fread(&temp,
sizeof(
double), 1, fpMatlabAnswer))
646 if (temp >= fMin && temp <= fMax)
647 pMatlabAnswer[nMatlabAnswerCount++] = temp;
649 fclose(fpMatlabAnswer);
653 for (i = 0; i < (
unsigned int)min((
int)lpResult->
nEigenValueCount, (
int)nFindEigenValue); i++)
655 for (i = 0; i < (
unsigned int)std::min((
int)lpResult->
nEigenValueCount, (int)nFindEigenValue); i++)
659 for (j = 0; j < nMatlabAnswerCount; j++)
663 fCorrectAnwser[nCorrectAnwser++] = pMatlabAnswer[j];
670 fWrongAnwser[nWrongAnwser++] = lpResult->
pEigenValues[i];
673 for (i = 0; i < nMatlabAnswerCount; i++)
677 for (j = 0; j < (
unsigned int)min((
int)lpResult->
nEigenValueCount, (int)nFindEigenValue); j++)
679 for (j = 0; j < (
unsigned int)std::min((
int)lpResult->
nEigenValueCount, (int)nFindEigenValue); j++)
690 fMisAnswer[nMisAnswer++] = pMatlabAnswer[i];
694 sprintf(szBuffer,
"\n%d result\n------------------------------\nFind eigenvalues: %d\nMiss eigenvalues: %d\nWrong eigenvalues: %d\n", nIndex, nCorrectAnwser, nMisAnswer, nWrongAnwser);
697 strcpy(szBuffer,
"\nFinding eigenvalues:\n");
698 for (i = 0; i < nCorrectAnwser; i++)
699 sprintf(szBuffer,
"%s%d: %f\n", szBuffer, i, fCorrectAnwser[i]);
704 strcpy(szBuffer,
"\nMissing eigenvalues:\n");
705 for (i = 0; i < nMisAnswer; i++)
706 sprintf(szBuffer,
"%s%d: %f\n", szBuffer, i, fMisAnswer[i]);
712 strcpy(szBuffer,
"\nWrong eigenvalues:\n");
713 for (i = 0; i < nWrongAnwser; i++)
714 sprintf(szBuffer,
"%s%d: %f\n", szBuffer, i, fWrongAnwser[i]);
716 sprintf(szBuffer,
"%s\n", szBuffer);
722 sprintf(szBuffer,
"Can't find audi file %s\n", szBuffer);
732 FILE *fpMatlabResult;
734 if (NULL != (fpMatlabResult = fopen(
"./data/Lanczosresult.csv",
"at")))
737 for (i = 1; i <= 41; i++)
739 char szBuffer[1000000] =
"";
741 if (NULL == pResult[i])
746 sprintf(szBuffer,
"%s,%20.20f", szBuffer, pResult[i]->pEigenValues[j]);
749 strcat(szBuffer,
"\n");
750 fputs(szBuffer, fpMatlabResult);
754 fclose(fpMatlabResult);
760 int nEigenValueCount = 0;
761 int nFindEigenvalueCount = 10;
769 for (
int i = 1; i <= 41; i++)
771 sprintf(szBuffer,
"\n\n-Start %dth Lanczos eigenvalues solver", i);
773 sprintf(szBuffer,
"./data/Matlab_%d.dat", i);
774 pA_Matrix = TestCSRBuildingViaFileLoad(szBuffer, 2000);
776 if (NULL == pA_Matrix)
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);
785 AuditResult_EV(pA_Matrix, lpResult, 1e-8);
792 catch (
unsigned long dwError)
811 char szFileName[1024];
814 int nFindEigenvalueCount = 10;
816 #ifdef _MFC_VER == 0x0C00
817 sprintf(szFileName,
"D:\\git\\data\\Matlab_%d.dat", nFileIndex);
819 sprintf(szFileName,
"./data/Matlab_%d.dat", nFileIndex);
824 MPI_Init(NULL, NULL);
827 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
830 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
835 #ifdef DOING_MEASUREMENT
839 pA_Matrix = TestCSRBuildingViaFileLoad_(szFileName, 2000);
840 lpResult = lanczos.
DoLanczosMethod(pA_Matrix, nIteration, nInterval, nEigCount, 1.2, 2.3, 1e-8, bSelect, bCalcuVector, bCalcuVector);
843 AuditResult_Seorth(nFileIndex, nFindEigenvalueCount, lpResult, 1.2, 2.3);
849 pA_Matrix = TestCSRBuildingViaFileLoadOrigin(szFileName, 2000);
850 AuditResult_EV(pA_Matrix, lpResult, 1e-8);
852 AuditResult_WF(lpResult, 1e-8, 200);
863 catch (
unsigned long dwError)
887 mkdir(
"result", 0777);
890 if( NULL != (out = fopen(
"result\\evaluation.txt",
"wt")))
892 if( NULL != (out = fopen(
"result/evaluation.txt",
"wt")))
897 sprintf(szTemp,
"%d,%f,%f,%f,%f,%f,%f\n",
912 if( NULL == lpResult)
917 char szFileName[1024], szBuffer[1024];
918 std::string writeString;
924 mkdir(
"result", 0777);
927 if( NULL != (out = fopen(
"result\\eigenvalues.txt",
"wt")))
929 if( NULL != (out = fopen(
"result/eigenvalues.txt",
"wt")))
934 sprintf(szBuffer,
"[ev %d] %18.16f\n", i, lpResult->
pEigenValues[i]);
935 fputs(szBuffer, out);
945 sprintf(szFileName,
"result\\eigenvector_%02d.txt", j);
947 sprintf(szFileName,
"result/eigenvector_%02d.txt", j);
950 if( NULL != (out = fopen(szFileName,
"wt")))
952 for( i = 0 ;i < nMatrixSize ; i ++ )
954 sprintf(szBuffer,
"%16.16f %16.16f\n",
958 writeString += szBuffer;
962 fputs(writeString.c_str(), out);
967 if( !writeString.empty() )
969 fputs(writeString.c_str(), out);
983 sprintf(szFileName,
"result\\wavefunction_%02d.txt", j);
985 sprintf(szFileName,
"result/wavefunction_%02d.txt", j);
988 if( NULL != (out = fopen(szFileName,
"wt")))
990 for( i = 0 ;i < nMatrixSize / 10 ; i ++ )
992 sprintf(szBuffer,
"%16.16f\n",
995 writeString += szBuffer;
999 fputs(writeString.c_str(), out);
1000 writeString.clear();
1004 if( !writeString.empty() )
1006 fputs(writeString.c_str(), out);
1007 writeString.clear();
1021 char szBuffer[1024];
1035 for( j = 0 ; j < nWaveFunctionSize; j ++ )
1040 if (fabs(1-tempResult.
GetNorm()) < fTolerance)
1043 sprintf(szBuffer,
"WaveFunction[%d] sum: [ %20.20f ] %s\n", i, tempResult.
GetNorm(), bPass ?
"OK" :
"NG");
1054 int nFindEigenvalueCount = 10;
1056 unsigned int nRowStart = 0, nRowEnd, i;
1060 MPI_Init(NULL, NULL);
1063 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
1066 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
1082 pA_Matrix = pCSRTotal->
SplitCSR(nRowStart, nRowEnd);
1088 if (NULL == pA_Matrix)
1099 lpResult = lanczos.
DoLanczosMethod(pA_Matrix, nIteration, nInterval, nEigCount, -0.1, 1.63, 1e-8, bSelect, bCalcuVector, bWaveFunction);
1103 SaveResult(lpResult, nRowCount, bCalcuVector, bWaveFunction);
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",
1125 sprintf(szMsg,
"[ev %d] %18.16f\n", i, lpResult->
pEigenValues[i]);
1133 AuditResult_WF(lpResult, 1e-8, nRowCount/10);
1141 AuditResult_EV(pA_Matrix, lpResult, 1e-8);
1153 catch (
unsigned long dwError)
1171 #if _MFC_VER == 0x0C00
1173 #else //_MFC_VER == 0x0C00
1175 #endif //_MFC_VER == 0x0C00
1181 int nEigenValueCount = 0;
1182 int nFindEigenvalueCount = 10;
1191 if (NULL == pA_Matrix)
1200 AuditResult_Seorth(1, nFindEigenvalueCount, lpResult, 1.2, 2.3);
1208 catch (
unsigned long dwError)
1227 #if _MFC_VER == 0x0C00
1228 m_pLanczosThread = NULL;
1232 #endif //_MFC_VER == 0x0C00
1249 #if _MFC_VER == 0x0C00
1251 #endif /_MFC_VER == 0x0C00
1257 #if _MFC_VER == 0x0C00
1259 #else //_MFC_VER == 0x0C00
1261 #endif //_MFC_VER == 0x0C00
1267 int nEigenValueCount = 0;
1268 int nFindEigenvalueCount = 10;
1274 char szBuffer[1024];
1279 for (
int i = 1; i <= 1; i++)
1281 sprintf(szBuffer,
"\n\n-Start %dth Lanczos eigenvalues solver", i);
1283 sprintf(szBuffer,
"./data/Matlab_%d.dat", i);
1285 pA_Matrix = TestCSRBuildingViaFileLoad(szBuffer, 2000);
1287 if (NULL == pA_Matrix)
1295 AuditResult_Seorth(i, nFindEigenvalueCount, lpResult, 1.2, 2.3);
1297 AuditResult_EV(pA_Matrix, lpResult, 1e-8);
1312 catch (
unsigned long dwError)
1332 #if _MFC_VER == 0x0C00
1333 m_pLanczosThread = NULL;
1337 #endif //_MFC_VER == 0x0C00
1346 int nEigenValueCount = 0;
1347 int nFindEigenvalueCount = 60;
1353 FILE *fpMatlabResult;
1355 fpMatlabResult = fopen(
"./data/Lanczosresult.csv",
"w");
1356 fclose(fpMatlabResult);
1358 if (NULL != (fpMatlabResult = fopen(
"./data/Lanczosresult.csv",
"at")))
1360 char szBuffer[1024];
1362 for (
int i = 1; i <= 41; i++)
1364 char szBuffer2[10240] =
"";
1366 sprintf(szBuffer,
"\n\n%dth -Start Lanczos eigenvalue solver\n", i);
1368 sprintf(szBuffer,
"data\\Matlab_%d.dat", i);
1369 pA_Matrix = TestCSRBuildingViaFileLoad(szBuffer, 2000);
1372 lpResult = lanczos.
DoLanczosMethod(pA_Matrix, nIteration, nInterval, nEigCount, 1.2, 2.3, 1e-8,
false, bCalcuVector,
false);
1377 sprintf(szBuffer2,
"%d,", i);
1380 sprintf(szBuffer2,
"%s,%20.20f", szBuffer2, lpResult->
pEigenValues[j]);
1383 strcat(szBuffer2,
"\n");
1384 fputs(szBuffer2, fpMatlabResult);
1393 fclose(fpMatlabResult);
1397 catch (
unsigned long dwError)
1417 int nEigenValueCount = 0;
1422 pA_Matrix = TestCSRBuildingViaArray();
1425 lpResult = lanczos.
DoLanczosMethod(pA_Matrix, 6, 6, 1, 1.2, 2.3, 1e-8,
false,
false,
false);
1430 catch (
unsigned long dwError)
1455 pCSR = TestCSRBuildingViaArray();
1472 pCSR->
SetAt(number, 2, 2);
1476 pCSR->
SetAt(number, 3, 5);
1486 pCSR->
SetAt(number, 7, 7);
1494 catch (
unsigned long dwError)
1514 if (NULL != m_pCurrentLanczosInstance)
1515 m_pCurrentLanczosInstance->StopIteration();
struct _tag LANCZOS_PARAM
static void CompareWithMatLabSeOrth(int nIteration, int nInterval, int nEigCount, bool bSelect, bool bCalcuVector)
void DumpResult(CKNLanczosMethod::LPEIGENVALUE_RESULT *pResult)
void SetSize(unsigned int nSize)
Set Vector elements size.
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
double GetImaginaryNumber() const
Get imaginary part.
static CKNMatrixOperation::CKNCSR * LargeCSRBuildingViaFileForMPI(char *pszFileName, int nMatrixSize)
static void FinalizeManager()
Get Root rank.
void ScalarMultiple(CKNComplex Scalar)
Scalar multiple operation.
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.
bool InsertRowAtEnd()
Insert row after last row.
static void TestLanczos(int nIteration, int nInterval, int nEigCount, bool bCalcuVector)
static void StopLanczos()
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaFileLoadOrigin(char *pszFileName, int nMatrixSize)
Show message and debugging variable.
double GetRealNumber() const
Get real part.
CKNMatrixOperation::CKNVector * pEigenVectorsForAMatrix
static CKNMatrixOperation::CKNCSR * BuildCSRFromFileTemp(FILE *fDataFile, unsigned int nRowOrder, unsigned int nColumnOrder, int nDataCount)
Building CSR from file using double, double, double, double order.
unsigned int GetColumnCount()
Getting row size of matrix.
Data and operation representation of CSR(Compressed Sparse Row)
static int GetCurrentLoadBalanceCount()
Get Current node's rank load balancing number.
static void MeasurementEnd(MEASUREMENT_INDEX index)
Measurement end for part.
This class for doing Lanczos method.
void * LanczosThread(void *pParam)
static void SaveResult(CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, int nIndex)
Show lanczos method result.
static double GetTakeTime(MEASUREMENT_INDEX index)
Get taken time for part.
static void COmpareWIthMatLabSeOrthMPI(int nRowCount, int nIteration, int nInterval, int nEigCount, bool bSelect, bool bCalcuVector, int nFileIndex)
static void AuditResult_Seorth(int nIndex, int nFindEigenValue, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fMin, double fMax)
static int GetTotalNodeCount()
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaFileLoad(char *pszFileName, int nMatrixSize)
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)
const unsigned long ERROR_OUT_OF_RANGE
Error code that means during access vector or matrix input index out of range.
void MinusVector(CKNVector *vector)
Do minus operation between vectors.
static bool IsInMPIRoutine()
double GetNorm()
Get norm of complex number.
static void SolvingLargeSizeHamlitonian(int nIteration, int nInterval, int nEigCount, bool bSelect, bool bCalcuVector, bool bWaveFunction)
#define LARGE_MATRIX_ORDER
struct _tag * LPLANCZOS_PARAM
bool SetAt(CKNComplex number, unsigned int nRow, unsigned int nColumn)
Set element to specific index.
static void LargeSizeMatrixMPI(int nRowCount, int nIteration, int nInterval, int nEigCount, bool bSelect, bool bCalcuVector, bool bWaveFunction)
static void TestCSRBuilding()
Common definition for Solver.
CKNComplex GetAt(unsigned int nIndex)
Get element value from specific index.
static CKNLanczosMethod * m_pCurrentLanczosInstance
Structure for engienvalue computing.
#define MATLAB_SEORTH_RESULT_FILE
void Finalize()
Free allocated memory for vector elements.
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.
This class includes functions for matrix debugging.
static double GetTotalTakeTime()
static void SaveResultCVS()
double GetNorm(bool bMPI=false)
Getting norm of vector.
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaFileLoad_(char *pszFileName, int nMatrixSize)
#define LARGE_MATRIX_READ_COUNT
static int GetCurrentRank()
#define LARGE_SIZE_MATRIX_FILE
static void TotalMeasurementEnd()
Measurement end for total taken time.
static void ShowCSR(CKNMatrixOperation::CKNCSR *pCSR, char *pszDebugMsg)
Set show message or not.
static void AuditResult(int nIndex, int nFindEigenValue, CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fMin, double fMax)
unsigned int nEigenValueCount
#define FREE_MEM(pointer)
Macro for memory allocation and assign null value.
static void TotalMeasurementStart()
Measurement start for total taken time.
bool InsertColumnAtEnd()
Insert column after last column.
const unsigned long ERROR_MALLOC
Error code that means error occur during memory allocation.
This class for complex operation and saving value.
CKNMatrixOperation::CKNCSR * pA_Matrix
static void AuditResult_WF(CKNLanczosMethod::LPEIGENVALUE_RESULT lpResult, double fTolerance, unsigned int nWaveFunctionSize)
static void DumpCSR(CKNMatrixOperation::CKNCSR *pCSR, const char *pstrFileName)
For dubugging save CSR information into file.
static CKNMatrixOperation::CKNCSR * TestCSRBuildingViaArray()
static void ReleaseResult(LPEIGENVALUE_RESULT lpResult, bool bReleaseStruct)
Release memory for lanczos method result.
static void MeasurementStart(MEASUREMENT_INDEX index)
Measurement start for part.
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 TestSimpleLanczos()
static bool IsSame(double operand1, double operand2, double tol)
Compare two double variable.
void SetComplexNumber(double fReal, double fImaginaray)
Set Complex number using real part and imaginary part.
static void CompareWithMatLabSeOrth_(int nIteration, int nInterval, int nEigCount, bool bSelect, bool bCalcuVector)
void * LanczosThreadForMPI(void *pParam)
static void InitTimer()
Init time related variable.
This class for describing vector for Lanczos method.