本文整理汇总了C++中PetscLogEventEnd函数的典型用法代码示例。如果您正苦于以下问题:C++ PetscLogEventEnd函数的具体用法?C++ PetscLogEventEnd怎么用?C++ PetscLogEventEnd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PetscLogEventEnd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: TaoComputeObjective
/*@
TaoComputeObjective - Computes the objective function value at a given point
Collective on Tao
Input Parameters:
+ tao - the Tao context
- X - input vector
Output Parameter:
. f - Objective value at X
Notes: TaoComputeObjective() is typically used within minimization implementations,
so most users would not generally call this routine themselves.
Level: advanced
.seealso: TaoComputeGradient(), TaoComputeObjectiveAndGradient(), TaoSetObjectiveRoutine()
@*/
PetscErrorCode TaoComputeObjective(Tao tao, Vec X, PetscReal *f)
{
PetscErrorCode ierr;
Vec temp;
PetscFunctionBegin;
PetscValidHeaderSpecific(tao,TAO_CLASSID,1);
PetscValidHeaderSpecific(X,VEC_CLASSID,2);
PetscCheckSameComm(tao,1,X,2);
if (tao->ops->computeobjective) {
ierr = PetscLogEventBegin(Tao_ObjectiveEval,tao,X,NULL,NULL);CHKERRQ(ierr);
PetscStackPush("Tao user objective evaluation routine");
ierr = (*tao->ops->computeobjective)(tao,X,f,tao->user_objP);CHKERRQ(ierr);
PetscStackPop;
ierr = PetscLogEventEnd(Tao_ObjectiveEval,tao,X,NULL,NULL);CHKERRQ(ierr);
tao->nfuncs++;
} else if (tao->ops->computeobjectiveandgradient) {
ierr = PetscInfo(tao,"Duplicating variable vector in order to call func/grad routine\n");CHKERRQ(ierr);
ierr = VecDuplicate(X,&temp);CHKERRQ(ierr);
ierr = PetscLogEventBegin(Tao_ObjGradientEval,tao,X,NULL,NULL);CHKERRQ(ierr);
PetscStackPush("Tao user objective/gradient evaluation routine");
ierr = (*tao->ops->computeobjectiveandgradient)(tao,X,f,temp,tao->user_objgradP);CHKERRQ(ierr);
PetscStackPop;
ierr = PetscLogEventEnd(Tao_ObjGradientEval,tao,X,NULL,NULL);CHKERRQ(ierr);
ierr = VecDestroy(&temp);CHKERRQ(ierr);
tao->nfuncgrads++;
} else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"TaoSetObjectiveRoutine() has not been called");
ierr = PetscInfo1(tao,"TAO Function evaluation: %14.12e\n",(double)(*f));CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:fengyuqi,项目名称:petsc,代码行数:49,代码来源:taosolver_fg.c
示例2: TaoComputeGradient
/*@
TaoComputeGradient - Computes the gradient of the objective function
Collective on Tao
Input Parameters:
+ tao - the Tao context
- X - input vector
Output Parameter:
. G - gradient vector
Notes: TaoComputeGradient() is typically used within minimization implementations,
so most users would not generally call this routine themselves.
Level: advanced
.seealso: TaoComputeObjective(), TaoComputeObjectiveAndGradient(), TaoSetGradientRoutine()
@*/
PetscErrorCode TaoComputeGradient(Tao tao, Vec X, Vec G)
{
PetscErrorCode ierr;
PetscReal dummy;
PetscFunctionBegin;
PetscValidHeaderSpecific(tao,TAO_CLASSID,1);
PetscValidHeaderSpecific(X,VEC_CLASSID,2);
PetscValidHeaderSpecific(G,VEC_CLASSID,2);
PetscCheckSameComm(tao,1,X,2);
PetscCheckSameComm(tao,1,G,3);
if (tao->ops->computegradient) {
ierr = PetscLogEventBegin(Tao_GradientEval,tao,X,G,NULL);CHKERRQ(ierr);
PetscStackPush("Tao user gradient evaluation routine");
ierr = (*tao->ops->computegradient)(tao,X,G,tao->user_gradP);CHKERRQ(ierr);
PetscStackPop;
ierr = PetscLogEventEnd(Tao_GradientEval,tao,X,G,NULL);CHKERRQ(ierr);
tao->ngrads++;
} else if (tao->ops->computeobjectiveandgradient) {
ierr = PetscLogEventBegin(Tao_ObjGradientEval,tao,X,G,NULL);CHKERRQ(ierr);
PetscStackPush("Tao user objective/gradient evaluation routine");
ierr = (*tao->ops->computeobjectiveandgradient)(tao,X,&dummy,G,tao->user_objgradP);CHKERRQ(ierr);
PetscStackPop;
ierr = PetscLogEventEnd(Tao_ObjGradientEval,tao,X,G,NULL);CHKERRQ(ierr);
tao->nfuncgrads++;
} else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"TaoSetGradientRoutine() has not been called");
PetscFunctionReturn(0);
}
开发者ID:fengyuqi,项目名称:petsc,代码行数:47,代码来源:taosolver_fg.c
示例3: PCMGACycle_Private
PetscErrorCode PCMGACycle_Private(PC pc,PC_MG_Levels **mglevels)
{
PetscErrorCode ierr;
PetscInt i,l = mglevels[0]->levels;
PetscFunctionBegin;
/* compute RHS on each level */
for (i=l-1; i>0; i--) {
if (mglevels[i]->eventinterprestrict) {ierr = PetscLogEventBegin(mglevels[i]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
ierr = MatRestrict(mglevels[i]->restrct,mglevels[i]->b,mglevels[i-1]->b);CHKERRQ(ierr);
if (mglevels[i]->eventinterprestrict) {ierr = PetscLogEventEnd(mglevels[i]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
}
/* solve separately on each level */
for (i=0; i<l; i++) {
ierr = VecSet(mglevels[i]->x,0.0);CHKERRQ(ierr);
if (mglevels[i]->eventsmoothsolve) {ierr = PetscLogEventBegin(mglevels[i]->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
ierr = KSPSolve(mglevels[i]->smoothd,mglevels[i]->b,mglevels[i]->x);CHKERRQ(ierr);
ierr = KSPCheckSolve(mglevels[i]->smoothd,pc,mglevels[i]->x);CHKERRQ(ierr);
if (mglevels[i]->eventsmoothsolve) {ierr = PetscLogEventEnd(mglevels[i]->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
}
for (i=1; i<l; i++) {
if (mglevels[i]->eventinterprestrict) {ierr = PetscLogEventBegin(mglevels[i]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
ierr = MatInterpolateAdd(mglevels[i]->interpolate,mglevels[i-1]->x,mglevels[i]->x,mglevels[i]->x);CHKERRQ(ierr);
if (mglevels[i]->eventinterprestrict) {ierr = PetscLogEventEnd(mglevels[i]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
}
PetscFunctionReturn(0);
}
开发者ID:firedrakeproject,项目名称:petsc,代码行数:27,代码来源:smg.c
示例4: MatPtAP_SeqAIJ_SeqAIJ
PetscErrorCode MatPtAP_SeqAIJ_SeqAIJ(Mat A,Mat P,MatReuse scall,PetscReal fill,Mat *C)
{
PetscErrorCode ierr;
const char *algTypes[2] = {"scalable","nonscalable"};
PetscInt alg=0; /* set default algorithm */
PetscFunctionBegin;
if (scall == MAT_INITIAL_MATRIX) {
/*
Alg 'scalable' determines which implementations to be used:
"nonscalable": do dense axpy in MatPtAPNumeric() - fastest, but requires storage of struct A*P;
"scalable": do two sparse axpy in MatPtAPNumeric() - might slow, does not store structure of A*P.
*/
ierr = PetscObjectOptionsBegin((PetscObject)A);CHKERRQ(ierr);
ierr = PetscOptionsEList("-matptap_via","Algorithmic approach","MatPtAP",algTypes,2,algTypes[0],&alg,NULL);CHKERRQ(ierr);
ierr = PetscOptionsEnd();CHKERRQ(ierr);
ierr = PetscLogEventBegin(MAT_PtAPSymbolic,A,P,0,0);CHKERRQ(ierr);
switch (alg) {
case 1:
ierr = MatPtAPSymbolic_SeqAIJ_SeqAIJ_DenseAxpy(A,P,fill,C);CHKERRQ(ierr);
break;
default:
ierr = MatPtAPSymbolic_SeqAIJ_SeqAIJ_SparseAxpy(A,P,fill,C);CHKERRQ(ierr);
break;
}
ierr = PetscLogEventEnd(MAT_PtAPSymbolic,A,P,0,0);CHKERRQ(ierr);
}
ierr = PetscLogEventBegin(MAT_PtAPNumeric,A,P,0,0);CHKERRQ(ierr);
ierr = (*(*C)->ops->ptapnumeric)(A,P,*C);CHKERRQ(ierr);
ierr = PetscLogEventEnd(MAT_PtAPNumeric,A,P,0,0);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:00liujj,项目名称:petsc,代码行数:32,代码来源:matptap.c
示例5: PCMGKCycle_Private
PetscErrorCode PCMGKCycle_Private(PC pc,PC_MG_Levels **mglevels)
{
PetscErrorCode ierr;
PetscInt i,l = mglevels[0]->levels;
PetscFunctionBegin;
/* restrict the RHS through all levels to coarsest. */
for (i=l-1; i>0; i--){
if (mglevels[i]->eventinterprestrict) {ierr = PetscLogEventBegin(mglevels[i]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
ierr = MatRestrict(mglevels[i]->restrct,mglevels[i]->b,mglevels[i-1]->b);CHKERRQ(ierr);
if (mglevels[i]->eventinterprestrict) {ierr = PetscLogEventEnd(mglevels[i]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
}
/* work our way up through the levels */
ierr = VecSet(mglevels[0]->x,0.0);CHKERRQ(ierr);
for (i=0; i<l-1; i++) {
if (mglevels[i]->eventsmoothsolve) {ierr = PetscLogEventBegin(mglevels[i]->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
ierr = KSPSolve(mglevels[i]->smoothd,mglevels[i]->b,mglevels[i]->x);CHKERRQ(ierr);
if (mglevels[i]->eventsmoothsolve) {ierr = PetscLogEventEnd(mglevels[i]->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
if (mglevels[i+1]->eventinterprestrict) {ierr = PetscLogEventBegin(mglevels[i+1]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
ierr = MatInterpolate(mglevels[i+1]->interpolate,mglevels[i]->x,mglevels[i+1]->x);CHKERRQ(ierr);
if (mglevels[i+1]->eventinterprestrict) {ierr = PetscLogEventEnd(mglevels[i+1]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
}
if (mglevels[l-1]->eventsmoothsolve) {ierr = PetscLogEventBegin(mglevels[l-1]->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
ierr = KSPSolve(mglevels[l-1]->smoothd,mglevels[l-1]->b,mglevels[l-1]->x);CHKERRQ(ierr);
if (mglevels[l-1]->eventsmoothsolve) {ierr = PetscLogEventEnd(mglevels[l-1]->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
PetscFunctionReturn(0);
}
开发者ID:Kun-Qu,项目名称:petsc,代码行数:29,代码来源:fmg.c
示例6: F
/*
Performs the FAS coarse correction as:
fine problem: F(x) = b
coarse problem: F^c(x^c) = b^c
b^c = F^c(Rx) - R(F(x) - b)
*/
PetscErrorCode SNESFASCoarseCorrection(SNES snes, Vec X, Vec F, Vec X_new)
{
PetscErrorCode ierr;
Vec X_c, Xo_c, F_c, B_c;
SNESConvergedReason reason;
SNES next;
Mat restrct, interpolate;
SNES_FAS *fasc;
PetscFunctionBegin;
ierr = SNESFASCycleGetCorrection(snes, &next);CHKERRQ(ierr);
if (next) {
fasc = (SNES_FAS*)next->data;
ierr = SNESFASCycleGetRestriction(snes, &restrct);CHKERRQ(ierr);
ierr = SNESFASCycleGetInterpolation(snes, &interpolate);CHKERRQ(ierr);
X_c = next->vec_sol;
Xo_c = next->work[0];
F_c = next->vec_func;
B_c = next->vec_rhs;
if (fasc->eventinterprestrict) {ierr = PetscLogEventBegin(fasc->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
ierr = SNESFASRestrict(snes,X,Xo_c);CHKERRQ(ierr);
/* restrict the defect: R(F(x) - b) */
ierr = MatRestrict(restrct, F, B_c);CHKERRQ(ierr);
if (fasc->eventinterprestrict) {ierr = PetscLogEventEnd(fasc->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
if (fasc->eventresidual) {ierr = PetscLogEventBegin(fasc->eventresidual,0,0,0,0);CHKERRQ(ierr);}
/* F_c = F^c(Rx) - R(F(x) - b) since the second term was sitting in next->vec_rhs */
ierr = SNESComputeFunction(next, Xo_c, F_c);CHKERRQ(ierr);
if (fasc->eventresidual) {ierr = PetscLogEventEnd(fasc->eventresidual,0,0,0,0);CHKERRQ(ierr);}
/* solve the coarse problem corresponding to F^c(x^c) = b^c = F^c(Rx) - R(F(x) - b) */
ierr = VecCopy(B_c, X_c);CHKERRQ(ierr);
ierr = VecCopy(F_c, B_c);CHKERRQ(ierr);
ierr = VecCopy(X_c, F_c);CHKERRQ(ierr);
/* set initial guess of the coarse problem to the projected fine solution */
ierr = VecCopy(Xo_c, X_c);CHKERRQ(ierr);
/* recurse to the next level */
ierr = SNESSetInitialFunction(next, F_c);CHKERRQ(ierr);
ierr = SNESSolve(next, B_c, X_c);CHKERRQ(ierr);
ierr = SNESGetConvergedReason(next,&reason);CHKERRQ(ierr);
if (reason < 0 && reason != SNES_DIVERGED_MAX_IT) {
snes->reason = SNES_DIVERGED_INNER;
PetscFunctionReturn(0);
}
/* correct as x <- x + I(x^c - Rx)*/
ierr = VecAXPY(X_c, -1.0, Xo_c);CHKERRQ(ierr);
if (fasc->eventinterprestrict) {ierr = PetscLogEventBegin(fasc->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
ierr = MatInterpolateAdd(interpolate, X_c, X, X_new);CHKERRQ(ierr);
if (fasc->eventinterprestrict) {ierr = PetscLogEventEnd(fasc->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
}
PetscFunctionReturn(0);
}
开发者ID:fengyuqi,项目名称:petsc,代码行数:67,代码来源:fas.c
示例7: PCMGMCycle_Private
PetscErrorCode PCMGMCycle_Private(PC pc,PC_MG_Levels **mglevelsin,PCRichardsonConvergedReason *reason)
{
PC_MG *mg = (PC_MG*)pc->data;
PC_MG_Levels *mgc,*mglevels = *mglevelsin;
PetscErrorCode ierr;
PetscInt cycles = (mglevels->level == 1) ? 1 : (PetscInt) mglevels->cycles;
PC subpc;
PCFailedReason pcreason;
PetscFunctionBegin;
if (mglevels->eventsmoothsolve) {ierr = PetscLogEventBegin(mglevels->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
ierr = KSPSolve(mglevels->smoothd,mglevels->b,mglevels->x);CHKERRQ(ierr); /* pre-smooth */
ierr = KSPGetPC(mglevels->smoothd,&subpc);CHKERRQ(ierr);
ierr = PCGetSetUpFailedReason(subpc,&pcreason);CHKERRQ(ierr);
if (pcreason) {
pc->failedreason = PC_SUBPC_ERROR;
}
if (mglevels->eventsmoothsolve) {ierr = PetscLogEventEnd(mglevels->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
if (mglevels->level) { /* not the coarsest grid */
if (mglevels->eventresidual) {ierr = PetscLogEventBegin(mglevels->eventresidual,0,0,0,0);CHKERRQ(ierr);}
ierr = (*mglevels->residual)(mglevels->A,mglevels->b,mglevels->x,mglevels->r);CHKERRQ(ierr);
if (mglevels->eventresidual) {ierr = PetscLogEventEnd(mglevels->eventresidual,0,0,0,0);CHKERRQ(ierr);}
/* if on finest level and have convergence criteria set */
if (mglevels->level == mglevels->levels-1 && mg->ttol && reason) {
PetscReal rnorm;
ierr = VecNorm(mglevels->r,NORM_2,&rnorm);CHKERRQ(ierr);
if (rnorm <= mg->ttol) {
if (rnorm < mg->abstol) {
*reason = PCRICHARDSON_CONVERGED_ATOL;
ierr = PetscInfo2(pc,"Linear solver has converged. Residual norm %g is less than absolute tolerance %g\n",(double)rnorm,(double)mg->abstol);CHKERRQ(ierr);
} else {
*reason = PCRICHARDSON_CONVERGED_RTOL;
ierr = PetscInfo2(pc,"Linear solver has converged. Residual norm %g is less than relative tolerance times initial residual norm %g\n",(double)rnorm,(double)mg->ttol);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
}
mgc = *(mglevelsin - 1);
if (mglevels->eventinterprestrict) {ierr = PetscLogEventBegin(mglevels->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
ierr = MatRestrict(mglevels->restrct,mglevels->r,mgc->b);CHKERRQ(ierr);
if (mglevels->eventinterprestrict) {ierr = PetscLogEventEnd(mglevels->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
ierr = VecSet(mgc->x,0.0);CHKERRQ(ierr);
while (cycles--) {
ierr = PCMGMCycle_Private(pc,mglevelsin-1,reason);CHKERRQ(ierr);
}
if (mglevels->eventinterprestrict) {ierr = PetscLogEventBegin(mglevels->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
ierr = MatInterpolateAdd(mglevels->interpolate,mgc->x,mglevels->x,mglevels->x);CHKERRQ(ierr);
if (mglevels->eventinterprestrict) {ierr = PetscLogEventEnd(mglevels->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
if (mglevels->eventsmoothsolve) {ierr = PetscLogEventBegin(mglevels->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
ierr = KSPSolve(mglevels->smoothu,mglevels->b,mglevels->x);CHKERRQ(ierr); /* post smooth */
if (mglevels->eventsmoothsolve) {ierr = PetscLogEventEnd(mglevels->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
}
PetscFunctionReturn(0);
}
开发者ID:ziolai,项目名称:petsc,代码行数:56,代码来源:mg.c
示例8: SNESComputeFunction_DMDA
static PetscErrorCode SNESComputeFunction_DMDA(SNES snes,Vec X,Vec F,void *ctx)
{
PetscErrorCode ierr;
DM dm;
DMSNES_DA *dmdasnes = (DMSNES_DA*)ctx;
DMDALocalInfo info;
Vec Xloc;
void *x,*f;
PetscFunctionBegin;
PetscValidHeaderSpecific(snes,SNES_CLASSID,1);
PetscValidHeaderSpecific(X,VEC_CLASSID,2);
PetscValidHeaderSpecific(F,VEC_CLASSID,3);
if (!dmdasnes->residuallocal) SETERRQ(PetscObjectComm((PetscObject)snes),PETSC_ERR_PLIB,"Corrupt context");
ierr = SNESGetDM(snes,&dm);CHKERRQ(ierr);
ierr = DMGetLocalVector(dm,&Xloc);CHKERRQ(ierr);
ierr = DMGlobalToLocalBegin(dm,X,INSERT_VALUES,Xloc);CHKERRQ(ierr);
ierr = DMGlobalToLocalEnd(dm,X,INSERT_VALUES,Xloc);CHKERRQ(ierr);
ierr = DMDAGetLocalInfo(dm,&info);CHKERRQ(ierr);
ierr = DMDAVecGetArray(dm,Xloc,&x);CHKERRQ(ierr);
switch (dmdasnes->residuallocalimode) {
case INSERT_VALUES: {
ierr = DMDAVecGetArray(dm,F,&f);CHKERRQ(ierr);
ierr = PetscLogEventBegin(SNES_FunctionEval,snes,X,F,0);CHKERRQ(ierr);
CHKMEMQ;
ierr = (*dmdasnes->residuallocal)(&info,x,f,dmdasnes->residuallocalctx);CHKERRQ(ierr);
CHKMEMQ;
ierr = PetscLogEventEnd(SNES_FunctionEval,snes,X,F,0);CHKERRQ(ierr);
ierr = DMDAVecRestoreArray(dm,F,&f);CHKERRQ(ierr);
} break;
case ADD_VALUES: {
Vec Floc;
ierr = DMGetLocalVector(dm,&Floc);CHKERRQ(ierr);
ierr = VecZeroEntries(Floc);CHKERRQ(ierr);
ierr = DMDAVecGetArray(dm,Floc,&f);CHKERRQ(ierr);
ierr = PetscLogEventBegin(SNES_FunctionEval,snes,X,F,0);CHKERRQ(ierr);
CHKMEMQ;
ierr = (*dmdasnes->residuallocal)(&info,x,f,dmdasnes->residuallocalctx);CHKERRQ(ierr);
CHKMEMQ;
ierr = PetscLogEventEnd(SNES_FunctionEval,snes,X,F,0);CHKERRQ(ierr);
ierr = DMDAVecRestoreArray(dm,Floc,&f);CHKERRQ(ierr);
ierr = VecZeroEntries(F);CHKERRQ(ierr);
ierr = DMLocalToGlobalBegin(dm,Floc,ADD_VALUES,F);CHKERRQ(ierr);
ierr = DMLocalToGlobalEnd(dm,Floc,ADD_VALUES,F);CHKERRQ(ierr);
ierr = DMRestoreLocalVector(dm,&Floc);CHKERRQ(ierr);
} break;
default: SETERRQ1(PetscObjectComm((PetscObject)snes),PETSC_ERR_ARG_INCOMP,"Cannot use imode=%d",(int)dmdasnes->residuallocalimode);
}
ierr = DMDAVecRestoreArray(dm,Xloc,&x);CHKERRQ(ierr);
ierr = DMRestoreLocalVector(dm,&Xloc);CHKERRQ(ierr);
if (snes->domainerror) {
ierr = VecSetInf(F);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
开发者ID:plguhur,项目名称:petsc,代码行数:55,代码来源:dmdasnes.c
示例9: TaoComputeObjectiveAndGradient
/*@
TaoComputeObjectiveAndGradient - Computes the objective function value at a given point
Collective on Tao
Input Parameters:
+ tao - the Tao context
- X - input vector
Output Parameter:
+ f - Objective value at X
- g - Gradient vector at X
Notes: TaoComputeObjectiveAndGradient() is typically used within minimization implementations,
so most users would not generally call this routine themselves.
Level: advanced
.seealso: TaoComputeGradient(), TaoComputeObjectiveAndGradient(), TaoSetObjectiveRoutine()
@*/
PetscErrorCode TaoComputeObjectiveAndGradient(Tao tao, Vec X, PetscReal *f, Vec G)
{
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidHeaderSpecific(tao,TAO_CLASSID,1);
PetscValidHeaderSpecific(X,VEC_CLASSID,2);
PetscValidHeaderSpecific(G,VEC_CLASSID,4);
PetscCheckSameComm(tao,1,X,2);
PetscCheckSameComm(tao,1,G,4);
if (tao->ops->computeobjectiveandgradient) {
ierr = PetscLogEventBegin(Tao_ObjGradientEval,tao,X,G,NULL);
CHKERRQ(ierr);
PetscStackPush("Tao user objective/gradient evaluation routine");
ierr = (*tao->ops->computeobjectiveandgradient)(tao,X,f,G,tao->user_objgradP);
CHKERRQ(ierr);
PetscStackPop;
if (tao->ops->computegradient == TaoDefaultComputeGradient) {
/* Overwrite gradient with finite difference gradient */
ierr = TaoDefaultComputeGradient(tao,X,G,tao->user_objgradP);
CHKERRQ(ierr);
}
ierr = PetscLogEventEnd(Tao_ObjGradientEval,tao,X,G,NULL);
CHKERRQ(ierr);
tao->nfuncgrads++;
} else if (tao->ops->computeobjective && tao->ops->computegradient) {
ierr = PetscLogEventBegin(Tao_ObjectiveEval,tao,X,NULL,NULL);
CHKERRQ(ierr);
PetscStackPush("Tao user objective evaluation routine");
ierr = (*tao->ops->computeobjective)(tao,X,f,tao->user_objP);
CHKERRQ(ierr);
PetscStackPop;
ierr = PetscLogEventEnd(Tao_ObjectiveEval,tao,X,NULL,NULL);
CHKERRQ(ierr);
tao->nfuncs++;
ierr = PetscLogEventBegin(Tao_GradientEval,tao,X,G,NULL);
CHKERRQ(ierr);
PetscStackPush("Tao user gradient evaluation routine");
ierr = (*tao->ops->computegradient)(tao,X,G,tao->user_gradP);
CHKERRQ(ierr);
PetscStackPop;
ierr = PetscLogEventEnd(Tao_GradientEval,tao,X,G,NULL);
CHKERRQ(ierr);
tao->ngrads++;
} else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"TaoSetObjectiveRoutine() or TaoSetGradientRoutine() not set");
ierr = PetscInfo1(tao,"TAO Function evaluation: %14.12e\n",(double)(*f));
CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:petsc,项目名称:petsc,代码行数:69,代码来源:taosolver_fg.c
示例10: MatPtAP_SeqAIJ_SeqAIJ
PetscErrorCode MatPtAP_SeqAIJ_SeqAIJ(Mat A,Mat P,MatReuse scall,PetscReal fill,Mat *C)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if (scall == MAT_INITIAL_MATRIX) {
ierr = PetscLogEventBegin(MAT_PtAPSymbolic,A,P,0,0);CHKERRQ(ierr);
ierr = MatPtAPSymbolic_SeqAIJ_SeqAIJ(A,P,fill,C);CHKERRQ(ierr);
ierr = PetscLogEventEnd(MAT_PtAPSymbolic,A,P,0,0);CHKERRQ(ierr);
}
ierr = PetscLogEventBegin(MAT_PtAPNumeric,A,P,0,0);CHKERRQ(ierr);
ierr = (*(*C)->ops->ptapnumeric)(A,P,*C);CHKERRQ(ierr);
ierr = PetscLogEventEnd(MAT_PtAPNumeric,A,P,0,0);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:feelpp,项目名称:debian-petsc,代码行数:15,代码来源:matptap.c
示例11: MatTransposeMatMult_SeqAIJ_SeqDense
PetscErrorCode MatTransposeMatMult_SeqAIJ_SeqDense(Mat A,Mat B,MatReuse scall,PetscReal fill,Mat *C)
{
PetscErrorCode ierr;
PetscFunctionBegin;
if (scall == MAT_INITIAL_MATRIX) {
ierr = PetscLogEventBegin(MAT_TransposeMatMultSymbolic,A,B,0,0);CHKERRQ(ierr);
ierr = MatTransposeMatMultSymbolic_SeqAIJ_SeqDense(A,B,fill,C);CHKERRQ(ierr);
ierr = PetscLogEventEnd(MAT_TransposeMatMultSymbolic,A,B,0,0);CHKERRQ(ierr);
}
ierr = PetscLogEventBegin(MAT_TransposeMatMultNumeric,A,B,0,0);CHKERRQ(ierr);
ierr = MatTransposeMatMultNumeric_SeqAIJ_SeqDense(A,B,*C);CHKERRQ(ierr);
ierr = PetscLogEventEnd(MAT_TransposeMatMultNumeric,A,B,0,0);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:00liujj,项目名称:petsc,代码行数:15,代码来源:mattransposematmult.c
示例12: MatColoringCreate
/*@
MatColoringApply - Apply the coloring to the matrix, producing index
sets corresponding to a number of independent sets in the induced
graph.
Collective on MatColoring
Input Parameters:
. mc - the MatColoring context
Output Parameter:
. coloring - the ISColoring instance containing the coloring
Level: beginner
.keywords: Coloring, Apply
.seealso: MatColoring, MatColoringCreate()
@*/
PetscErrorCode MatColoringApply(MatColoring mc,ISColoring *coloring)
{
PetscErrorCode ierr;
PetscBool flg;
PetscViewerFormat format;
PetscViewer viewer;
PetscInt nc,ncolors;
PetscFunctionBegin;
PetscValidHeaderSpecific(mc,MAT_COLORING_CLASSID,1);
ierr = PetscLogEventBegin(Mat_Coloring_Apply,mc,0,0,0);CHKERRQ(ierr);
ierr = (*mc->ops->apply)(mc,coloring);CHKERRQ(ierr);
ierr = PetscLogEventEnd(Mat_Coloring_Apply,mc,0,0,0);CHKERRQ(ierr);
/* valid */
if (mc->valid) {
ierr = MatColoringTestValid(mc,*coloring);CHKERRQ(ierr);
}
/* view */
ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)mc),((PetscObject)mc)->prefix,"-mat_coloring_view",&viewer,&format,&flg);CHKERRQ(ierr);
if (flg && !PetscPreLoadingOn) {
ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
ierr = MatColoringView(mc,viewer);CHKERRQ(ierr);
ierr = MatGetSize(mc->mat,NULL,&nc);CHKERRQ(ierr);
ierr = ISColoringGetIS(*coloring,&ncolors,NULL);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer," Number of colors %d\n",ncolors);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer," Number of total columns %d\n",nc);CHKERRQ(ierr);
if (nc <= 1000) {ierr = ISColoringView(*coloring,viewer);CHKERRQ(ierr);}
ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
开发者ID:00liujj,项目名称:petsc,代码行数:51,代码来源:matcoloring.c
示例13: DMPlexDistribute
/*@
DMPlexDistributeField - Distribute field data to match a given PetscSF, usually the SF from mesh distribution
Collective on DM
Input Parameters:
+ dm - The DMPlex object
. pointSF - The PetscSF describing the communication pattern
. originalSection - The PetscSection for existing data layout
- originalVec - The existing data
Output Parameters:
+ newSection - The PetscSF describing the new data layout
- newVec - The new data
Level: developer
.seealso: DMPlexDistribute(), DMPlexDistributeData()
@*/
PetscErrorCode DMPlexDistributeField(DM dm, PetscSF pointSF, PetscSection originalSection, Vec originalVec, PetscSection newSection, Vec newVec)
{
PetscSF fieldSF;
PetscInt *remoteOffsets, fieldSize;
PetscScalar *originalValues, *newValues;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscLogEventBegin(DMPLEX_DistributeField,dm,0,0,0);CHKERRQ(ierr);
ierr = PetscSFDistributeSection(pointSF, originalSection, &remoteOffsets, newSection);CHKERRQ(ierr);
ierr = PetscSectionGetStorageSize(newSection, &fieldSize);CHKERRQ(ierr);
ierr = VecSetSizes(newVec, fieldSize, PETSC_DETERMINE);CHKERRQ(ierr);
ierr = VecSetType(newVec,dm->vectype);CHKERRQ(ierr);
ierr = VecGetArray(originalVec, &originalValues);CHKERRQ(ierr);
ierr = VecGetArray(newVec, &newValues);CHKERRQ(ierr);
ierr = PetscSFCreateSectionSF(pointSF, originalSection, remoteOffsets, newSection, &fieldSF);CHKERRQ(ierr);
ierr = PetscSFBcastBegin(fieldSF, MPIU_SCALAR, originalValues, newValues);CHKERRQ(ierr);
ierr = PetscSFBcastEnd(fieldSF, MPIU_SCALAR, originalValues, newValues);CHKERRQ(ierr);
ierr = PetscSFDestroy(&fieldSF);CHKERRQ(ierr);
ierr = VecRestoreArray(newVec, &newValues);CHKERRQ(ierr);
ierr = VecRestoreArray(originalVec, &originalValues);CHKERRQ(ierr);
ierr = PetscLogEventEnd(DMPLEX_DistributeField,dm,0,0,0);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:OpenCMISS-Dependencies,项目名称:petsc,代码行数:45,代码来源:plexdistribute.c
示例14: go
/*@
VecMTDotBegin - Starts a split phase transpose multiple dot product computation.
Input Parameters:
+ x - the first vector
. nv - number of vectors
. y - array of vectors
- result - where the result will go (can be PETSC_NULL)
Level: advanced
Notes:
Each call to VecMTDotBegin() should be paired with a call to VecMTDotEnd().
.seealso: VecMTDotEnd(), VecNormBegin(), VecNormEnd(), VecNorm(), VecDot(), VecMDot(),
VecDotBegin(), VecDotEnd(), VecMDotBegin(), VecMDotEnd(), PetscCommSplitReductionBegin()
@*/
PetscErrorCode VecMTDotBegin(Vec x,PetscInt nv,const Vec y[],PetscScalar result[])
{
PetscErrorCode ierr;
PetscSplitReduction *sr;
MPI_Comm comm;
int i;
PetscFunctionBegin;
ierr = PetscObjectGetComm((PetscObject)x,&comm);CHKERRQ(ierr);
ierr = PetscSplitReductionGet(comm,&sr);CHKERRQ(ierr);
if (sr->state != STATE_BEGIN) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Called before all VecxxxEnd() called");
for (i=0;i<nv;i++) {
if (sr->numopsbegin+i >= sr->maxops) {
ierr = PetscSplitReductionExtend(sr);CHKERRQ(ierr);
}
sr->reducetype[sr->numopsbegin+i] = REDUCE_SUM;
sr->invecs[sr->numopsbegin+i] = (void*)x;
}
if (!x->ops->mtdot_local) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Vector does not suppport local mdots");
ierr = PetscLogEventBegin(VEC_ReduceArithmetic,0,0,0,0);CHKERRQ(ierr);
ierr = (*x->ops->mdot_local)(x,nv,y,sr->lvalues+sr->numopsbegin);CHKERRQ(ierr);
ierr = PetscLogEventEnd(VEC_ReduceArithmetic,0,0,0,0);CHKERRQ(ierr);
sr->numopsbegin += nv;
PetscFunctionReturn(0);
}
开发者ID:Kun-Qu,项目名称:petsc,代码行数:43,代码来源:comb.c
示例15: VecLoad_Default
PetscErrorCode VecLoad_Default(Vec newvec, PetscViewer viewer)
{
PetscErrorCode ierr;
PetscBool isbinary;
#if defined(PETSC_HAVE_HDF5)
PetscBool ishdf5;
#endif
PetscFunctionBegin;
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr);
#if defined(PETSC_HAVE_HDF5)
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERHDF5,&ishdf5);CHKERRQ(ierr);
#endif
#if defined(PETSC_HAVE_HDF5)
if (ishdf5) {
if (!((PetscObject)newvec)->name) {
SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Since HDF5 format gives ASCII name for each object in file; must use VecLoad() after setting name of Vec with PetscObjectSetName()");
ierr = PetscLogEventEnd(VEC_Load,viewer,0,0,0);CHKERRQ(ierr);
}
ierr = VecLoad_HDF5(newvec, viewer);CHKERRQ(ierr);
} else
#endif
{
ierr = VecLoad_Binary(newvec, viewer);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
开发者ID:feelpp,项目名称:debian-petsc,代码行数:28,代码来源:vecio.c
示例16: SUBSET_NONZERO_PATTERN
/*@
MatAXPY - Computes Y = a*X + Y.
Logically Collective on Mat
Input Parameters:
+ a - the scalar multiplier
. X - the first matrix
. Y - the second matrix
- str - either SAME_NONZERO_PATTERN, DIFFERENT_NONZERO_PATTERN
or SUBSET_NONZERO_PATTERN (nonzeros of X is a subset of Y's)
Level: intermediate
.keywords: matrix, add
.seealso: MatAYPX()
@*/
PetscErrorCode MatAXPY(Mat Y,PetscScalar a,Mat X,MatStructure str)
{
PetscErrorCode ierr;
PetscInt m1,m2,n1,n2;
PetscFunctionBegin;
PetscValidHeaderSpecific(X,MAT_CLASSID,3);
PetscValidHeaderSpecific(Y,MAT_CLASSID,1);
PetscValidLogicalCollectiveScalar(Y,a,2);
ierr = MatGetSize(X,&m1,&n1);CHKERRQ(ierr);
ierr = MatGetSize(Y,&m2,&n2);CHKERRQ(ierr);
if (m1 != m2 || n1 != n2) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"Non conforming matrix add: %D %D %D %D",m1,m2,n1,n2);
ierr = PetscLogEventBegin(MAT_AXPY,Y,0,0,0);CHKERRQ(ierr);
if (Y->ops->axpy) {
ierr = (*Y->ops->axpy)(Y,a,X,str);CHKERRQ(ierr);
} else {
ierr = MatAXPY_Basic(Y,a,X,str);CHKERRQ(ierr);
}
ierr = PetscLogEventEnd(MAT_AXPY,Y,0,0,0);CHKERRQ(ierr);
#if defined(PETSC_HAVE_CUSP)
if (Y->valid_GPU_matrix != PETSC_CUSP_UNALLOCATED) {
Y->valid_GPU_matrix = PETSC_CUSP_CPU;
}
#endif
PetscFunctionReturn(0);
}
开发者ID:feelpp,项目名称:debian-petsc,代码行数:45,代码来源:axpy.c
示例17: PCGAMGgraph_GEO
PetscErrorCode PCGAMGgraph_GEO(PC pc,const Mat Amat,Mat *a_Gmat)
{
PetscErrorCode ierr;
PC_MG *mg = (PC_MG*)pc->data;
PC_GAMG *pc_gamg = (PC_GAMG*)mg->innerctx;
const PetscInt verbose = pc_gamg->verbose;
const PetscReal vfilter = pc_gamg->threshold;
PetscMPIInt rank,size;
MPI_Comm comm;
Mat Gmat;
PetscBool set,flg,symm;
PetscFunctionBegin;
ierr = PetscObjectGetComm((PetscObject)Amat,&comm);CHKERRQ(ierr);
#if defined PETSC_USE_LOG
ierr = PetscLogEventBegin(PC_GAMGGgraph_GEO,0,0,0,0);CHKERRQ(ierr);
#endif
ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr);
ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr);
ierr = MatIsSymmetricKnown(Amat, &set, &flg);CHKERRQ(ierr);
symm = (PetscBool)!(set && flg);
ierr = PCGAMGCreateGraph(Amat, &Gmat);CHKERRQ(ierr);
ierr = PCGAMGFilterGraph(&Gmat, vfilter, symm, verbose);CHKERRQ(ierr);
*a_Gmat = Gmat;
#if defined PETSC_USE_LOG
ierr = PetscLogEventEnd(PC_GAMGGgraph_GEO,0,0,0,0);CHKERRQ(ierr);
#endif
PetscFunctionReturn(0);
}
开发者ID:00liujj,项目名称:petsc,代码行数:32,代码来源:geo.c
示例18: FluidFieldDivergence
PetscErrorCode FluidFieldDivergence(FluidField f)
{
DALocalInfo info;
Vec u,v,w; // Local, ghosted vectors
PetscErrorCode ierr;
PetscFunctionBegin;
PetscLogEventBegin(EVENT_FluidFieldDivergence,0,0,0,0);
// PetscLogEventRegister(&EVENT_FluidFieldDivergence,"FluidFieldDivergence", 0);
ierr = DAGetLocalInfo(f->da,&info); CHKERRQ(ierr);
ierr = DAGetLocalVector(f->da,&u); CHKERRQ(ierr);
ierr = DAGetLocalVector(f->da,&v); CHKERRQ(ierr);
ierr = DAGlobalToLocalBegin(f->da,f->u,INSERT_VALUES,u); CHKERRQ(ierr);
ierr = DAGlobalToLocalEnd( f->da,f->u,INSERT_VALUES,u); CHKERRQ(ierr);
ierr = DAGlobalToLocalBegin(f->da,f->v,INSERT_VALUES,v); CHKERRQ(ierr);
//TODO: interleaving work with communication here a possible source of optimization?
ierr = DAGlobalToLocalEnd( f->da,f->v,INSERT_VALUES,v); CHKERRQ(ierr);
if( f->is3D )
{
ierr = DAGetLocalVector(f->da,&w); CHKERRQ(ierr);
ierr = DAGlobalToLocalBegin(f->da,f->w,INSERT_VALUES,w); CHKERRQ(ierr);
ierr = DAGlobalToLocalEnd( f->da,f->w,INSERT_VALUES,w); CHKERRQ(ierr);
FluidFieldDivergence_3D(info, f->d, u, v, w, f->div);
ierr = DARestoreLocalVector(f->da,&w); CHKERRQ(ierr);
} else {
FluidFieldDivergence_2D(info, f->d, u, v, f->div);
}
ierr = DARestoreLocalVector(f->da,&u); CHKERRQ(ierr);
ierr = DARestoreLocalVector(f->da,&v); CHKERRQ(ierr);
PetscLogEventEnd(EVENT_FluidFieldDivergence,0,0,0,0);
PetscFunctionReturn(0);
}
开发者ID:adrielb,项目名称:DCell,代码行数:34,代码来源:Divergence.c
示例19: SNESFASDownSmooth_Private
/*
Defines the action of the downsmoother
*/
PetscErrorCode SNESFASDownSmooth_Private(SNES snes, Vec B, Vec X, Vec F, PetscReal *fnorm)
{
PetscErrorCode ierr = 0;
SNESConvergedReason reason;
Vec FPC;
SNES smoothd;
SNES_FAS *fas = (SNES_FAS*) snes->data;
PetscFunctionBegin;
ierr = SNESFASCycleGetSmootherDown(snes, &smoothd);CHKERRQ(ierr);
ierr = SNESSetInitialFunction(smoothd, F);CHKERRQ(ierr);
if (fas->eventsmoothsolve) {ierr = PetscLogEventBegin(fas->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
ierr = SNESSolve(smoothd, B, X);CHKERRQ(ierr);
if (fas->eventsmoothsolve) {ierr = PetscLogEventEnd(fas->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
/* check convergence reason for the smoother */
ierr = SNESGetConvergedReason(smoothd,&reason);CHKERRQ(ierr);
if (reason < 0 && !(reason == SNES_DIVERGED_MAX_IT || reason == SNES_DIVERGED_LOCAL_MIN || reason == SNES_DIVERGED_LINE_SEARCH)) {
snes->reason = SNES_DIVERGED_INNER;
PetscFunctionReturn(0);
}
ierr = SNESGetFunction(smoothd, &FPC, NULL, NULL);CHKERRQ(ierr);
ierr = VecCopy(FPC, F);CHKERRQ(ierr);
if (fnorm) {ierr = VecNorm(F,NORM_2,fnorm);CHKERRQ(ierr);}
PetscFunctionReturn(0);
}
开发者ID:fengyuqi,项目名称:petsc,代码行数:28,代码来源:fas.c
示例20: DMPlexUninterpolate
/*@
DMPlexInterpolate - Take in a cell-vertex mesh and return one with all intermediate faces, edges, etc.
Collective on DM
Input Parameter:
. dm - The DMPlex object with only cells and vertices
Output Parameter:
. dmInt - The complete DMPlex object
Level: intermediate
.keywords: mesh
.seealso: DMPlexUninterpolate(), DMPlexCreateFromCellList()
@*/
PetscErrorCode DMPlexInterpolate(DM dm, DM *dmInt)
{
DM idm, odm = dm;
PetscInt depth, dim, d;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscLogEventBegin(DMPLEX_Interpolate,dm,0,0,0);CHKERRQ(ierr);
ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr);
ierr = DMPlexGetDimension(dm, &dim);CHKERRQ(ierr);
if (dim <= 1) {
ierr = PetscObjectReference((PetscObject) dm);CHKERRQ(ierr);
idm = dm;
}
for (d = 1; d < dim; ++d) {
/* Create interpolated mesh */
ierr = DMCreate(PetscObjectComm((PetscObject)dm), &idm);CHKERRQ(ierr);
ierr = DMSetType(idm, DMPLEX);CHKERRQ(ierr);
ierr = DMPlexSetDimension(idm, dim);CHKERRQ(ierr);
if (depth > 0) {ierr = DMPlexInterpolateFaces_Internal(odm, 1, idm);CHKERRQ(ierr);}
if (odm != dm) {ierr = DMDestroy(&odm);CHKERRQ(ierr);}
odm = idm;
}
*dmInt = idm;
ierr = PetscLogEventEnd(DMPLEX_Interpolate,dm,0,0,0);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:ZJLi2013,项目名称:petsc,代码行数:43,代码来源:plexinterpolate.c
注:本文中的PetscLogEventEnd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论