48 #define spINSIDE_SPARSE
126 void spPrint(
char* eMatrix,
int PrintReordered,
int Data,
int Header)
130 int I, Row, Col, Size, Top, StartCol = 1, StopCol, Columns, ElementCount = 0;
131 double Magnitude, SmallestDiag, SmallestElement;
132 double LargestElement = 0.0, LargestDiag = 0.0;
133 ElementPtr pElement, pImagElements[PRINTER_WIDTH / 10 + 1];
134 int *PrintOrdToIntRowMap, *PrintOrdToIntColMap;
141 Top =
Matrix->AllocatedSize;
142 CALLOC(PrintOrdToIntRowMap,
int, Top + 1);
143 CALLOC(PrintOrdToIntColMap,
int, Top + 1);
144 if (PrintOrdToIntRowMap ==
NULL OR PrintOrdToIntColMap ==
NULL) {
148 for (I = 1; I <= Size; I++) {
149 PrintOrdToIntRowMap[
Matrix->IntToExtRowMap[I]] = I;
150 PrintOrdToIntColMap[
Matrix->IntToExtColMap[I]] = I;
154 for (J = 1, I = 1; I <= Top; I++) {
155 if (PrintOrdToIntRowMap[I] != 0)
156 PrintOrdToIntRowMap[J++] = PrintOrdToIntRowMap[I];
158 for (J = 1, I = 1; I <= Top; I++) {
159 if (PrintOrdToIntColMap[I] != 0)
160 PrintOrdToIntColMap[J++] = PrintOrdToIntColMap[I];
165 printf(
"MATRIX SUMMARY\n\n");
166 printf(
"Size of matrix = %1u x %1u.\n", Size, Size);
167 if (
Matrix->Reordered
AND PrintReordered)
168 printf(
"Matrix has been reordered.\n");
172 printf(
"Matrix after factorization:\n");
174 printf(
"Matrix before factorization:\n");
176 SmallestElement = DBL_MAX;
177 SmallestDiag = SmallestElement;
181 Columns = PRINTER_WIDTH;
185 Columns = (Columns + 1) / 10;
196 StopCol = StartCol + Columns - 1;
204 for (I = StartCol; I <= StopCol; I++) {
208 Col = PrintOrdToIntColMap[I];
214 printf(
"Columns %1d to %1d.\n", StartCol, StopCol);
216 printf(
"Columns %1d to %1d.\n",
217 Matrix->IntToExtColMap[PrintOrdToIntColMap[StartCol]],
218 Matrix->IntToExtColMap[PrintOrdToIntColMap[StopCol]]);
224 for (I = 1; I <= Size; I++) {
228 Row = PrintOrdToIntRowMap[I];
240 for (J = StartCol; J <= StopCol; J++) {
244 Col = PrintOrdToIntColMap[J];
246 pElement =
Matrix->FirstInCol[Col];
247 while (pElement !=
NULL AND pElement->
Row != Row)
251 pImagElements[J - StartCol] = pElement;
253 if (pElement !=
NULL)
263 if ((Magnitude =
ELEMENT_MAG(pElement)) > LargestElement)
264 LargestElement = Magnitude;
265 if ((Magnitude < SmallestElement)
AND(Magnitude != 0.0))
266 SmallestElement = Magnitude;
288 printf(
"\nLargest element in matrix = %-1.4lg.\n", LargestElement);
289 printf(
"Smallest element in matrix = %-1.4lg.\n", SmallestElement);
292 for (I = 1; I <= Size; I++) {
295 if (Magnitude > LargestDiag)
296 LargestDiag = Magnitude;
297 if (Magnitude < SmallestDiag)
298 SmallestDiag = Magnitude;
304 printf(
"\nLargest diagonal element = %-1.4lg.\n", LargestDiag);
305 printf(
"Smallest diagonal element = %-1.4lg.\n", SmallestDiag);
307 printf(
"\nLargest pivot element = %-1.4lg.\n", LargestDiag);
308 printf(
"Smallest pivot element = %-1.4lg.\n", SmallestDiag);
312 printf(
"\nDensity = %2.2lf%%.\n", ((
double)(ElementCount * 100)) / ((
double)(Size * Size)));
317 (void)fflush(stdout);
319 FREE(PrintOrdToIntColMap);
320 FREE(PrintOrdToIntRowMap);
371 int Row, Col, Err = 0;
378 if ((pMatrixFile = fopen(File,
"w")) ==
NULL)
385 Err = fprintf(pMatrixFile,
386 "Warning : The following matrix is factored in to LU form.\n");
390 if (fprintf(pMatrixFile,
"%s\n",
Label) < 0)
392 Err = fprintf(pMatrixFile,
"%d\t%s\n", Size,
393 (
Matrix->Complex ?
"complex" :
"real"));
400 for (I = 1; I <= Size; I++) {
401 pElement =
Matrix->FirstInCol[I];
402 while (pElement !=
NULL) {
407 Row =
Matrix->IntToExtRowMap[pElement->
Row];
408 Col =
Matrix->IntToExtColMap[I];
411 if (fprintf(pMatrixFile,
"%d\t%d\n", Row, Col) < 0)
417 if (fprintf(pMatrixFile,
"0\t0\n") < 0)
424 for (I = 1; I <= Size; I++) {
425 pElement =
Matrix->FirstInCol[I];
426 while (pElement !=
NULL) {
427 Row =
Matrix->IntToExtRowMap[pElement->
Row];
428 Col =
Matrix->IntToExtColMap[I];
429 Err = fprintf(pMatrixFile,
"%d\t%d\t%-.15lg\n",
430 Row, Col, (
double)pElement->
Real);
438 if (fprintf(pMatrixFile,
"0\t0\t0.0\n") < 0)
444 if (fclose(pMatrixFile) < 0)
489 if ((pMatrixFile = fopen(File,
"a")) ==
NULL)
501 for (I = 1; I <= Size; I++) {
502 if (fprintf(pMatrixFile,
"%-.15lg\n", (
double)
RHS[I]) < 0)
509 if (fclose(pMatrixFile) < 0)
555 int NumberOfElements;
563 if ((pStatsFile = fopen(File,
"a")) ==
NULL)
569 fprintf(pStatsFile,
"Matrix has not been factored.\n");
570 fprintf(pStatsFile,
"||| Starting new matrix |||\n");
571 fprintf(pStatsFile,
"%s\n",
Label);
572 fprintf(pStatsFile,
"Matrix is real.\n");
573 fprintf(pStatsFile,
" Size = %d\n", Size);
576 NumberOfElements = 0;
577 LargestElement = 0.0;
578 SmallestElement = DBL_MAX;
580 for (I = 1; I <= Size; I++) {
581 pElement =
Matrix->FirstInCol[I];
582 while (pElement !=
NULL) {
585 if (
Data > LargestElement)
586 LargestElement =
Data;
588 SmallestElement =
Data;
593 SmallestElement =
MIN(SmallestElement, LargestElement);
596 fprintf(pStatsFile,
" Initial number of elements = %d\n",
597 NumberOfElements -
Matrix->Fillins);
599 " Initial average number of elements per row = %lf\n",
600 (
double)(NumberOfElements -
Matrix->Fillins) / (
double)Size);
601 fprintf(pStatsFile,
" Fill-ins = %d\n",
Matrix->Fillins);
602 fprintf(pStatsFile,
" Average number of fill-ins per row = %lf%%\n",
603 (
double)
Matrix->Fillins / (
double)Size);
604 fprintf(pStatsFile,
" Total number of elements = %d\n",
606 fprintf(pStatsFile,
" Average number of elements per row = %lf\n",
607 (
double)NumberOfElements / (
double)Size);
608 fprintf(pStatsFile,
" Density = %lf%%\n",
609 (
double)(100.0 * NumberOfElements) / (
double)(Size * Size));
610 fprintf(pStatsFile,
" Relative Threshold = %e\n",
Matrix->RelThreshold);
611 fprintf(pStatsFile,
" Absolute Threshold = %e\n",
Matrix->AbsThreshold);
612 fprintf(pStatsFile,
" Largest Element = %e\n", LargestElement);
613 fprintf(pStatsFile,
" Smallest Element = %e\n\n\n", SmallestElement);
616 (void)fclose(pStatsFile);
struct MatrixFrame * MatrixPtr
#define CALLOC(ptr, type, number)
#define ASSERT(condition)
#define IS_SPARSE(matrix)
int spFileVector(char *eMatrix, char *File, RealVector RHS, RealVector iRHS)
int spFileMatrix(char *eMatrix, char *File, char *Label, int Reordered, int Data, int Header)
void spPrint(char *eMatrix, int PrintReordered, int Data, int Header)
int spFileStats(char *eMatrix, char *File, char *Label)
struct MatrixElement * NextInCol