Exemplo n.º 1
0
/*!
  @param[in] A the known system matrix
  @param[in] r the input vector
  @param[inout] x On exit contains the result of the multigrid V-cycle with r as the RHS, x is the approximation to Ax = r.

  @return returns 0 upon success and non-zero otherwise

  @see ComputeMG_ref
*/
int ComputeMG(const SparseMatrix  & A, const Vector & r, Vector & x) {

  // This line and the next two lines should be removed and your version of ComputeSYMGS should be used.
	if(A.optimizationData == 0 || r.optimizationData == 0 || x.optimizationData == 0){
		A.isMgOptimized = false;
		return ComputeMG_ref(A, r, x);
	}

  assert(x.localLength==A.localNumberOfColumns); // Make sure x contain space for halo values

  ZeroVector(x); // initialize x to zero

  int ierr = 0;
  if (A.mgData!=0) { // Go to next coarse level if defined
    int numberOfPresmootherSteps = A.mgData->numberOfPresmootherSteps;
    for (int i=0; i< numberOfPresmootherSteps; ++i) ierr += ComputeSYMGS(A, r, x);
    if (ierr!=0) return ierr;
    ierr = ComputeSPMV(A, x, *A.mgData->Axf); if (ierr!=0) return ierr;
    // Perform restriction operation using simple injection
    ierr = ComputeRestriction(A, r);  if (ierr!=0) return ierr;
    ierr = ComputeMG(*A.Ac,*A.mgData->rc, *A.mgData->xc);  if (ierr!=0) return ierr;
    ierr = ComputeProlongation(A, x);  if (ierr!=0) return ierr;
    int numberOfPostsmootherSteps = A.mgData->numberOfPostsmootherSteps;
    for (int i=0; i< numberOfPostsmootherSteps; ++i) ierr += ComputeSYMGS(A, r, x);
    if (ierr!=0) return ierr;
  }
  else {
    ierr = ComputeSYMGS(A, r, x);
    if (ierr!=0) return ierr;
  }
  return 0;
}
Exemplo n.º 2
0
/*!
    @param[in] A the known system matrix.

    @param[in] r the input vector.

    @param[inout] x On exit contains the result of the multigrid V-cycle with r
    as the RHS, x is the approximation to Ax = r.

    @return returns 0 upon success and non-zero otherwise.

    @see ComputeMG
*/
inline int
ComputeMG(
    SparseMatrix &A,
    Array<floatType> &r,
    Array<floatType> &x,
    Context ctx,
    Runtime *lrt
) {
    const auto *const Asclrs = A.sclrs->data();
    assert(Asclrs);
    // Make sure x contain space for halo values.
    assert(x.length() == size_t(Asclrs->localNumberOfColumns));
    // Initialize x to zero.
    ZeroVector(x, ctx, lrt);
    //
    int ierr = 0;
    // Go to next coarse level if defined
    if (A.mgData != NULL) {
        const int nPre = A.mgData->numberOfPresmootherSteps;
        for (int i = 0; i < nPre; ++i) {
            ierr += ComputeSYMGS(A, r, x, ctx, lrt);
        }
        if (ierr != 0) return ierr;
        //
        ierr = ComputeSPMV(A, x, *A.mgData->Axf, ctx, lrt);
        if (ierr != 0) return ierr;
        // Perform restriction operation using simple injection.
        ierr = ComputeRestriction(A, r, ctx, lrt);
        if (ierr != 0) return ierr;
        //
        ierr = ComputeMG(*A.Ac, *A.mgData->rc, *A.mgData->xc, ctx, lrt);
        if (ierr != 0) return ierr;
        //
        ierr = ComputeProlongation(A, x, ctx, lrt);
        if (ierr!=0) return ierr;
        const int nPost = A.mgData->numberOfPostsmootherSteps;
        for (int i = 0; i < nPost; ++i) {
            ierr += ComputeSYMGS(A, r, x, ctx, lrt);
        }
        if (ierr != 0) return ierr;
    }
    else {
        ierr = ComputeSYMGS(A, r, x, ctx, lrt);
        if (ierr != 0) return ierr;
    }
    //
    return 0;
}