Esempio n. 1
0
        public static void ConjugateGradient(FloatResidentArray X, SparseMatrix A, FloatResidentArray B, int maxiter, float eps)
        {
            int N = (int)B.Count;
            FloatResidentArray R  = new FloatResidentArray(N);
            FloatResidentArray P  = new FloatResidentArray(N);
            FloatResidentArray AP = new FloatResidentArray(N);

            A.RefreshDevice();
            X.RefreshDevice();
            B.RefreshDevice();

            wrapper.Fmsub(R, B, A, X, N);                       // R = B - A*X
            wrapper.Copy(P, R, N);
            int k = 0;

            while (k < maxiter)
            {
                wrapper.Multiply(AP, A, P, N);                  // AP = A*P
                float r     = ScalarProd(R, R, N);              // save <R|R>
                float alpha = r / ScalarProd(P, AP, N);         // alpha = <R|R> / <P|AP>
                wrapper.Saxpy(X, X, alpha, P, N);               // X = X - alpha*P
                wrapper.Saxpy(R, R, -alpha, AP, N);             // RR = R-alpha*AP
                float rr = ScalarProd(R, R, N);
                if (rr < eps * eps)
                {
                    break;
                }

                float beta = rr / r;
                wrapper.Saxpy(P, R, beta, P, N);                // P = R + beta*P
                ++k;
            }

            X.RefreshHost();
        }
Esempio n. 2
0
 public void RefreshHost()
 {
     indices.RefreshHost();
     data.RefreshHost();
     rows.RefreshHost();
 }
Esempio n. 3
0
 public void RefreshHost()
 {
     _inner.RefreshHost();
 }