Actual source code: xmonitor.c

      1: #include "tao.h"
      2: #include "petscdraw.h"

      4: typedef struct{
      5:   PetscLogDouble t0;
      6:   PetscDraw Draw1,Draw2;
      7:   PetscDrawLG LG1,LG2;
      8:   TAO_SOLVER tao;
      9: }TaoXMonitor;

     11: int TaoPetscXMonitor(TAO_SOLVER, void *);
     12: int DestroyTaoPetscXMonitor(void *);

     15: int TaoSetPetscXMonitor(TAO_SOLVER tao){
     16:   int info;
     17:   TaoXMonitor *mctx;
     19:   PetscNew(TaoXMonitor,&mctx);
     20:   mctx->tao=tao;
     21:   info=TaoSetMonitor(tao,TaoPetscXMonitor,(void*)mctx); CHKERRQ(info);
     22:   info=TaoSetDestroyRoutine(tao,DestroyTaoPetscXMonitor,(void*)mctx); CHKERRQ(info);
     23:   return(0);
     24: }

     26: int TaoPetscXMonitor(TAO_SOLVER ttao, void *mctx){
     27:   TaoXMonitor *mntr = (TaoXMonitor*) mctx;
     28:   TAO_SOLVER  tao= mntr->tao;
     29:   int info,iter,rank=0;
     30:   char display[51];
     31:   PetscLogDouble t1;
     32:   PetscReal t2,fff;
     33:   double ff,Norm1,norm2,norm3;
     34:   TaoTerminateReason reason;
     35:   PetscTruth flag;

     39:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
     40:
     41:   if (rank){
     42:     return(0);
     43:   }

     46:   info = TaoGetSolutionStatus(tao,&iter,&ff,&Norm1,&norm2,&norm3,&reason);CHKERRQ(info);

     48:   if (iter==0){
     49:     info = PetscOptionsGetenv(PETSC_COMM_WORLD,"DISPLAY",display,50,&flag);
     50:     CHKERRQ(info);
     51:     info = PetscDrawCreate(PETSC_COMM_WORLD,display,
     52:                       "Function Value",
     53:                       0,0,500,150,&mntr->Draw1);CHKERRQ(info);
     54:     info = PetscDrawCreate(PETSC_COMM_WORLD,display,
     55:                       "Residual of Optimality Conditions",
     56:                       0,175,500,150,&mntr->Draw2);CHKERRQ(info);
     57:     info = PetscDrawSetFromOptions(mntr->Draw1); CHKERRQ(info);
     58:     info = PetscDrawSetFromOptions(mntr->Draw2); CHKERRQ(info);
     59:     info = PetscDrawLGCreate(mntr->Draw1,1,&mntr->LG1); CHKERRQ(info);
     60:     info = PetscDrawLGCreate(mntr->Draw2,1,&mntr->LG2); CHKERRQ(info);
     61:     info = PetscGetCPUTime(&mntr->t0); CHKERRQ(info);
     62:   }

     64:   info = PetscGetCPUTime(&t1); CHKERRQ(info);
     65:   t1 = t1 - mntr->t0;
     66:   t2=t1;
     67:   fff=ff;
     68:   info = PetscDrawLGAddPoint(mntr->LG1,&t2,&fff); CHKERRQ(info);
     69:   info = PetscDrawLGDraw(mntr->LG1); CHKERRQ(info);
     70:   fff=Norm1;
     71:   info = PetscDrawLGAddPoint(mntr->LG2,&t2,&fff); CHKERRQ(info);
     72:   info = PetscDrawLGDraw(mntr->LG2); CHKERRQ(info);

     74:   return(0);
     75: }

     79: int DestroyTaoPetscXMonitor(void *ctx){

     81:   TaoXMonitor * mntr = (TaoXMonitor *) ctx;
     82:   int info;

     85:   info = PetscSleep(-1); CHKERRQ(info);
     86:   info =  PetscDrawLGDestroy(mntr->LG1); CHKERRQ(info);
     87:   info =  PetscDrawLGDestroy(mntr->LG2); CHKERRQ(info);
     88:   info =  PetscDrawDestroy(mntr->Draw1); CHKERRQ(info);
     89:   info =  PetscDrawDestroy(mntr->Draw2); CHKERRQ(info);
     90:   info = PetscFree(ctx); CHKERRQ(info);
     91:   return(0);
     92: }