/* nag_sparse_real_symm_precon_ichol (f11jac) Example Program.
*
* Copyright 2022 Numerical Algorithms Group.
*
* Mark 28.3, 2022.
*
*/
#include <nag.h>
#include <stdio.h>
int main(void) {
double dtol;
double *a;
double dscale;
Integer *irow, *icol;
Integer *ipiv, nnzc, *istr;
Integer exit_status = 0, i, n, lfill, npivm;
Integer nnz;
Integer num;
char nag_enum_arg[40];
Nag_SparseSym_Piv pstrat;
Nag_SparseSym_Fact mic;
Nag_Sparse_Comm comm;
NagError fail;
INIT_FAIL(fail);
printf(
"nag_sparse_real_symm_precon_ichol (f11jac) Example Program Results\n\n");
/* Skip heading in data file */
scanf("%*[^\n]");
/* Read algorithmic parameters */
scanf("%" NAG_IFMT "", &n);
scanf("%*[^\n]");
scanf("%" NAG_IFMT "%*[^\n]", &nnz);
scanf("%" NAG_IFMT "%lf%*[^\n]", &lfill, &dtol);
scanf("%39s%lf%*[^\n]", nag_enum_arg, &dscale);
/* nag_enum_name_to_value (x04nac).
* Converts NAG enum member name to value
*/
mic = (Nag_SparseSym_Fact)nag_enum_name_to_value(nag_enum_arg);
scanf("%39s%*[^\n]", nag_enum_arg);
pstrat = (Nag_SparseSym_Piv)nag_enum_name_to_value(nag_enum_arg);
/* Allocate memory */
num = 2 * nnz;
ipiv = NAG_ALLOC(n, Integer);
istr = NAG_ALLOC(n + 1, Integer);
irow = NAG_ALLOC(num, Integer);
icol = NAG_ALLOC(num, Integer);
a = NAG_ALLOC(num, double);
if (!ipiv || !istr || !irow || !icol || !a) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
/* Read the matrix a */
for (i = 1; i <= nnz; ++i)
scanf("%lf%" NAG_IFMT "%" NAG_IFMT "%*[^\n]", &a[i - 1], &irow[i - 1],
&icol[i - 1]);
/* Calculate incomplete Cholesky factorization */
/* nag_sparse_real_symm_precon_ichol (f11jac).
* Incomplete Cholesky factorization (symmetric)
*/
nag_sparse_real_symm_precon_ichol(n, nnz, &a, &num, &irow, &icol, lfill, dtol,
mic, dscale, pstrat, ipiv, istr, &nnzc,
&npivm, &comm, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_sparse_real_symm_precon_ichol (f11jac).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* Output original matrix */
printf(" Original Matrix \n");
printf(" n = %6" NAG_IFMT "\n", n);
printf(" nnz = %6" NAG_IFMT "\n\n", nnz);
for (i = 1; i <= nnz; ++i)
printf(" %8" NAG_IFMT "%16.4e%8" NAG_IFMT "%8" NAG_IFMT "\n", i, a[i - 1],
irow[i - 1], icol[i - 1]);
printf("\n");
/* Output details of the factorization */
printf(" Factorization\n n = %6" NAG_IFMT " \n nnz = %6" NAG_IFMT "\n", n,
nnzc);
printf(" npivm = %6" NAG_IFMT "\n\n", npivm);
for (i = nnz + 1; i <= nnz + nnzc; ++i)
printf(" %8" NAG_IFMT "%16.4e%8" NAG_IFMT "%8" NAG_IFMT "\n", i, a[i - 1],
irow[i - 1], icol[i - 1]);
printf("\n i ipiv(i) \n");
for (i = 1; i <= n; ++i)
printf(" %8" NAG_IFMT "%8" NAG_IFMT "\n", i, ipiv[i - 1]);
END:
NAG_FREE(irow);
NAG_FREE(icol);
NAG_FREE(a);
NAG_FREE(istr);
NAG_FREE(ipiv);
return exit_status;
}