/* nag_sparse_complex_herm_precon_ichol (f11jnc) Example Program.
*
* Copyright 2020 Numerical Algorithms Group.
*
* Mark 27.1, 2020.
*/
#include <nag.h>
int main(void) {
/* Scalars */
Integer exit_status = 0;
double dscale, dtol;
Integer i, la, lfill, n, nnz, nnzc, npivm;
/* Arrays */
Complex *a = 0;
Integer *icol = 0, *ipiv = 0, *irow = 0, *istr = 0;
char nag_enum_arg[100];
/* NAG types */
Nag_SparseSym_Piv pstrat;
Nag_SparseSym_Fact mic;
NagError fail;
INIT_FAIL(fail);
printf(
"nag_sparse_complex_herm_precon_ichol (f11jnc) Example Program Results\n");
/* Skip heading in data file */
scanf("%*[^\n]");
/* Read algorithmic parameters */
scanf("%" NAG_IFMT "%*[^\n]%" NAG_IFMT "%*[^\n]", &n, &nnz);
/* Allocate memory */
la = 3 * nnz;
if (!(a = NAG_ALLOC(la, Complex)) || !(icol = NAG_ALLOC(la, Integer)) ||
!(ipiv = NAG_ALLOC(n, Integer)) || !(irow = NAG_ALLOC(la, Integer)) ||
!(istr = NAG_ALLOC(n + 1, Integer))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
scanf("%" NAG_IFMT "%lf%*[^\n]", &lfill, &dtol);
scanf("%99s%*[^\n]", nag_enum_arg);
/* 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("%lf%*[^\n]", &dscale);
scanf("%99s%*[^\n]", nag_enum_arg);
pstrat = (Nag_SparseSym_Piv)nag_enum_name_to_value(nag_enum_arg);
/* Read the matrix a */
for (i = 0; i < nnz; i++)
scanf(" ( %lf , %lf ) %" NAG_IFMT "%" NAG_IFMT "%*[^\n] ", &a[i].re,
&a[i].im, &irow[i], &icol[i]);
/* Calculate incomplete Cholesky factorization using
* nag_sparse_complex_herm_precon_ichol (f11jnc).
*/
nag_sparse_complex_herm_precon_ichol(n, nnz, a, la, irow, icol, lfill, dtol,
mic, dscale, pstrat, ipiv, istr, &nnzc,
&npivm, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_sparse_complex_herm_precon_ichol (f11jnc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* Output original matrix */
printf(" Original Matrix \n");
printf(" n = %4" NAG_IFMT ", nnz = %4" NAG_IFMT "\n", n, nnz);
printf("%8s%16s%23s%9s\n", "i", "a[i]", "irow[i]", "icol[i]");
for (i = 0; i < nnz; i++)
printf("%8" NAG_IFMT " (%13.4e, %13.4e) %8" NAG_IFMT " %8" NAG_IFMT " \n",
i, a[i].re, a[i].im, irow[i], icol[i]);
printf("\n");
/* Output details of the factorization */
printf(" Factorization \n");
printf(" n = %4" NAG_IFMT ", nnzc = %4" NAG_IFMT ", npivm = %4" NAG_IFMT
"\n",
n, nnzc, npivm);
printf("%8s%16s%23s%9s\n", "i", "a[i]", "irow[i]", "icol[i]");
for (i = nnz; i < nnz + nnzc; i++)
printf("%8" NAG_IFMT " (%13.4e, %13.4e) %8" NAG_IFMT " %8" NAG_IFMT " \n",
i, a[i].re, a[i].im, irow[i], icol[i]);
printf("\n%8s%12s\n", "i", "ipiv[i-1]");
for (i = 1; i <= n; i++)
printf("%8" NAG_IFMT "%8" NAG_IFMT "\n", i, ipiv[i - 1]);
END:
NAG_FREE(a);
NAG_FREE(icol);
NAG_FREE(ipiv);
NAG_FREE(irow);
NAG_FREE(istr);
return exit_status;
}