PetscErrorCode main(int argc,char **argv) { PetscErrorCode ierr; /* used to check for functions returning nonzeros */ PetscMPIInt size; Vec x; /* solution */ KSP ksp; PC pc; Vec ceq,cin; PetscBool flg; /* A return value when checking for use options */ Tao tao; /* Tao solver context */ TaoConvergedReason reason; AppCtx user; /* application context */ /* Initialize TAO,PETSc */ ierr = PetscInitialize(&argc,&argv,(char *)0,help);CHKERRQ(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr); /* Specify default parameters for the problem, check for command-line overrides */ ierr = PetscStrncpy(user.name,"HS21",8);CHKERRQ(ierr); ierr = PetscOptionsGetString(NULL,NULL,"-cutername",user.name,24,&flg);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\n---- MAROS Problem %s -----\n",user.name);CHKERRQ(ierr); ierr = InitializeProblem(&user);CHKERRQ(ierr); ierr = VecDuplicate(user.d,&x);CHKERRQ(ierr); ierr = VecDuplicate(user.beq,&ceq);CHKERRQ(ierr); ierr = VecDuplicate(user.bin,&cin);CHKERRQ(ierr); ierr = VecSet(x,1.0);CHKERRQ(ierr); ierr = TaoCreate(PETSC_COMM_WORLD,&tao);CHKERRQ(ierr); ierr = TaoSetType(tao,TAOIPM);CHKERRQ(ierr); ierr = TaoSetInitialVector(tao,x);CHKERRQ(ierr); ierr = TaoSetObjectiveAndGradientRoutine(tao,FormFunctionGradient,(void*)&user);CHKERRQ(ierr); ierr = TaoSetEqualityConstraintsRoutine(tao,ceq,FormEqualityConstraints,(void*)&user);CHKERRQ(ierr); ierr = TaoSetInequalityConstraintsRoutine(tao,cin,FormInequalityConstraints,(void*)&user);CHKERRQ(ierr); ierr = TaoSetInequalityBounds(tao,user.bin,NULL);CHKERRQ(ierr); ierr = TaoSetJacobianEqualityRoutine(tao,user.Aeq,user.Aeq,FormEqualityJacobian,(void*)&user);CHKERRQ(ierr); ierr = TaoSetJacobianInequalityRoutine(tao,user.Ain,user.Ain,FormInequalityJacobian,(void*)&user);CHKERRQ(ierr); ierr = TaoSetHessianRoutine(tao,user.H,user.H,FormHessian,(void*)&user);CHKERRQ(ierr); ierr = TaoGetKSP(tao,&ksp);CHKERRQ(ierr); ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr); ierr = PCSetType(pc,PCLU);CHKERRQ(ierr); /* This algorithm produces matrices with zeros along the diagonal therefore we need to use SuperLU which does partial pivoting */ ierr = PCFactorSetMatSolverPackage(pc,MATSOLVERSUPERLU);CHKERRQ(ierr); ierr = KSPSetType(ksp,KSPPREONLY);CHKERRQ(ierr); ierr = TaoSetTolerances(tao,0,0,0);CHKERRQ(ierr); ierr = TaoSetFromOptions(tao);CHKERRQ(ierr); ierr = TaoSolve(tao);CHKERRQ(ierr); ierr = TaoGetConvergedReason(tao,&reason);CHKERRQ(ierr); if (reason < 0) { ierr = PetscPrintf(MPI_COMM_WORLD, "TAO failed to converge due to %s.\n",TaoConvergedReasons[reason]);CHKERRQ(ierr); } else { ierr = PetscPrintf(MPI_COMM_WORLD, "Optimization completed with status %s.\n",TaoConvergedReasons[reason]);CHKERRQ(ierr); } ierr = DestroyProblem(&user);CHKERRQ(ierr); ierr = VecDestroy(&x);CHKERRQ(ierr); ierr = VecDestroy(&ceq);CHKERRQ(ierr); ierr = VecDestroy(&cin);CHKERRQ(ierr); ierr = TaoDestroy(&tao);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }
PETSC_EXTERN void PETSC_STDCALL taosetinequalitybounds_(Tao tao,Vec IL,Vec IU, int *__ierr ){ *__ierr = TaoSetInequalityBounds( (Tao)PetscToPointer((tao) ), (Vec)PetscToPointer((IL) ), (Vec)PetscToPointer((IU) )); }