void comparePCLandP(CLDict *clDict,float *OrigP, float *Epsilon, float *Fst, int *NumAlleles, int *Geno, int *Z, float *lambda, struct IND *Individual, float *randomArr) { float *OldP; float *P; int ret; OldP = calloc(PSIZE,sizeof(float)); P = calloc(PSIZE,sizeof(float)); memcpy(P,OrigP,PSIZE*sizeof(float)); UpdateP (P, Epsilon, Fst, NumAlleles, Geno, Z, lambda, Individual, randomArr); memcpy(OldP,P,PSIZE*sizeof(float)); UpdatePCL (clDict,P,Epsilon, Fst, NumAlleles, Geno, Z, lambda, Individual, randomArr); ret = comparefloatArrs(P,OldP,PSIZE,"P and old P"); if (ret == EXIT_FAILURE) { ReleaseCLDict(clDict); exit(EXIT_FAILURE); } free(OldP); free(P); }
bool LinearSystem<Real>::SolveSymmetricCG (const GMatrix<Real>& A, const Real* B, Real* X) { // Based on the algorithm in "Matrix Computations" by Golum and Van Loan. assertion(A.GetNumRows() == A.GetNumColumns(), "Matrix must be square\n"); int size = A.GetNumRows(); Real* R = new1<Real>(size); Real* P = new1<Real>(size); Real* W = new1<Real>(size); // The first iteration. size_t numBytes = size*sizeof(Real); memset(X, 0, numBytes); memcpy(R, B, numBytes); Real rho0 = Dot(size, R, R); memcpy(P, R, numBytes); Multiply(A, P, W); Real alpha = rho0/Dot(size, P, W); UpdateX(size, X, alpha, P); UpdateR(size, R, alpha, W); Real rho1 = Dot(size, R, R); // The remaining iterations. const int imax = 1024; int i; for (i = 1; i < imax; ++i) { Real root0 = Math<Real>::Sqrt(rho1); Real norm = Dot(size, B, B); Real root1 = Math<Real>::Sqrt(norm); if (root0 <= ZeroTolerance*root1) { break; } Real beta = rho1/rho0; UpdateP(size, P, beta, R); Multiply(A, P, W); alpha = rho1/Dot(size, P, W); UpdateX(size, X, alpha, P); UpdateR(size, R, alpha, W); rho0 = rho1; rho1 = Dot(size, R, R); } delete1(W); delete1(P); delete1(R); return i < imax; }