static void icgsm(double *u, double *unrm, int n, int m, double *Q, PyObject *mmat, double *um, double *temp) { const int maxcgsit = 5; const double alpha = 0.5; double unrm_old; int ret, i, isorth = 0; ret = SpMatrix_Matvec(mmat, n, u, n, um); assert(ret == 0); *unrm = sqrt(F77(ddot)(&n, u, &ONE, um, &ONE)); if (m == 0) return; for (i = 0; !isorth && i < maxcgsit; i ++) { F77(dgemv)("t", &n, &m, &DONE, Q, &n, um, &ONE, &DZER, temp, &ONE, 1); F77(dgemv)("n", &n, &m, &DMONE, Q, &n, temp, &ONE, &DONE, u, &ONE, 1); ret = SpMatrix_Matvec(mmat, n, u, n, um); assert(ret == 0); unrm_old = (*unrm); *unrm = sqrt(F77(ddot)(&n, u, &ONE, um, &ONE)); isorth=((*unrm) > alpha*unrm_old); } if (i >= maxcgsit) { printf("warning: loss of orthogonality. "); printf("icgsm() not converged after %d steps.\n", maxcgsit); } }
static int jacobi(PyObject *matrix, int n, double *dinv, int steps, double *x, double *y, double *temp) { int ONE = 1; int i, step, res; /* 1st step */ for (i = 0; i < n; i ++) y[i] = x[i]*dinv[i]; /* following steps */ for(step = 1; step < steps; step ++) { F77(dcopy)(&n, y, &ONE, temp, &ONE); res = SpMatrix_Matvec(matrix, n, temp, n, y); if (res == -1) return res; for (i = 0; i < n; i ++) y[i] = (x[i] - y[i])*dinv[i] + temp[i]; } return 0; }