| { |
| PetscErrorCode ierr; |
| PetscInt i,k; |
| PetscScalar *pV; |
| PetscBool khas,mhas,lindep; |
| PetscReal knorm,mnorm,norm; |
| Vec t; |
| PetscFunctionBegin; |
| PetscValidHeaderSpecific(qep,QEP_CLASSID,1); |
| ierr = PetscFree(qep->eigi);CHKERRQ(ierr); |
| ierr = PetscFree(qep->perm);CHKERRQ(ierr); |
| ierr = PetscFree(qep->errest);CHKERRQ(ierr); |
| ierr = VecGetArray(qep->V[0],&pV);CHKERRQ(ierr); |
| for (i=0;i<qep->ncv;i++) { |
| ierr = VecDestroy(&qep->V[i]);CHKERRQ(ierr); |
| } |
| ierr = PetscFree(pV);CHKERRQ(ierr); |
| ierr = PetscFree(qep->V);CHKERRQ(ierr); |
| ierr = SlepcVecDestroyVecs(qep->ncv,&qep->V);CHKERRQ(ierr); |
| } |
| /* Allocate memory for next solution */ |
| ierr = PetscMalloc(qep->ncv*sizeof(PetscScalar),&qep->eigi);CHKERRQ(ierr); |
| ierr = PetscMalloc(qep->ncv*sizeof(PetscInt),&qep->perm);CHKERRQ(ierr); |
| ierr = PetscMalloc(qep->ncv*sizeof(PetscReal),&qep->errest);CHKERRQ(ierr); |
| ierr = PetscMalloc(qep->ncv*sizeof(Vec),&qep->V);CHKERRQ(ierr); |
| ierr = PetscMalloc(qep->ncv*qep->nloc*sizeof(PetscScalar),&pV);CHKERRQ(ierr); |
| for (i=0;i<qep->ncv;i++) { |
| ierr = VecCreateMPIWithArray(((PetscObject)qep)->comm,qep->nloc,PETSC_DECIDE,pV+i*qep->nloc,&qep->V[i]);CHKERRQ(ierr); |
| } |
| ierr = VecCreateMPIWithArray(((PetscObject)qep)->comm,qep->nloc,PETSC_DECIDE,PETSC_NULL,&t);CHKERRQ(ierr); |
| ierr = SlepcVecDuplicateVecs(t,qep->ncv,&qep->V);CHKERRQ(ierr); |
| ierr = VecDestroy(&t);CHKERRQ(ierr); |
| /* process initial vectors */ |
| if (qep->nini<0) { |
| PetscErrorCode QEPDestroy(QEP *qep) |
| { |
| PetscErrorCode ierr; |
| PetscScalar *pV; |
| PetscInt i; |
| PetscFunctionBegin; |
| if (!*qep) PetscFunctionReturn(0); |
| ierr = PetscFree((*qep)->eigi);CHKERRQ(ierr); |
| ierr = PetscFree((*qep)->perm);CHKERRQ(ierr); |
| ierr = PetscFree((*qep)->errest);CHKERRQ(ierr); |
| ierr = VecGetArray((*qep)->V[0],&pV);CHKERRQ(ierr); |
| for (i=0;i<(*qep)->ncv;i++) { |
| ierr = VecDestroy(&(*qep)->V[i]);CHKERRQ(ierr); |
| } |
| ierr = PetscFree(pV);CHKERRQ(ierr); |
| ierr = PetscFree((*qep)->V);CHKERRQ(ierr); |
| ierr = SlepcVecDestroyVecs((*qep)->ncv,&(*qep)->V);CHKERRQ(ierr); |
| } |
| ierr = QEPMonitorCancel(*qep);CHKERRQ(ierr); |
| ierr = IPDestroy(&(*qep)->ip);CHKERRQ(ierr); |
| PetscErrorCode EPSAllocateSolution(EPS eps) |
| { |
| PetscErrorCode ierr; |
| PetscInt i; |
| PetscScalar *pV,*pW; |
| Vec t; |
| PetscFunctionBegin; |
| PetscValidHeaderSpecific(eps,EPS_CLASSID,1); |
| if (eps->allocated_ncv != eps->ncv) { |
| if (eps->allocated_ncv > 0) { |
| ierr = PetscFree(eps->eigr);CHKERRQ(ierr); |
| ierr = PetscFree(eps->eigi);CHKERRQ(ierr); |
| ierr = PetscFree(eps->errest);CHKERRQ(ierr); |
| ierr = PetscFree(eps->errest_left);CHKERRQ(ierr); |
| ierr = VecGetArray(eps->V[0],&pV);CHKERRQ(ierr); |
| for (i=0;i<eps->allocated_ncv;i++) { |
| ierr = VecDestroy(&eps->V[i]);CHKERRQ(ierr); |
| } |
| ierr = PetscFree(pV);CHKERRQ(ierr); |
| ierr = PetscFree(eps->V);CHKERRQ(ierr); |
| if (eps->W) { |
| ierr = VecGetArray(eps->W[0],&pW);CHKERRQ(ierr); |
| for (i=0;i<eps->allocated_ncv;i++) { |
| ierr = VecDestroy(&eps->W[i]);CHKERRQ(ierr); |
| } |
| ierr = PetscFree(pW);CHKERRQ(ierr); |
| ierr = PetscFree(eps->W);CHKERRQ(ierr); |
| } |
| } |
| ierr = EPSFreeSolution(eps);CHKERRQ(ierr); |
| ierr = PetscMalloc(eps->ncv*sizeof(PetscScalar),&eps->eigr);CHKERRQ(ierr); |
| ierr = PetscMalloc(eps->ncv*sizeof(PetscScalar),&eps->eigi);CHKERRQ(ierr); |
| ierr = PetscMalloc(eps->ncv*sizeof(PetscReal),&eps->errest);CHKERRQ(ierr); |
| ierr = PetscMalloc(eps->ncv*sizeof(PetscReal),&eps->errest_left);CHKERRQ(ierr); |
| ierr = PetscMalloc(eps->ncv*sizeof(Vec),&eps->V);CHKERRQ(ierr); |
| ierr = PetscMalloc(eps->ncv*eps->nloc*sizeof(PetscScalar),&pV);CHKERRQ(ierr); |
| for (i=0;i<eps->ncv;i++) { |
| ierr = VecCreateMPIWithArray(((PetscObject)eps)->comm,eps->nloc,PETSC_DECIDE,pV+i*eps->nloc,&eps->V[i]);CHKERRQ(ierr); |
| } |
| ierr = VecCreateMPIWithArray(((PetscObject)eps)->comm,eps->nloc,PETSC_DECIDE,PETSC_NULL,&t);CHKERRQ(ierr); |
| ierr = SlepcVecDuplicateVecs(t,eps->ncv,&eps->V);CHKERRQ(ierr); |
| if (eps->leftvecs) { |
| ierr = PetscMalloc(eps->ncv*sizeof(Vec),&eps->W);CHKERRQ(ierr); |
| ierr = PetscMalloc(eps->ncv*eps->nloc*sizeof(PetscScalar),&pW);CHKERRQ(ierr); |
| for (i=0;i<eps->ncv;i++) { |
| ierr = VecCreateMPIWithArray(((PetscObject)eps)->comm,eps->nloc,PETSC_DECIDE,pW+i*eps->nloc,&eps->W[i]);CHKERRQ(ierr); |
| } |
| ierr = SlepcVecDuplicateVecs(t,eps->ncv,&eps->W);CHKERRQ(ierr); |
| } |
| ierr = VecDestroy(&t);CHKERRQ(ierr); |
| eps->allocated_ncv = eps->ncv; |
| } |
| PetscFunctionReturn(0); |
| PetscErrorCode EPSFreeSolution(EPS eps) |
| { |
| PetscErrorCode ierr; |
| PetscInt i; |
| PetscScalar *pV,*pW; |
| PetscFunctionBegin; |
| PetscValidHeaderSpecific(eps,EPS_CLASSID,1); |
| if (eps->allocated_ncv > 0) { |
| ierr = PetscFree(eps->eigr);CHKERRQ(ierr); |
| ierr = PetscFree(eps->eigi);CHKERRQ(ierr); |
| ierr = PetscFree(eps->errest);CHKERRQ(ierr); |
| ierr = PetscFree(eps->errest_left);CHKERRQ(ierr); |
| ierr = VecGetArray(eps->V[0],&pV);CHKERRQ(ierr); |
| for (i=0;i<eps->allocated_ncv;i++) { |
| ierr = VecDestroy(&eps->V[i]);CHKERRQ(ierr); |
| } |
| ierr = PetscFree(pV);CHKERRQ(ierr); |
| ierr = PetscFree(eps->V);CHKERRQ(ierr); |
| ierr = PetscFree(eps->errest);CHKERRQ(ierr); |
| ierr = PetscFree(eps->errest_left);CHKERRQ(ierr); |
| ierr = SlepcVecDestroyVecs(eps->allocated_ncv,&eps->V);CHKERRQ(ierr); |
| if (eps->W) { |
| ierr = VecGetArray(eps->W[0],&pW);CHKERRQ(ierr); |
| for (i=0;i<eps->allocated_ncv;i++) { |
| ierr = VecDestroy(&eps->W[i]);CHKERRQ(ierr); |
| } |
| ierr = PetscFree(pW);CHKERRQ(ierr); |
| ierr = PetscFree(eps->W);CHKERRQ(ierr); |
| ierr = SlepcVecDestroyVecs(eps->allocated_ncv,&eps->W);CHKERRQ(ierr); |
| } |
| eps->allocated_ncv = 0; |
| } |
| PetscErrorCode ierr; |
| PetscInt i; |
| EPS_SUBSPACE *ctx = (EPS_SUBSPACE *)eps->data; |
| PetscScalar *pAV; |
| PetscFunctionBegin; |
| if (eps->ncv) { /* ncv set */ |
| } |
| ierr = EPSAllocateSolution(eps);CHKERRQ(ierr); |
| ierr = PetscMalloc(eps->ncv*sizeof(Vec),&ctx->AV);CHKERRQ(ierr); |
| ierr = PetscMalloc(eps->ncv*eps->nloc*sizeof(PetscScalar),&pAV);CHKERRQ(ierr); |
| for (i=0;i<eps->ncv;i++) { |
| ierr = VecCreateMPIWithArray(((PetscObject)eps)->comm,eps->nloc,PETSC_DECIDE,pAV+i*eps->nloc,&ctx->AV[i]);CHKERRQ(ierr); |
| } |
| ierr = SlepcVecDuplicateVecs(eps->V[0],eps->ncv,&ctx->AV);CHKERRQ(ierr); |
| ierr = PetscFree(eps->T);CHKERRQ(ierr); |
| ierr = PetscMalloc(eps->ncv*eps->ncv*sizeof(PetscScalar),&eps->T);CHKERRQ(ierr); |
| ierr = EPSDefaultGetWork(eps,1);CHKERRQ(ierr); |
| { |
| PetscErrorCode ierr; |
| PetscInt i; |
| PetscScalar *pAV; |
| EPS_SUBSPACE *ctx = (EPS_SUBSPACE *)eps->data; |
| PetscFunctionBegin; |
| ierr = VecGetArray(ctx->AV[0],&pAV);CHKERRQ(ierr); |
| for (i=0;i<eps->ncv;i++) { |
| ierr = VecDestroy(&ctx->AV[i]);CHKERRQ(ierr); |
| } |
| ierr = PetscFree(pAV);CHKERRQ(ierr); |
| ierr = PetscFree(ctx->AV);CHKERRQ(ierr); |
| ierr = SlepcVecDestroyVecs(eps->ncv,&ctx->AV);CHKERRQ(ierr); |
| ierr = EPSDestroy_Default(eps);CHKERRQ(ierr); |
| PetscFunctionReturn(0); |
| } |
| tridiagonal matrix with DD on the diagonal, DL on the subdiagonal, and |
| DU on the superdiagonal. |
| */ |
| static void tv(int nx,PetscScalar *x,PetscScalar *y) |
| static void tv(int nx,const PetscScalar *x,PetscScalar *y) |
| { |
| PetscScalar dd,dl,du; |
| int j; |
| "This example illustrates how the user can set the initial vector.\n\n" |
| "The command line options are:\n" |
| " -m <m>, where <m> = number of grid subdivisions in each dimension.\n\n"; |
| cut -d : -f 1 | uniq | xargs gvim |
| #include <slepceps.h> |
| /* |