1ba92ff59SBarry Smith #include <petsctaolinesearch.h> /*I "petsctaolinesearch.h" I*/ 2aaa7dc30SBarry Smith #include <petsc-private/taolinesearchimpl.h> 30c52818fSSatish Balay 40c52818fSSatish Balay PetscBool TaoLineSearchInitialized = PETSC_FALSE; 56c23d075SBarry Smith PetscFunctionList TaoLineSearchList = NULL; 60c52818fSSatish Balay 70c52818fSSatish Balay PetscClassId TAOLINESEARCH_CLASSID=0; 80c52818fSSatish Balay PetscLogEvent TaoLineSearch_ApplyEvent = 0, TaoLineSearch_EvalEvent=0; 90c52818fSSatish Balay 100c52818fSSatish Balay #undef __FUNCT__ 110c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchView" 120c52818fSSatish Balay /*@C 130c52818fSSatish Balay TaoLineSearchView - Prints information about the TaoLineSearch 140c52818fSSatish Balay 150c52818fSSatish Balay Collective on TaoLineSearch 160c52818fSSatish Balay 170c52818fSSatish Balay InputParameters: 18441846f8SBarry Smith + ls - the Tao context 190c52818fSSatish Balay - viewer - visualization context 200c52818fSSatish Balay 210c52818fSSatish Balay Options Database Key: 220c52818fSSatish Balay . -tao_ls_view - Calls TaoLineSearchView() at the end of each line search 230c52818fSSatish Balay 240c52818fSSatish Balay Notes: 250c52818fSSatish Balay The available visualization contexts include 260c52818fSSatish Balay + PETSC_VIEWER_STDOUT_SELF - standard output (default) 270c52818fSSatish Balay - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 280c52818fSSatish Balay output where only the first processor opens 290c52818fSSatish Balay the file. All other processors send their 300c52818fSSatish Balay data to the first processor to print. 310c52818fSSatish Balay 320c52818fSSatish Balay Level: beginner 330c52818fSSatish Balay 340c52818fSSatish Balay .seealso: PetscViewerASCIIOpen() 350c52818fSSatish Balay @*/ 360c52818fSSatish Balay 370c52818fSSatish Balay PetscErrorCode TaoLineSearchView(TaoLineSearch ls, PetscViewer viewer) 380c52818fSSatish Balay { 390c52818fSSatish Balay PetscErrorCode ierr; 400c52818fSSatish Balay PetscBool isascii, isstring; 410c52818fSSatish Balay const TaoLineSearchType type; 420c52818fSSatish Balay PetscBool destroyviewer = PETSC_FALSE; 43f06e3bfaSBarry Smith 440c52818fSSatish Balay PetscFunctionBegin; 450c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 460c52818fSSatish Balay if (!viewer) { 470c52818fSSatish Balay destroyviewer = PETSC_TRUE; 480c52818fSSatish Balay ierr = PetscViewerASCIIGetStdout(((PetscObject)ls)->comm, &viewer);CHKERRQ(ierr); 490c52818fSSatish Balay } 500c52818fSSatish Balay PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 510c52818fSSatish Balay PetscCheckSameComm(ls,1,viewer,2); 520c52818fSSatish Balay 530c52818fSSatish Balay ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr); 540c52818fSSatish Balay ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSTRING,&isstring);CHKERRQ(ierr); 550c52818fSSatish Balay if (isascii) { 560c52818fSSatish Balay if (((PetscObject)ls)->prefix) { 570c52818fSSatish Balay ierr = PetscViewerASCIIPrintf(viewer,"TaoLineSearch Object:(%s)\n",((PetscObject)ls)->prefix);CHKERRQ(ierr); 580c52818fSSatish Balay } else { 590c52818fSSatish Balay ierr = PetscViewerASCIIPrintf(viewer,"TaoLineSearch Object:\n");CHKERRQ(ierr); 600c52818fSSatish Balay } 610c52818fSSatish Balay ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 620c52818fSSatish Balay ierr = TaoLineSearchGetType(ls,&type);CHKERRQ(ierr); 630c52818fSSatish Balay if (type) { 640c52818fSSatish Balay ierr = PetscViewerASCIIPrintf(viewer,"type: %s\n",type);CHKERRQ(ierr); 650c52818fSSatish Balay } else { 660c52818fSSatish Balay ierr = PetscViewerASCIIPrintf(viewer,"type: not set yet\n");CHKERRQ(ierr); 670c52818fSSatish Balay } 680c52818fSSatish Balay if (ls->ops->view) { 690c52818fSSatish Balay ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 700c52818fSSatish Balay ierr = (*ls->ops->view)(ls,viewer);CHKERRQ(ierr); 710c52818fSSatish Balay ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 720c52818fSSatish Balay } 730c52818fSSatish Balay ierr = PetscViewerASCIIPrintf(viewer,"maximum function evaluations=%D\n",ls->max_funcs);CHKERRQ(ierr); 74f06e3bfaSBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"tolerances: ftol=%g, rtol=%g, gtol=%g\n",(double)ls->ftol,(double)ls->rtol,(double)ls->gtol);CHKERRQ(ierr); 750c52818fSSatish Balay ierr = PetscViewerASCIIPrintf(viewer,"total number of function evaluations=%D\n",ls->nfeval);CHKERRQ(ierr); 760c52818fSSatish Balay ierr = PetscViewerASCIIPrintf(viewer,"total number of gradient evaluations=%D\n",ls->ngeval);CHKERRQ(ierr); 770c52818fSSatish Balay ierr = PetscViewerASCIIPrintf(viewer,"total number of function/gradient evaluations=%D\n",ls->nfgeval);CHKERRQ(ierr); 780c52818fSSatish Balay 790c52818fSSatish Balay if (ls->bounded) { 800c52818fSSatish Balay ierr = PetscViewerASCIIPrintf(viewer,"using variable bounds\n");CHKERRQ(ierr); 810c52818fSSatish Balay } 820c52818fSSatish Balay ierr = PetscViewerASCIIPrintf(viewer,"Termination reason: %D\n",(int)ls->reason);CHKERRQ(ierr); 830c52818fSSatish Balay ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 840c52818fSSatish Balay 850c52818fSSatish Balay } else if (isstring) { 860c52818fSSatish Balay ierr = TaoLineSearchGetType(ls,&type);CHKERRQ(ierr); 870c52818fSSatish Balay ierr = PetscViewerStringSPrintf(viewer," %-3.3s",type);CHKERRQ(ierr); 880c52818fSSatish Balay } 890c52818fSSatish Balay if (destroyviewer) { 900c52818fSSatish Balay ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 910c52818fSSatish Balay } 920c52818fSSatish Balay PetscFunctionReturn(0); 930c52818fSSatish Balay } 940c52818fSSatish Balay 950c52818fSSatish Balay #undef __FUNCT__ 960c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchCreate" 970c52818fSSatish Balay /*@C 980c52818fSSatish Balay TaoLineSearchCreate - Creates a TAO Line Search object. Algorithms in TAO that use 990c52818fSSatish Balay line-searches will automatically create one. 1000c52818fSSatish Balay 1010c52818fSSatish Balay Collective on MPI_Comm 1020c52818fSSatish Balay 1030c52818fSSatish Balay Input Parameter: 1040c52818fSSatish Balay . comm - MPI communicator 1050c52818fSSatish Balay 1060c52818fSSatish Balay Output Parameter: 1070c52818fSSatish Balay . newls - the new TaoLineSearch context 1080c52818fSSatish Balay 1090c52818fSSatish Balay Available methods include: 1100c52818fSSatish Balay + more-thuente 1110c52818fSSatish Balay . gpcg 1120c52818fSSatish Balay - unit - Do not perform any line search 1130c52818fSSatish Balay 1140c52818fSSatish Balay 1150c52818fSSatish Balay Options Database Keys: 1160c52818fSSatish Balay . -tao_ls_type - select which method TAO should use 1170c52818fSSatish Balay 1180c52818fSSatish Balay Level: beginner 1190c52818fSSatish Balay 1200c52818fSSatish Balay .seealso: TaoLineSearchSetType(), TaoLineSearchApply(), TaoLineSearchDestroy() 1210c52818fSSatish Balay @*/ 1220c52818fSSatish Balay 1230c52818fSSatish Balay PetscErrorCode TaoLineSearchCreate(MPI_Comm comm, TaoLineSearch *newls) 1240c52818fSSatish Balay { 1250c52818fSSatish Balay PetscErrorCode ierr; 1260c52818fSSatish Balay TaoLineSearch ls; 1270c52818fSSatish Balay 1280c52818fSSatish Balay PetscFunctionBegin; 1290c52818fSSatish Balay PetscValidPointer(newls,2); 1306c23d075SBarry Smith *newls = NULL; 1310c52818fSSatish Balay 1320c52818fSSatish Balay #ifndef PETSC_USE_DYNAMIC_LIBRARIES 1330c52818fSSatish Balay ierr = TaoLineSearchInitializePackage();CHKERRQ(ierr); 1340c52818fSSatish Balay #endif 1350c52818fSSatish Balay 136f06e3bfaSBarry Smith ierr = PetscHeaderCreate(ls,_p_TaoLineSearch,struct _TaoLineSearchOps,TAOLINESEARCH_CLASSID,"TaoLineSearch",0,0,comm,TaoLineSearchDestroy,TaoLineSearchView);CHKERRQ(ierr); 1370c52818fSSatish Balay ls->bounded = 0; 1380c52818fSSatish Balay ls->max_funcs=30; 1390c52818fSSatish Balay ls->ftol = 0.0001; 1400c52818fSSatish Balay ls->gtol = 0.9; 1416f4723b1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 1426f4723b1SBarry Smith ls->rtol = 1.0e-5; 1436f4723b1SBarry Smith #else 1440c52818fSSatish Balay ls->rtol = 1.0e-10; 1456f4723b1SBarry Smith #endif 1460c52818fSSatish Balay ls->stepmin=1.0e-20; 1470c52818fSSatish Balay ls->stepmax=1.0e+20; 1480c52818fSSatish Balay ls->step=1.0; 1490c52818fSSatish Balay ls->nfeval=0; 1500c52818fSSatish Balay ls->ngeval=0; 1510c52818fSSatish Balay ls->nfgeval=0; 1520c52818fSSatish Balay 1530c52818fSSatish Balay ls->ops->computeobjective=0; 1540c52818fSSatish Balay ls->ops->computegradient=0; 1550c52818fSSatish Balay ls->ops->computeobjectiveandgradient=0; 1560c52818fSSatish Balay ls->ops->computeobjectiveandgts=0; 1570c52818fSSatish Balay ls->ops->setup=0; 1580c52818fSSatish Balay ls->ops->apply=0; 1590c52818fSSatish Balay ls->ops->view=0; 1600c52818fSSatish Balay ls->ops->setfromoptions=0; 1610c52818fSSatish Balay ls->ops->reset=0; 1620c52818fSSatish Balay ls->ops->destroy=0; 1630c52818fSSatish Balay ls->setupcalled=PETSC_FALSE; 1640c52818fSSatish Balay ls->usetaoroutines=PETSC_FALSE; 1650c52818fSSatish Balay *newls = ls; 1660c52818fSSatish Balay PetscFunctionReturn(0); 1670c52818fSSatish Balay } 1680c52818fSSatish Balay 1690c52818fSSatish Balay #undef __FUNCT__ 1700c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchSetUp" 1710c52818fSSatish Balay /*@ 1720c52818fSSatish Balay TaoLineSearchSetUp - Sets up the internal data structures for the later use 1730c52818fSSatish Balay of a Tao solver 1740c52818fSSatish Balay 1750c52818fSSatish Balay Collective on ls 1760c52818fSSatish Balay 1770c52818fSSatish Balay Input Parameters: 1780c52818fSSatish Balay . ls - the TaoLineSearch context 1790c52818fSSatish Balay 1800c52818fSSatish Balay Notes: 1810c52818fSSatish Balay The user will not need to explicitly call TaoLineSearchSetUp(), as it will 1820c52818fSSatish Balay automatically be called in TaoLineSearchSolve(). However, if the user 1830c52818fSSatish Balay desires to call it explicitly, it should come after TaoLineSearchCreate() 1840c52818fSSatish Balay but before TaoLineSearchApply(). 1850c52818fSSatish Balay 1860c52818fSSatish Balay Level: developer 1870c52818fSSatish Balay 1880c52818fSSatish Balay .seealso: TaoLineSearchCreate(), TaoLineSearchApply() 1890c52818fSSatish Balay @*/ 1900c52818fSSatish Balay 1910c52818fSSatish Balay PetscErrorCode TaoLineSearchSetUp(TaoLineSearch ls) 1920c52818fSSatish Balay { 1930c52818fSSatish Balay PetscErrorCode ierr; 1948caf6e8cSBarry Smith const char *default_type=TAOLINESEARCHMT; 1950c52818fSSatish Balay PetscBool flg; 196f06e3bfaSBarry Smith 1970c52818fSSatish Balay PetscFunctionBegin; 1980c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 1990c52818fSSatish Balay if (ls->setupcalled) PetscFunctionReturn(0); 2000c52818fSSatish Balay if (!((PetscObject)ls)->type_name) { 2010c52818fSSatish Balay ierr = TaoLineSearchSetType(ls,default_type);CHKERRQ(ierr); 2020c52818fSSatish Balay } 2030c52818fSSatish Balay if (ls->ops->setup) { 2040c52818fSSatish Balay ierr = (*ls->ops->setup)(ls);CHKERRQ(ierr); 2050c52818fSSatish Balay } 2060c52818fSSatish Balay if (ls->usetaoroutines) { 207441846f8SBarry Smith ierr = TaoIsObjectiveDefined(ls->tao,&flg);CHKERRQ(ierr); 2080c52818fSSatish Balay ls->hasobjective = flg; 209441846f8SBarry Smith ierr = TaoIsGradientDefined(ls->tao,&flg);CHKERRQ(ierr); 2100c52818fSSatish Balay ls->hasgradient = flg; 211441846f8SBarry Smith ierr = TaoIsObjectiveAndGradientDefined(ls->tao,&flg);CHKERRQ(ierr); 2120c52818fSSatish Balay ls->hasobjectiveandgradient = flg; 2130c52818fSSatish Balay } else { 2140c52818fSSatish Balay if (ls->ops->computeobjective) { 2150c52818fSSatish Balay ls->hasobjective = PETSC_TRUE; 2160c52818fSSatish Balay } else { 2170c52818fSSatish Balay ls->hasobjective = PETSC_FALSE; 2180c52818fSSatish Balay } 2190c52818fSSatish Balay if (ls->ops->computegradient) { 2200c52818fSSatish Balay ls->hasgradient = PETSC_TRUE; 2210c52818fSSatish Balay } else { 2220c52818fSSatish Balay ls->hasgradient = PETSC_FALSE; 2230c52818fSSatish Balay } 2240c52818fSSatish Balay if (ls->ops->computeobjectiveandgradient) { 2250c52818fSSatish Balay ls->hasobjectiveandgradient = PETSC_TRUE; 2260c52818fSSatish Balay } else { 2270c52818fSSatish Balay ls->hasobjectiveandgradient = PETSC_FALSE; 2280c52818fSSatish Balay } 2290c52818fSSatish Balay } 2300c52818fSSatish Balay ls->setupcalled = PETSC_TRUE; 2310c52818fSSatish Balay PetscFunctionReturn(0); 2320c52818fSSatish Balay } 2330c52818fSSatish Balay 2340c52818fSSatish Balay #undef __FUNCT__ 2350c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchReset" 2360c52818fSSatish Balay /*@ 2370c52818fSSatish Balay TaoLineSearchReset - Some line searches may carry state information 2380c52818fSSatish Balay from one TaoLineSearchApply() to the next. This function resets this 2390c52818fSSatish Balay state information. 2400c52818fSSatish Balay 2410c52818fSSatish Balay Collective on TaoLineSearch 2420c52818fSSatish Balay 2430c52818fSSatish Balay Input Parameter: 2440c52818fSSatish Balay . ls - the TaoLineSearch context 2450c52818fSSatish Balay 2460c52818fSSatish Balay Level: developer 2470c52818fSSatish Balay 2480c52818fSSatish Balay .seealso: TaoLineSearchCreate(), TaoLineSearchApply() 2490c52818fSSatish Balay @*/ 2500c52818fSSatish Balay PetscErrorCode TaoLineSearchReset(TaoLineSearch ls) 2510c52818fSSatish Balay { 2520c52818fSSatish Balay PetscErrorCode ierr; 253050fc7a3SBarry Smith 2540c52818fSSatish Balay PetscFunctionBegin; 2550c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 2560c52818fSSatish Balay if (ls->ops->reset) { 2570c52818fSSatish Balay ierr = (*ls->ops->reset)(ls);CHKERRQ(ierr); 2580c52818fSSatish Balay } 2590c52818fSSatish Balay PetscFunctionReturn(0); 2600c52818fSSatish Balay } 261f06e3bfaSBarry Smith 2620c52818fSSatish Balay #undef __FUNCT__ 2630c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchDestroy" 2640c52818fSSatish Balay /*@ 2650c52818fSSatish Balay TaoLineSearchDestroy - Destroys the TAO context that was created with 2660c52818fSSatish Balay TaoLineSearchCreate() 2670c52818fSSatish Balay 2680c52818fSSatish Balay Collective on TaoLineSearch 2690c52818fSSatish Balay 2700c52818fSSatish Balay Input Parameter 2710c52818fSSatish Balay . ls - the TaoLineSearch context 2720c52818fSSatish Balay 2730c52818fSSatish Balay Level: beginner 2740c52818fSSatish Balay 2750c52818fSSatish Balay .seealse: TaoLineSearchCreate(), TaoLineSearchSolve() 2760c52818fSSatish Balay @*/ 2770c52818fSSatish Balay PetscErrorCode TaoLineSearchDestroy(TaoLineSearch *ls) 2780c52818fSSatish Balay { 2790c52818fSSatish Balay PetscErrorCode ierr; 280050fc7a3SBarry Smith 2810c52818fSSatish Balay PetscFunctionBegin; 2820c52818fSSatish Balay if (!*ls) PetscFunctionReturn(0); 2830c52818fSSatish Balay PetscValidHeaderSpecific(*ls,TAOLINESEARCH_CLASSID,1); 2840c52818fSSatish Balay if (--((PetscObject)*ls)->refct > 0) {*ls=0; PetscFunctionReturn(0);} 285050fc7a3SBarry Smith ierr = VecDestroy(&(*ls)->stepdirection);CHKERRQ(ierr); 286050fc7a3SBarry Smith ierr = VecDestroy(&(*ls)->start_x);CHKERRQ(ierr); 2870c52818fSSatish Balay if ((*ls)->ops->destroy) { 2880c52818fSSatish Balay ierr = (*(*ls)->ops->destroy)(*ls);CHKERRQ(ierr); 2890c52818fSSatish Balay } 2900c52818fSSatish Balay ierr = PetscHeaderDestroy(ls);CHKERRQ(ierr); 2910c52818fSSatish Balay PetscFunctionReturn(0); 2920c52818fSSatish Balay } 2930c52818fSSatish Balay 2940c52818fSSatish Balay #undef __FUNCT__ 2950c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchApply" 2960c52818fSSatish Balay /*@ 2970c52818fSSatish Balay TaoLineSearchApply - Performs a line-search in a given step direction. Criteria for acceptable step length depends on the line-search algorithm chosen 2980c52818fSSatish Balay 2990c52818fSSatish Balay Collective on TaoLineSearch 3000c52818fSSatish Balay 3010c52818fSSatish Balay Input Parameters: 302441846f8SBarry Smith + ls - the Tao context 3030c52818fSSatish Balay . x - The current solution (on output x contains the new solution determined by the line search) 3040c52818fSSatish Balay . f - objective function value at current solution (on output contains the objective function value at new solution) 3050c52818fSSatish Balay . g - gradient evaluated at x (on output contains the gradient at new solution) 3060c52818fSSatish Balay - s - search direction 3070c52818fSSatish Balay 3080c52818fSSatish Balay Output Parameters: 3090c52818fSSatish Balay + x - new solution 3100c52818fSSatish Balay . f - objective function value at x 3110c52818fSSatish Balay . g - gradient vector at x 3120c52818fSSatish Balay . steplength - scalar multiplier of s used ( x = x0 + steplength * x ) 3130c52818fSSatish Balay - reason - reason why the line-search stopped 3140c52818fSSatish Balay 3150c52818fSSatish Balay reason will be set to one of: 3160c52818fSSatish Balay 3170c52818fSSatish Balay + TAOLINESEARCH_FAILED_ASCENT - initial line search step * g is not descent direction 3180c52818fSSatish Balay . TAOLINESEARCH_FAILED_INFORNAN - function evaluation gives Inf or Nan value 3190c52818fSSatish Balay . TAOLINESEARCH_FAILED_BADPARAMETER - negative value set as parameter 3200c52818fSSatish Balay . TAOLINESEARCH_HALTED_MAXFCN - maximum number of function evaluation reached 3210c52818fSSatish Balay . TAOLINESEARCH_HALTED_UPPERBOUND - step is at upper bound 3220c52818fSSatish Balay . TAOLINESEARCH_HALTED_LOWERBOUND - step is at lower bound 3230c52818fSSatish Balay . TAOLINESEARCH_HALTED_RTOL - range of uncertainty is smaller than given tolerance 3240c52818fSSatish Balay . TAOLINESEARCH_HALTED_USER - user can set this reason to stop line search 3250c52818fSSatish Balay . TAOLINESEARCH_HALTED_OTHER - any other reason 3260c52818fSSatish Balay - TAOLINESEARCH_SUCCESS - successful line search 3270c52818fSSatish Balay 3280c52818fSSatish Balay Note: 3290c52818fSSatish Balay The algorithm developer must set up the TaoLineSearch with calls to 330441846f8SBarry Smith TaoLineSearchSetObjectiveRoutine() and TaoLineSearchSetGradientRoutine(), TaoLineSearchSetObjectiveAndGradientRoutine(), or TaoLineSearchUseTaoRoutines() 3310c52818fSSatish Balay 3320c52818fSSatish Balay Note: 3330c52818fSSatish Balay You may or may not need to follow this with a call to 3340c52818fSSatish Balay TaoAddLineSearchCounts(), depending on whether you want these 3350c52818fSSatish Balay evaluations to count toward the total function/gradient evaluations. 3360c52818fSSatish Balay 3370c52818fSSatish Balay Level: beginner 3380c52818fSSatish Balay 3390c52818fSSatish Balay .seealso: TaoLineSearchCreate(), TaoLineSearchSetType(), TaoLineSearchSetInitialStepLength(), TaoAddLineSearchCounts() 3400c52818fSSatish Balay @*/ 3410c52818fSSatish Balay 342e4cb33bbSBarry Smith PetscErrorCode TaoLineSearchApply(TaoLineSearch ls, Vec x, PetscReal *f, Vec g, Vec s, PetscReal *steplength, TaoLineSearchConvergedReason *reason) 3430c52818fSSatish Balay { 3440c52818fSSatish Balay PetscErrorCode ierr; 3450c52818fSSatish Balay PetscInt low1,low2,low3,high1,high2,high3; 3460c52818fSSatish Balay 3470c52818fSSatish Balay PetscFunctionBegin; 3480c52818fSSatish Balay *reason = TAOLINESEARCH_CONTINUE_ITERATING; 3490c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 3500c52818fSSatish Balay PetscValidHeaderSpecific(x,VEC_CLASSID,2); 3510c52818fSSatish Balay PetscValidScalarPointer(f,3); 3520c52818fSSatish Balay PetscValidHeaderSpecific(g,VEC_CLASSID,4); 3530c52818fSSatish Balay PetscValidHeaderSpecific(s,VEC_CLASSID,5); 3540c52818fSSatish Balay PetscValidPointer(reason,7); 3550c52818fSSatish Balay PetscCheckSameComm(ls,1,x,2); 3560c52818fSSatish Balay PetscCheckSameTypeAndComm(x,2,g,4); 3570c52818fSSatish Balay PetscCheckSameTypeAndComm(x,2,s,5); 3580c52818fSSatish Balay ierr = VecGetOwnershipRange(x, &low1, &high1);CHKERRQ(ierr); 3590c52818fSSatish Balay ierr = VecGetOwnershipRange(g, &low2, &high2);CHKERRQ(ierr); 3600c52818fSSatish Balay ierr = VecGetOwnershipRange(s, &low3, &high3);CHKERRQ(ierr); 361f06e3bfaSBarry Smith if ( low1!= low2 || low1!= low3 || high1!= high2 || high1!= high3) SETERRQ(PETSC_COMM_SELF,1,"InCompatible vector local lengths"); 3620c52818fSSatish Balay 3630c52818fSSatish Balay ierr = PetscObjectReference((PetscObject)s);CHKERRQ(ierr); 364050fc7a3SBarry Smith ierr = VecDestroy(&ls->stepdirection);CHKERRQ(ierr); 365050fc7a3SBarry Smith ls->stepdirection = s; 3660c52818fSSatish Balay 3670c52818fSSatish Balay ierr = TaoLineSearchSetUp(ls);CHKERRQ(ierr); 368f06e3bfaSBarry Smith if (!ls->ops->apply) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Line Search Object does not have 'apply' routine"); 3690c52818fSSatish Balay ls->nfeval=0; 3700c52818fSSatish Balay ls->ngeval=0; 3710c52818fSSatish Balay ls->nfgeval=0; 3720c52818fSSatish Balay /* Check parameter values */ 3730c52818fSSatish Balay if (ls->ftol < 0.0) { 374f06e3bfaSBarry Smith ierr = PetscInfo1(ls,"Bad Line Search Parameter: ftol (%g) < 0\n",(double)ls->ftol);CHKERRQ(ierr); 3750c52818fSSatish Balay *reason=TAOLINESEARCH_FAILED_BADPARAMETER; 3760c52818fSSatish Balay } 3770c52818fSSatish Balay if (ls->rtol < 0.0) { 378f06e3bfaSBarry Smith ierr = PetscInfo1(ls,"Bad Line Search Parameter: rtol (%g) < 0\n",(double)ls->rtol);CHKERRQ(ierr); 3790c52818fSSatish Balay *reason=TAOLINESEARCH_FAILED_BADPARAMETER; 3800c52818fSSatish Balay } 3810c52818fSSatish Balay if (ls->gtol < 0.0) { 382f06e3bfaSBarry Smith ierr = PetscInfo1(ls,"Bad Line Search Parameter: gtol (%g) < 0\n",(double)ls->gtol);CHKERRQ(ierr); 3830c52818fSSatish Balay *reason=TAOLINESEARCH_FAILED_BADPARAMETER; 3840c52818fSSatish Balay } 3850c52818fSSatish Balay if (ls->stepmin < 0.0) { 386f06e3bfaSBarry Smith ierr = PetscInfo1(ls,"Bad Line Search Parameter: stepmin (%g) < 0\n",(double)ls->stepmin);CHKERRQ(ierr); 3870c52818fSSatish Balay *reason=TAOLINESEARCH_FAILED_BADPARAMETER; 3880c52818fSSatish Balay } 3890c52818fSSatish Balay if (ls->stepmax < ls->stepmin) { 390f06e3bfaSBarry Smith ierr = PetscInfo2(ls,"Bad Line Search Parameter: stepmin (%g) > stepmax (%g)\n",(double)ls->stepmin,(double)ls->stepmax);CHKERRQ(ierr); 3910c52818fSSatish Balay *reason=TAOLINESEARCH_FAILED_BADPARAMETER; 3920c52818fSSatish Balay } 3930c52818fSSatish Balay if (ls->max_funcs < 0) { 3940c52818fSSatish Balay ierr = PetscInfo1(ls,"Bad Line Search Parameter: max_funcs (%D) < 0\n",ls->max_funcs);CHKERRQ(ierr); 3950c52818fSSatish Balay *reason=TAOLINESEARCH_FAILED_BADPARAMETER; 3960c52818fSSatish Balay } 3970c52818fSSatish Balay if (PetscIsInfOrNanReal(*f)) { 398f06e3bfaSBarry Smith ierr = PetscInfo1(ls,"Initial Line Search Function Value is Inf or Nan (%g)\n",(double)*f);CHKERRQ(ierr); 3990c52818fSSatish Balay *reason=TAOLINESEARCH_FAILED_INFORNAN; 4000c52818fSSatish Balay } 4010c52818fSSatish Balay 4020c52818fSSatish Balay ierr = PetscObjectReference((PetscObject)x); 4030c52818fSSatish Balay ierr = VecDestroy(&ls->start_x);CHKERRQ(ierr); 4040c52818fSSatish Balay ls->start_x = x; 405050fc7a3SBarry Smith 4060c52818fSSatish Balay ierr = PetscLogEventBegin(TaoLineSearch_ApplyEvent,ls,0,0,0);CHKERRQ(ierr); 4070c52818fSSatish Balay ierr = (*ls->ops->apply)(ls,x,f,g,s);CHKERRQ(ierr); 4080c52818fSSatish Balay ierr = PetscLogEventEnd(TaoLineSearch_ApplyEvent, ls, 0,0,0);CHKERRQ(ierr); 4090c52818fSSatish Balay *reason=ls->reason; 4100c52818fSSatish Balay ls->new_f = *f; 4110c52818fSSatish Balay 4120c52818fSSatish Balay if (steplength) { 4130c52818fSSatish Balay *steplength=ls->step; 4140c52818fSSatish Balay } 4150c52818fSSatish Balay 416*fbe0838dSJason Sarich ierr = TaoLineSearchViewFromOptions(ls,NULL,"-tao_ls_view");CHKERRQ(ierr); 4170c52818fSSatish Balay PetscFunctionReturn(0); 4180c52818fSSatish Balay } 4190c52818fSSatish Balay 4200c52818fSSatish Balay #undef __FUNCT__ 4210c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchSetType" 4220c52818fSSatish Balay /*@C 4230c52818fSSatish Balay TaoLineSearchSetType - Sets the algorithm used in a line search 4240c52818fSSatish Balay 4250c52818fSSatish Balay Collective on TaoLineSearch 4260c52818fSSatish Balay 4270c52818fSSatish Balay Input Parameters: 4280c52818fSSatish Balay + ls - the TaoLineSearch context 4290c52818fSSatish Balay - type - a known method 4300c52818fSSatish Balay 4310c52818fSSatish Balay Available methods include: 4320c52818fSSatish Balay + more-thuente 4330c52818fSSatish Balay . gpcg 4340c52818fSSatish Balay - unit - Do not perform any line search 4350c52818fSSatish Balay 4360c52818fSSatish Balay 4370c52818fSSatish Balay Options Database Keys: 4380c52818fSSatish Balay . -tao_ls_type - select which method TAO should use 4390c52818fSSatish Balay 4400c52818fSSatish Balay Level: beginner 4410c52818fSSatish Balay 4420c52818fSSatish Balay 4430c52818fSSatish Balay .seealso: TaoLineSearchCreate(), TaoLineSearchGetType(), TaoLineSearchApply() 4440c52818fSSatish Balay 4450c52818fSSatish Balay @*/ 4460c52818fSSatish Balay 4470c52818fSSatish Balay PetscErrorCode TaoLineSearchSetType(TaoLineSearch ls, const TaoLineSearchType type) 4480c52818fSSatish Balay { 4490c52818fSSatish Balay PetscErrorCode ierr; 4500c52818fSSatish Balay PetscErrorCode (*r)(TaoLineSearch); 4510c52818fSSatish Balay PetscBool flg; 4520c52818fSSatish Balay 4530c52818fSSatish Balay PetscFunctionBegin; 4540c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 4550c52818fSSatish Balay PetscValidCharPointer(type,2); 4560c52818fSSatish Balay ierr = PetscObjectTypeCompare((PetscObject)ls, type, &flg);CHKERRQ(ierr); 4570c52818fSSatish Balay if (flg) PetscFunctionReturn(0); 4580c52818fSSatish Balay 4590c52818fSSatish Balay ierr = PetscFunctionListFind(TaoLineSearchList,type, (void (**)(void)) &r);CHKERRQ(ierr); 4600c52818fSSatish Balay if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested TaoLineSearch type %s",type); 4610c52818fSSatish Balay if (ls->ops->destroy) { 4620c52818fSSatish Balay ierr = (*(ls)->ops->destroy)(ls);CHKERRQ(ierr); 4630c52818fSSatish Balay } 4640c52818fSSatish Balay ls->max_funcs=30; 4650c52818fSSatish Balay ls->ftol = 0.0001; 4660c52818fSSatish Balay ls->gtol = 0.9; 4676f4723b1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE) 4686f4723b1SBarry Smith ls->rtol = 1.0e-5; 4696f4723b1SBarry Smith #else 4700c52818fSSatish Balay ls->rtol = 1.0e-10; 4716f4723b1SBarry Smith #endif 4720c52818fSSatish Balay ls->stepmin=1.0e-20; 4730c52818fSSatish Balay ls->stepmax=1.0e+20; 4740c52818fSSatish Balay 4750c52818fSSatish Balay ls->nfeval=0; 4760c52818fSSatish Balay ls->ngeval=0; 4770c52818fSSatish Balay ls->nfgeval=0; 4780c52818fSSatish Balay ls->ops->setup=0; 4790c52818fSSatish Balay ls->ops->apply=0; 4800c52818fSSatish Balay ls->ops->view=0; 4810c52818fSSatish Balay ls->ops->setfromoptions=0; 4820c52818fSSatish Balay ls->ops->destroy=0; 4830c52818fSSatish Balay ls->setupcalled = PETSC_FALSE; 4840c52818fSSatish Balay ierr = (*r)(ls);CHKERRQ(ierr); 4850c52818fSSatish Balay ierr = PetscObjectChangeTypeName((PetscObject)ls, type);CHKERRQ(ierr); 4860c52818fSSatish Balay PetscFunctionReturn(0); 4870c52818fSSatish Balay } 4880c52818fSSatish Balay 4890c52818fSSatish Balay #undef __FUNCT__ 4900c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchSetFromOptions" 4910c52818fSSatish Balay /*@ 4920c52818fSSatish Balay TaoLineSearchSetFromOptions - Sets various TaoLineSearch parameters from user 4930c52818fSSatish Balay options. 4940c52818fSSatish Balay 4950c52818fSSatish Balay Collective on TaoLineSearch 4960c52818fSSatish Balay 4970c52818fSSatish Balay Input Paremeter: 4980c52818fSSatish Balay . ls - the TaoLineSearch context 4990c52818fSSatish Balay 5000c52818fSSatish Balay Options Database Keys: 5010c52818fSSatish Balay + -tao_ls_type <type> - The algorithm that TAO uses (more-thuente, gpcg, unit) 5020c52818fSSatish Balay . -tao_ls_ftol <tol> - tolerance for sufficient decrease 5030c52818fSSatish Balay . -tao_ls_gtol <tol> - tolerance for curvature condition 5040c52818fSSatish Balay . -tao_ls_rtol <tol> - relative tolerance for acceptable step 5050c52818fSSatish Balay . -tao_ls_stepmin <step> - minimum steplength allowed 5060c52818fSSatish Balay . -tao_ls_stepmax <step> - maximum steplength allowed 5070c52818fSSatish Balay . -tao_ls_max_funcs <n> - maximum number of function evaluations allowed 5080c52818fSSatish Balay - -tao_ls_view - display line-search results to standard output 5090c52818fSSatish Balay 5100c52818fSSatish Balay Level: beginner 5110c52818fSSatish Balay @*/ 5120c52818fSSatish Balay PetscErrorCode TaoLineSearchSetFromOptions(TaoLineSearch ls) 5130c52818fSSatish Balay { 5140c52818fSSatish Balay PetscErrorCode ierr; 5158caf6e8cSBarry Smith const char *default_type=TAOLINESEARCHMT; 5160c52818fSSatish Balay char type[256]; 5170c52818fSSatish Balay PetscBool flg; 518f06e3bfaSBarry Smith 5190c52818fSSatish Balay PetscFunctionBegin; 5200c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 5210c52818fSSatish Balay ierr = PetscObjectOptionsBegin((PetscObject)ls);CHKERRQ(ierr); 5220c52818fSSatish Balay if (!TaoLineSearchInitialized) { 5230c52818fSSatish Balay ierr = TaoLineSearchInitializePackage();CHKERRQ(ierr); 5240c52818fSSatish Balay } 5250c52818fSSatish Balay if (((PetscObject)ls)->type_name) { 5260c52818fSSatish Balay default_type = ((PetscObject)ls)->type_name; 5270c52818fSSatish Balay } 5280c52818fSSatish Balay /* Check for type from options */ 5290c52818fSSatish Balay ierr = PetscOptionsFList("-tao_ls_type","Tao Line Search type","TaoLineSearchSetType",TaoLineSearchList,default_type,type,256,&flg);CHKERRQ(ierr); 5300c52818fSSatish Balay if (flg) { 5310c52818fSSatish Balay ierr = TaoLineSearchSetType(ls,type);CHKERRQ(ierr); 5320c52818fSSatish Balay } else if (!((PetscObject)ls)->type_name) { 5330c52818fSSatish Balay ierr = TaoLineSearchSetType(ls,default_type); 5340c52818fSSatish Balay } 5350c52818fSSatish Balay 536f06e3bfaSBarry Smith ierr = PetscOptionsInt("-tao_ls_max_funcs","max function evals in line search","",ls->max_funcs,&ls->max_funcs,0);CHKERRQ(ierr); 537f06e3bfaSBarry Smith ierr = PetscOptionsReal("-tao_ls_ftol","tol for sufficient decrease","",ls->ftol,&ls->ftol,0);CHKERRQ(ierr); 538f06e3bfaSBarry Smith ierr = PetscOptionsReal("-tao_ls_gtol","tol for curvature condition","",ls->gtol,&ls->gtol,0);CHKERRQ(ierr); 539f06e3bfaSBarry Smith ierr = PetscOptionsReal("-tao_ls_rtol","relative tol for acceptable step","",ls->rtol,&ls->rtol,0);CHKERRQ(ierr); 540f06e3bfaSBarry Smith ierr = PetscOptionsReal("-tao_ls_stepmin","lower bound for step","",ls->stepmin,&ls->stepmin,0);CHKERRQ(ierr); 541f06e3bfaSBarry Smith ierr = PetscOptionsReal("-tao_ls_stepmax","upper bound for step","",ls->stepmax,&ls->stepmax,0);CHKERRQ(ierr); 5420c52818fSSatish Balay if (ls->ops->setfromoptions) { 5430c52818fSSatish Balay ierr = (*ls->ops->setfromoptions)(ls);CHKERRQ(ierr); 5440c52818fSSatish Balay } 5450c52818fSSatish Balay ierr = PetscOptionsEnd();CHKERRQ(ierr); 5460c52818fSSatish Balay PetscFunctionReturn(0); 5470c52818fSSatish Balay } 5480c52818fSSatish Balay 5490c52818fSSatish Balay #undef __FUNCT__ 5500c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchGetType" 5510c52818fSSatish Balay /*@C 5520c52818fSSatish Balay TaoLineSearchGetType - Gets the current line search algorithm 5530c52818fSSatish Balay 5540c52818fSSatish Balay Not Collective 5550c52818fSSatish Balay 5560c52818fSSatish Balay Input Parameter: 5570c52818fSSatish Balay . ls - the TaoLineSearch context 5580c52818fSSatish Balay 5590c52818fSSatish Balay Output Paramter: 5600c52818fSSatish Balay . type - the line search algorithm in effect 5610c52818fSSatish Balay 5620c52818fSSatish Balay Level: developer 5630c52818fSSatish Balay 5640c52818fSSatish Balay @*/ 5650c52818fSSatish Balay PetscErrorCode TaoLineSearchGetType(TaoLineSearch ls, const TaoLineSearchType *type) 5660c52818fSSatish Balay { 5670c52818fSSatish Balay PetscFunctionBegin; 5680c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 5690c52818fSSatish Balay PetscValidPointer(type,2); 5700c52818fSSatish Balay *type = ((PetscObject)ls)->type_name; 5710c52818fSSatish Balay PetscFunctionReturn(0); 5720c52818fSSatish Balay } 5730c52818fSSatish Balay 5740c52818fSSatish Balay #undef __FUNCT__ 5750c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchGetNumberFunctionEvaluations" 5760c52818fSSatish Balay /*@ 5770c52818fSSatish Balay TaoLineSearchGetNumberFunctionEvaluations - Gets the number of function and gradient evaluation 5780c52818fSSatish Balay routines used by the line search in last application (not cumulative). 5790c52818fSSatish Balay 5800c52818fSSatish Balay Not Collective 5810c52818fSSatish Balay 5820c52818fSSatish Balay Input Parameter: 5830c52818fSSatish Balay . ls - the TaoLineSearch context 5840c52818fSSatish Balay 5850c52818fSSatish Balay Output Parameters: 5860c52818fSSatish Balay + nfeval - number of function evaluations 5870c52818fSSatish Balay . ngeval - number of gradient evaluations 5880c52818fSSatish Balay - nfgeval - number of function/gradient evaluations 5890c52818fSSatish Balay 5900c52818fSSatish Balay Level: intermediate 5910c52818fSSatish Balay 5920c52818fSSatish Balay Note: 593441846f8SBarry Smith If the line search is using the Tao objective and gradient 594441846f8SBarry Smith routines directly (see TaoLineSearchUseTaoRoutines()), then TAO 5950c52818fSSatish Balay is already counting the number of evaluations. 5960c52818fSSatish Balay 5970c52818fSSatish Balay @*/ 5980c52818fSSatish Balay PetscErrorCode TaoLineSearchGetNumberFunctionEvaluations(TaoLineSearch ls, PetscInt *nfeval, PetscInt *ngeval, PetscInt *nfgeval) 5990c52818fSSatish Balay { 6000c52818fSSatish Balay PetscFunctionBegin; 6010c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 6020c52818fSSatish Balay *nfeval = ls->nfeval; 6030c52818fSSatish Balay *ngeval = ls->ngeval; 6040c52818fSSatish Balay *nfgeval = ls->nfgeval; 6050c52818fSSatish Balay PetscFunctionReturn(0); 6060c52818fSSatish Balay } 6070c52818fSSatish Balay 6080c52818fSSatish Balay #undef __FUNCT__ 609441846f8SBarry Smith #define __FUNCT__ "TaoLineSearchIsUsingTaoRoutines" 6100c52818fSSatish Balay /*@ 611441846f8SBarry Smith TaoLineSearchIsUsingTaoRoutines - Checks whether the line search is using 612441846f8SBarry Smith Tao evaluation routines. 6130c52818fSSatish Balay 6140c52818fSSatish Balay Not Collective 6150c52818fSSatish Balay 6160c52818fSSatish Balay Input Parameter: 6170c52818fSSatish Balay . ls - the TaoLineSearch context 6180c52818fSSatish Balay 6190c52818fSSatish Balay Output Parameter: 620441846f8SBarry Smith . flg - PETSC_TRUE if the line search is using Tao evaluation routines, 6210c52818fSSatish Balay otherwise PETSC_FALSE 6220c52818fSSatish Balay 6230c52818fSSatish Balay Level: developer 6240c52818fSSatish Balay @*/ 625441846f8SBarry Smith PetscErrorCode TaoLineSearchIsUsingTaoRoutines(TaoLineSearch ls, PetscBool *flg) 6260c52818fSSatish Balay { 6270c52818fSSatish Balay PetscFunctionBegin; 6280c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 629f06e3bfaSBarry Smith *flg = ls->usetaoroutines; 6300c52818fSSatish Balay PetscFunctionReturn(0); 6310c52818fSSatish Balay } 6320c52818fSSatish Balay 6330c52818fSSatish Balay #undef __FUNCT__ 6340c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchSetObjectiveRoutine" 6350c52818fSSatish Balay /*@C 6360c52818fSSatish Balay TaoLineSearchSetObjectiveRoutine - Sets the function evaluation routine for the line search 6370c52818fSSatish Balay 6380c52818fSSatish Balay Logically Collective on TaoLineSearch 6390c52818fSSatish Balay 6400c52818fSSatish Balay Input Parameter: 6410c52818fSSatish Balay + ls - the TaoLineSearch context 6420c52818fSSatish Balay . func - the objective function evaluation routine 6430c52818fSSatish Balay - ctx - the (optional) user-defined context for private data 6440c52818fSSatish Balay 6450c52818fSSatish Balay Calling sequence of func: 6460c52818fSSatish Balay $ func (TaoLinesearch ls, Vec x, PetscReal *f, void *ctx); 6470c52818fSSatish Balay 6480c52818fSSatish Balay + x - input vector 6490c52818fSSatish Balay . f - function value 6500c52818fSSatish Balay - ctx (optional) user-defined context 6510c52818fSSatish Balay 6520c52818fSSatish Balay Level: beginner 6530c52818fSSatish Balay 6540c52818fSSatish Balay Note: 6550c52818fSSatish Balay Use this routine only if you want the line search objective 656441846f8SBarry Smith evaluation routine to be different from the Tao's objective 6570c52818fSSatish Balay evaluation routine. If you use this routine you must also set 6580c52818fSSatish Balay the line search gradient and/or function/gradient routine. 6590c52818fSSatish Balay 6600c52818fSSatish Balay Note: 6610c52818fSSatish Balay Some algorithms (lcl, gpcg) set their own objective routine for the 6620c52818fSSatish Balay line search, application programmers should be wary of overriding the 6630c52818fSSatish Balay default objective routine. 6640c52818fSSatish Balay 665441846f8SBarry Smith .seealso: TaoLineSearchCreate(), TaoLineSearchSetGradientRoutine(), TaoLineSearchSetObjectiveAndGradientRoutine(), TaoLineSearchUseTaoRoutines() 6660c52818fSSatish Balay @*/ 6670c52818fSSatish Balay PetscErrorCode TaoLineSearchSetObjectiveRoutine(TaoLineSearch ls, PetscErrorCode(*func)(TaoLineSearch ls, Vec x, PetscReal*, void*), void *ctx) 6680c52818fSSatish Balay { 6690c52818fSSatish Balay PetscFunctionBegin; 6700c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 6710c52818fSSatish Balay 6720c52818fSSatish Balay ls->ops->computeobjective=func; 6730c52818fSSatish Balay if (ctx) ls->userctx_func=ctx; 6740c52818fSSatish Balay ls->usetaoroutines=PETSC_FALSE; 6750c52818fSSatish Balay PetscFunctionReturn(0); 6760c52818fSSatish Balay } 6770c52818fSSatish Balay 6780c52818fSSatish Balay #undef __FUNCT__ 6790c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchSetGradientRoutine" 6800c52818fSSatish Balay /*@C 6810c52818fSSatish Balay TaoLineSearchSetGradientRoutine - Sets the gradient evaluation routine for the line search 6820c52818fSSatish Balay 6830c52818fSSatish Balay Logically Collective on TaoLineSearch 6840c52818fSSatish Balay 6850c52818fSSatish Balay Input Parameter: 6860c52818fSSatish Balay + ls - the TaoLineSearch context 6870c52818fSSatish Balay . func - the gradient evaluation routine 6880c52818fSSatish Balay - ctx - the (optional) user-defined context for private data 6890c52818fSSatish Balay 6900c52818fSSatish Balay Calling sequence of func: 6910c52818fSSatish Balay $ func (TaoLinesearch ls, Vec x, Vec g, void *ctx); 6920c52818fSSatish Balay 6930c52818fSSatish Balay + x - input vector 6940c52818fSSatish Balay . g - gradient vector 6950c52818fSSatish Balay - ctx (optional) user-defined context 6960c52818fSSatish Balay 6970c52818fSSatish Balay Level: beginner 6980c52818fSSatish Balay 6990c52818fSSatish Balay Note: 7000c52818fSSatish Balay Use this routine only if you want the line search gradient 701441846f8SBarry Smith evaluation routine to be different from the Tao's gradient 7020c52818fSSatish Balay evaluation routine. If you use this routine you must also set 7030c52818fSSatish Balay the line search function and/or function/gradient routine. 7040c52818fSSatish Balay 7050c52818fSSatish Balay Note: 7060c52818fSSatish Balay Some algorithms (lcl, gpcg) set their own gradient routine for the 7070c52818fSSatish Balay line search, application programmers should be wary of overriding the 7080c52818fSSatish Balay default gradient routine. 7090c52818fSSatish Balay 710441846f8SBarry Smith .seealso: TaoLineSearchCreate(), TaoLineSearchSetObjectiveRoutine(), TaoLineSearchSetObjectiveAndGradientRoutine(), TaoLineSearchUseTaoRoutines() 7110c52818fSSatish Balay @*/ 7120c52818fSSatish Balay PetscErrorCode TaoLineSearchSetGradientRoutine(TaoLineSearch ls, PetscErrorCode(*func)(TaoLineSearch ls, Vec x, Vec g, void*), void *ctx) 7130c52818fSSatish Balay { 7140c52818fSSatish Balay PetscFunctionBegin; 7150c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 7160c52818fSSatish Balay ls->ops->computegradient=func; 7170c52818fSSatish Balay if (ctx) ls->userctx_grad=ctx; 7180c52818fSSatish Balay ls->usetaoroutines=PETSC_FALSE; 7190c52818fSSatish Balay PetscFunctionReturn(0); 7200c52818fSSatish Balay } 7210c52818fSSatish Balay 7220c52818fSSatish Balay #undef __FUNCT__ 7230c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchSetObjectiveAndGradientRoutine" 7240c52818fSSatish Balay /*@C 7250c52818fSSatish Balay TaoLineSearchSetObjectiveAndGradientRoutine - Sets the objective/gradient evaluation routine for the line search 7260c52818fSSatish Balay 7270c52818fSSatish Balay Logically Collective on TaoLineSearch 7280c52818fSSatish Balay 7290c52818fSSatish Balay Input Parameter: 7300c52818fSSatish Balay + ls - the TaoLineSearch context 7310c52818fSSatish Balay . func - the objective and gradient evaluation routine 7320c52818fSSatish Balay - ctx - the (optional) user-defined context for private data 7330c52818fSSatish Balay 7340c52818fSSatish Balay Calling sequence of func: 7350c52818fSSatish Balay $ func (TaoLinesearch ls, Vec x, PetscReal *f, Vec g, void *ctx); 7360c52818fSSatish Balay 7370c52818fSSatish Balay + x - input vector 7380c52818fSSatish Balay . f - function value 7390c52818fSSatish Balay . g - gradient vector 7400c52818fSSatish Balay - ctx (optional) user-defined context 7410c52818fSSatish Balay 7420c52818fSSatish Balay Level: beginner 7430c52818fSSatish Balay 7440c52818fSSatish Balay Note: 7450c52818fSSatish Balay Use this routine only if you want the line search objective and gradient 746441846f8SBarry Smith evaluation routines to be different from the Tao's objective 7470c52818fSSatish Balay and gradient evaluation routines. 7480c52818fSSatish Balay 7490c52818fSSatish Balay Note: 7500c52818fSSatish Balay Some algorithms (lcl, gpcg) set their own objective routine for the 7510c52818fSSatish Balay line search, application programmers should be wary of overriding the 7520c52818fSSatish Balay default objective routine. 7530c52818fSSatish Balay 754441846f8SBarry Smith .seealso: TaoLineSearchCreate(), TaoLineSearchSetObjectiveRoutine(), TaoLineSearchSetGradientRoutine(), TaoLineSearchUseTaoRoutines() 7550c52818fSSatish Balay @*/ 7560c52818fSSatish Balay PetscErrorCode TaoLineSearchSetObjectiveAndGradientRoutine(TaoLineSearch ls, PetscErrorCode(*func)(TaoLineSearch ls, Vec x, PetscReal *, Vec g, void*), void *ctx) 7570c52818fSSatish Balay { 7580c52818fSSatish Balay PetscFunctionBegin; 7590c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 7600c52818fSSatish Balay ls->ops->computeobjectiveandgradient=func; 7610c52818fSSatish Balay if (ctx) ls->userctx_funcgrad=ctx; 7620c52818fSSatish Balay ls->usetaoroutines = PETSC_FALSE; 7630c52818fSSatish Balay PetscFunctionReturn(0); 7640c52818fSSatish Balay } 7650c52818fSSatish Balay 7660c52818fSSatish Balay #undef __FUNCT__ 7670c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchSetObjectiveAndGTSRoutine" 7680c52818fSSatish Balay /*@C 7690c52818fSSatish Balay TaoLineSearchSetObjectiveAndGTSRoutine - Sets the objective and 7700c52818fSSatish Balay (gradient'*stepdirection) evaluation routine for the line search. 7710c52818fSSatish Balay Sometimes it is more efficient to compute the inner product of the gradient 7720c52818fSSatish Balay and the step direction than it is to compute the gradient, and this is all 7730c52818fSSatish Balay the line search typically needs of the gradient. 7740c52818fSSatish Balay 7750c52818fSSatish Balay Logically Collective on TaoLineSearch 7760c52818fSSatish Balay 7770c52818fSSatish Balay Input Parameter: 7780c52818fSSatish Balay + ls - the TaoLineSearch context 7790c52818fSSatish Balay . func - the objective and gradient evaluation routine 7800c52818fSSatish Balay - ctx - the (optional) user-defined context for private data 7810c52818fSSatish Balay 7820c52818fSSatish Balay Calling sequence of func: 7830c52818fSSatish Balay $ func (TaoLinesearch ls, Vec x, PetscReal *f, PetscReal *gts, void *ctx); 7840c52818fSSatish Balay 7850c52818fSSatish Balay + x - input vector 7860c52818fSSatish Balay . s - step direction 7870c52818fSSatish Balay . f - function value 7880c52818fSSatish Balay . gts - inner product of gradient and step direction vectors 7890c52818fSSatish Balay - ctx (optional) user-defined context 7900c52818fSSatish Balay 7910c52818fSSatish Balay Note: The gradient will still need to be computed at the end of the line 7920c52818fSSatish Balay search, so you will still need to set a line search gradient evaluation 7930c52818fSSatish Balay routine 7940c52818fSSatish Balay 7950c52818fSSatish Balay Note: Bounded line searches (those used in bounded optimization algorithms) 7960c52818fSSatish Balay don't use g's directly, but rather (g'x - g'x0)/steplength. You can get the 7970c52818fSSatish Balay x0 and steplength with TaoLineSearchGetStartingVector() and TaoLineSearchGetStepLength() 7980c52818fSSatish Balay 7990c52818fSSatish Balay Level: advanced 8000c52818fSSatish Balay 8010c52818fSSatish Balay Note: 8020c52818fSSatish Balay Some algorithms (lcl, gpcg) set their own objective routine for the 8030c52818fSSatish Balay line search, application programmers should be wary of overriding the 8040c52818fSSatish Balay default objective routine. 8050c52818fSSatish Balay 806441846f8SBarry Smith .seealso: TaoLineSearchCreate(), TaoLineSearchSetObjective(), TaoLineSearchSetGradient(), TaoLineSearchUseTaoRoutines() 8070c52818fSSatish Balay @*/ 8080c52818fSSatish Balay PetscErrorCode TaoLineSearchSetObjectiveAndGTSRoutine(TaoLineSearch ls, PetscErrorCode(*func)(TaoLineSearch ls, Vec x, Vec s, PetscReal *, PetscReal *, void*), void *ctx) 8090c52818fSSatish Balay { 8100c52818fSSatish Balay PetscFunctionBegin; 8110c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 8120c52818fSSatish Balay ls->ops->computeobjectiveandgts=func; 8130c52818fSSatish Balay if (ctx) ls->userctx_funcgts=ctx; 8140c52818fSSatish Balay ls->usegts = PETSC_TRUE; 8150c52818fSSatish Balay ls->usetaoroutines=PETSC_FALSE; 8160c52818fSSatish Balay PetscFunctionReturn(0); 8170c52818fSSatish Balay } 8180c52818fSSatish Balay 8190c52818fSSatish Balay #undef __FUNCT__ 820441846f8SBarry Smith #define __FUNCT__ "TaoLineSearchUseTaoRoutines" 8210c52818fSSatish Balay /*@C 822441846f8SBarry Smith TaoLineSearchUseTaoRoutines - Informs the TaoLineSearch to use the 823441846f8SBarry Smith objective and gradient evaluation routines from the given Tao object. 8240c52818fSSatish Balay 8250c52818fSSatish Balay Logically Collective on TaoLineSearch 8260c52818fSSatish Balay 8270c52818fSSatish Balay Input Parameter: 8280c52818fSSatish Balay + ls - the TaoLineSearch context 829441846f8SBarry Smith - ts - the Tao context with defined objective/gradient evaluation routines 8300c52818fSSatish Balay 8310c52818fSSatish Balay Level: developer 8320c52818fSSatish Balay 8330c52818fSSatish Balay .seealso: TaoLineSearchCreate() 8340c52818fSSatish Balay @*/ 835441846f8SBarry Smith PetscErrorCode TaoLineSearchUseTaoRoutines(TaoLineSearch ls, Tao ts) 8360c52818fSSatish Balay { 8370c52818fSSatish Balay PetscFunctionBegin; 8380c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 839441846f8SBarry Smith PetscValidHeaderSpecific(ts,TAO_CLASSID,1); 840441846f8SBarry Smith ls->tao = ts; 8410c52818fSSatish Balay ls->usetaoroutines=PETSC_TRUE; 8420c52818fSSatish Balay PetscFunctionReturn(0); 8430c52818fSSatish Balay } 8440c52818fSSatish Balay 8450c52818fSSatish Balay #undef __FUNCT__ 8460c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchComputeObjective" 8470c52818fSSatish Balay /*@ 8480c52818fSSatish Balay TaoLineSearchComputeObjective - Computes the objective function value at a given point 8490c52818fSSatish Balay 8500c52818fSSatish Balay Collective on TaoLineSearch 8510c52818fSSatish Balay 8520c52818fSSatish Balay Input Parameters: 8530c52818fSSatish Balay + ls - the TaoLineSearch context 8540c52818fSSatish Balay - x - input vector 8550c52818fSSatish Balay 8560c52818fSSatish Balay Output Parameter: 8570c52818fSSatish Balay . f - Objective value at X 8580c52818fSSatish Balay 8590c52818fSSatish Balay Notes: TaoLineSearchComputeObjective() is typically used within line searches 8600c52818fSSatish Balay so most users would not generally call this routine themselves. 8610c52818fSSatish Balay 8620c52818fSSatish Balay Level: developer 8630c52818fSSatish Balay 8640c52818fSSatish Balay .seealso: TaoLineSearchComputeGradient(), TaoLineSearchComputeObjectiveAndGradient(), TaoLineSearchSetObjectiveRoutine() 8650c52818fSSatish Balay @*/ 8660c52818fSSatish Balay PetscErrorCode TaoLineSearchComputeObjective(TaoLineSearch ls, Vec x, PetscReal *f) 8670c52818fSSatish Balay { 8680c52818fSSatish Balay PetscErrorCode ierr; 8690c52818fSSatish Balay Vec gdummy; 8700c52818fSSatish Balay PetscReal gts; 871f06e3bfaSBarry Smith 8720c52818fSSatish Balay PetscFunctionBegin; 8730c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 8740c52818fSSatish Balay PetscValidHeaderSpecific(x,VEC_CLASSID,2); 8750c52818fSSatish Balay PetscValidPointer(f,3); 8760c52818fSSatish Balay PetscCheckSameComm(ls,1,x,2); 8770c52818fSSatish Balay if (ls->usetaoroutines) { 878441846f8SBarry Smith ierr = TaoComputeObjective(ls->tao,x,f);CHKERRQ(ierr); 8790c52818fSSatish Balay } else { 8800c52818fSSatish Balay ierr = PetscLogEventBegin(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr); 881f06e3bfaSBarry Smith if (!ls->ops->computeobjective && !ls->ops->computeobjectiveandgradient && !ls->ops->computeobjectiveandgts) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Line Search does not have objective function set"); 8820c52818fSSatish Balay PetscStackPush("TaoLineSearch user objective routine"); 8830c52818fSSatish Balay if (ls->ops->computeobjective) { 8840c52818fSSatish Balay ierr = (*ls->ops->computeobjective)(ls,x,f,ls->userctx_func);CHKERRQ(ierr); 8850c52818fSSatish Balay } else if (ls->ops->computeobjectiveandgradient) { 8860c52818fSSatish Balay ierr = VecDuplicate(x,&gdummy);CHKERRQ(ierr); 8870c52818fSSatish Balay ierr = (*ls->ops->computeobjectiveandgradient)(ls,x,f,gdummy,ls->userctx_funcgrad);CHKERRQ(ierr); 8880c52818fSSatish Balay ierr = VecDestroy(&gdummy);CHKERRQ(ierr); 8890c52818fSSatish Balay } else { 8900c52818fSSatish Balay ierr = (*ls->ops->computeobjectiveandgts)(ls,x,ls->stepdirection,f,>s,ls->userctx_funcgts);CHKERRQ(ierr); 8910c52818fSSatish Balay } 8920c52818fSSatish Balay PetscStackPop; 8930c52818fSSatish Balay ierr = PetscLogEventEnd(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr); 8940c52818fSSatish Balay } 8950c52818fSSatish Balay ls->nfeval++; 8960c52818fSSatish Balay PetscFunctionReturn(0); 8970c52818fSSatish Balay } 8980c52818fSSatish Balay 8990c52818fSSatish Balay #undef __FUNCT__ 9000c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchComputeObjectiveAndGradient" 9010c52818fSSatish Balay /*@ 9020c52818fSSatish Balay TaoLineSearchComputeObjectiveAndGradient - Computes the objective function value at a given point 9030c52818fSSatish Balay 904441846f8SBarry Smith Collective on Tao 9050c52818fSSatish Balay 9060c52818fSSatish Balay Input Parameters: 9070c52818fSSatish Balay + ls - the TaoLineSearch context 9080c52818fSSatish Balay - x - input vector 9090c52818fSSatish Balay 9100c52818fSSatish Balay Output Parameter: 9110c52818fSSatish Balay + f - Objective value at X 9120c52818fSSatish Balay - g - Gradient vector at X 9130c52818fSSatish Balay 9140c52818fSSatish Balay Notes: TaoLineSearchComputeObjectiveAndGradient() is typically used within line searches 9150c52818fSSatish Balay so most users would not generally call this routine themselves. 9160c52818fSSatish Balay 9170c52818fSSatish Balay Level: developer 9180c52818fSSatish Balay 9190c52818fSSatish Balay .seealso: TaoLineSearchComputeGradient(), TaoLineSearchComputeObjectiveAndGradient(), TaoLineSearchSetObjectiveRoutine() 9200c52818fSSatish Balay @*/ 9210c52818fSSatish Balay PetscErrorCode TaoLineSearchComputeObjectiveAndGradient(TaoLineSearch ls, Vec x, PetscReal *f, Vec g) 9220c52818fSSatish Balay { 9230c52818fSSatish Balay PetscErrorCode ierr; 924f06e3bfaSBarry Smith 9250c52818fSSatish Balay PetscFunctionBegin; 9260c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 9270c52818fSSatish Balay PetscValidHeaderSpecific(x,VEC_CLASSID,2); 9280c52818fSSatish Balay PetscValidPointer(f,3); 9290c52818fSSatish Balay PetscValidHeaderSpecific(g,VEC_CLASSID,4); 9300c52818fSSatish Balay PetscCheckSameComm(ls,1,x,2); 9310c52818fSSatish Balay PetscCheckSameComm(ls,1,g,4); 9320c52818fSSatish Balay if (ls->usetaoroutines) { 933441846f8SBarry Smith ierr = TaoComputeObjectiveAndGradient(ls->tao,x,f,g);CHKERRQ(ierr); 9340c52818fSSatish Balay } else { 9350c52818fSSatish Balay ierr = PetscLogEventBegin(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr); 936f06e3bfaSBarry Smith if (!ls->ops->computeobjective && !ls->ops->computeobjectiveandgradient) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Line Search does not have objective function set"); 937f06e3bfaSBarry Smith if (!ls->ops->computegradient && !ls->ops->computeobjectiveandgradient) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Line Search does not have gradient function set"); 9380c52818fSSatish Balay 9390c52818fSSatish Balay PetscStackPush("TaoLineSearch user objective/gradient routine"); 9400c52818fSSatish Balay if (ls->ops->computeobjectiveandgradient) { 9410c52818fSSatish Balay ierr = (*ls->ops->computeobjectiveandgradient)(ls,x,f,g,ls->userctx_funcgrad);CHKERRQ(ierr); 9420c52818fSSatish Balay } else { 9430c52818fSSatish Balay ierr = (*ls->ops->computeobjective)(ls,x,f,ls->userctx_func);CHKERRQ(ierr); 9440c52818fSSatish Balay ierr = (*ls->ops->computegradient)(ls,x,g,ls->userctx_grad);CHKERRQ(ierr); 9450c52818fSSatish Balay } 9460c52818fSSatish Balay PetscStackPop; 9470c52818fSSatish Balay ierr = PetscLogEventEnd(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr); 948335036cbSBarry Smith ierr = PetscInfo1(ls,"TaoLineSearch Function evaluation: %14.12e\n",(double)(*f));CHKERRQ(ierr); 949f06e3bfaSBarry Smith } 950*fbe0838dSJason Sarich ls->nfgeval++; 9510c52818fSSatish Balay PetscFunctionReturn(0); 9520c52818fSSatish Balay } 9530c52818fSSatish Balay 9540c52818fSSatish Balay #undef __FUNCT__ 9550c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchComputeGradient" 9560c52818fSSatish Balay /*@ 9570c52818fSSatish Balay TaoLineSearchComputeGradient - Computes the gradient of the objective function 9580c52818fSSatish Balay 9590c52818fSSatish Balay Collective on TaoLineSearch 9600c52818fSSatish Balay 9610c52818fSSatish Balay Input Parameters: 9620c52818fSSatish Balay + ls - the TaoLineSearch context 9630c52818fSSatish Balay - x - input vector 9640c52818fSSatish Balay 9650c52818fSSatish Balay Output Parameter: 9660c52818fSSatish Balay . g - gradient vector 9670c52818fSSatish Balay 9680c52818fSSatish Balay Notes: TaoComputeGradient() is typically used within line searches 9690c52818fSSatish Balay so most users would not generally call this routine themselves. 9700c52818fSSatish Balay 9710c52818fSSatish Balay Level: developer 9720c52818fSSatish Balay 9730c52818fSSatish Balay .seealso: TaoLineSearchComputeObjective(), TaoLineSearchComputeObjectiveAndGradient(), TaoLineSearchSetGradient() 9740c52818fSSatish Balay @*/ 9750c52818fSSatish Balay PetscErrorCode TaoLineSearchComputeGradient(TaoLineSearch ls, Vec x, Vec g) 9760c52818fSSatish Balay { 9770c52818fSSatish Balay PetscErrorCode ierr; 9780c52818fSSatish Balay PetscReal fdummy; 979f06e3bfaSBarry Smith 9800c52818fSSatish Balay PetscFunctionBegin; 9810c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 9820c52818fSSatish Balay PetscValidHeaderSpecific(x,VEC_CLASSID,2); 9830c52818fSSatish Balay PetscValidHeaderSpecific(g,VEC_CLASSID,3); 9840c52818fSSatish Balay PetscCheckSameComm(ls,1,x,2); 9850c52818fSSatish Balay PetscCheckSameComm(ls,1,g,3); 9860c52818fSSatish Balay if (ls->usetaoroutines) { 987441846f8SBarry Smith ierr = TaoComputeGradient(ls->tao,x,g);CHKERRQ(ierr); 9880c52818fSSatish Balay } else { 9890c52818fSSatish Balay ierr = PetscLogEventBegin(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr); 990f06e3bfaSBarry Smith if (!ls->ops->computegradient && !ls->ops->computeobjectiveandgradient) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Line Search does not have gradient functions set"); 9910c52818fSSatish Balay PetscStackPush("TaoLineSearch user gradient routine"); 9920c52818fSSatish Balay if (ls->ops->computegradient) { 9930c52818fSSatish Balay ierr = (*ls->ops->computegradient)(ls,x,g,ls->userctx_grad);CHKERRQ(ierr); 9940c52818fSSatish Balay } else { 9950c52818fSSatish Balay ierr = (*ls->ops->computeobjectiveandgradient)(ls,x,&fdummy,g,ls->userctx_funcgrad);CHKERRQ(ierr); 9960c52818fSSatish Balay } 9970c52818fSSatish Balay PetscStackPop; 9980c52818fSSatish Balay ierr = PetscLogEventEnd(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr); 9990c52818fSSatish Balay } 10000c52818fSSatish Balay ls->ngeval++; 10010c52818fSSatish Balay PetscFunctionReturn(0); 10020c52818fSSatish Balay } 10030c52818fSSatish Balay 10040c52818fSSatish Balay #undef __FUNCT__ 10050c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchComputeObjectiveAndGTS" 10060c52818fSSatish Balay /*@ 10070c52818fSSatish Balay TaoLineSearchComputeObjectiveAndGTS - Computes the objective function value and inner product of gradient and step direction at a given point 10080c52818fSSatish Balay 1009441846f8SBarry Smith Collective on Tao 10100c52818fSSatish Balay 10110c52818fSSatish Balay Input Parameters: 10120c52818fSSatish Balay + ls - the TaoLineSearch context 10130c52818fSSatish Balay - x - input vector 10140c52818fSSatish Balay 10150c52818fSSatish Balay Output Parameter: 10160c52818fSSatish Balay + f - Objective value at X 10170c52818fSSatish Balay - gts - inner product of gradient and step direction at X 10180c52818fSSatish Balay 10190c52818fSSatish Balay Notes: TaoLineSearchComputeObjectiveAndGTS() is typically used within line searches 10200c52818fSSatish Balay so most users would not generally call this routine themselves. 10210c52818fSSatish Balay 10220c52818fSSatish Balay Level: developer 10230c52818fSSatish Balay 10240c52818fSSatish Balay .seealso: TaoLineSearchComputeGradient(), TaoLineSearchComputeObjectiveAndGradient(), TaoLineSearchSetObjectiveRoutine() 10250c52818fSSatish Balay @*/ 10260c52818fSSatish Balay PetscErrorCode TaoLineSearchComputeObjectiveAndGTS(TaoLineSearch ls, Vec x, PetscReal *f, PetscReal *gts) 10270c52818fSSatish Balay { 10280c52818fSSatish Balay PetscErrorCode ierr; 10290c52818fSSatish Balay PetscFunctionBegin; 10300c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 10310c52818fSSatish Balay PetscValidHeaderSpecific(x,VEC_CLASSID,2); 10320c52818fSSatish Balay PetscValidPointer(f,3); 10330c52818fSSatish Balay PetscValidPointer(gts,4); 10340c52818fSSatish Balay PetscCheckSameComm(ls,1,x,2); 10350c52818fSSatish Balay ierr = PetscLogEventBegin(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr); 1036f06e3bfaSBarry Smith if (!ls->ops->computeobjectiveandgts) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Line Search does not have objective and gts function set"); 10370c52818fSSatish Balay PetscStackPush("TaoLineSearch user objective/gts routine"); 10380c52818fSSatish Balay ierr = (*ls->ops->computeobjectiveandgts)(ls,x,ls->stepdirection,f,gts,ls->userctx_funcgts);CHKERRQ(ierr); 10390c52818fSSatish Balay PetscStackPop; 10400c52818fSSatish Balay ierr = PetscLogEventEnd(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr); 1041335036cbSBarry Smith ierr = PetscInfo1(ls,"TaoLineSearch Function evaluation: %14.12e\n",(double)(*f));CHKERRQ(ierr); 10420c52818fSSatish Balay ls->nfeval++; 10430c52818fSSatish Balay PetscFunctionReturn(0); 10440c52818fSSatish Balay } 10450c52818fSSatish Balay 10460c52818fSSatish Balay #undef __FUNCT__ 10470c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchGetSolution" 10480c52818fSSatish Balay /*@ 10490c52818fSSatish Balay TaoLineSearchGetSolution - Returns the solution to the line search 10500c52818fSSatish Balay 10510c52818fSSatish Balay Collective on TaoLineSearch 10520c52818fSSatish Balay 10530c52818fSSatish Balay Input Parameter: 10540c52818fSSatish Balay . ls - the TaoLineSearch context 10550c52818fSSatish Balay 10560c52818fSSatish Balay Output Parameter: 10570c52818fSSatish Balay + x - the new solution 10580c52818fSSatish Balay . f - the objective function value at x 10590c52818fSSatish Balay . g - the gradient at x 10600c52818fSSatish Balay . steplength - the multiple of the step direction taken by the line search 10610c52818fSSatish Balay - reason - the reason why the line search terminated 10620c52818fSSatish Balay 10630c52818fSSatish Balay reason will be set to one of: 10640c52818fSSatish Balay 10650c52818fSSatish Balay + TAOLINESEARCH_FAILED_INFORNAN - function evaluation gives Inf or Nan value 10660c52818fSSatish Balay . TAOLINESEARCH_FAILED_BADPARAMETER - negative value set as parameter 10670c52818fSSatish Balay . TAOLINESEARCH_FAILED_ASCENT - initial line search step * g is not descent direction 10680c52818fSSatish Balay . TAOLINESEARCH_HALTED_MAXFCN - maximum number of function evaluation reached 10690c52818fSSatish Balay . TAOLINESEARCH_HALTED_UPPERBOUND - step is at upper bound 10700c52818fSSatish Balay . TAOLINESEARCH_HALTED_LOWERBOUND - step is at lower bound 10710c52818fSSatish Balay . TAOLINESEARCH_HALTED_RTOL - range of uncertainty is smaller than given tolerance 10720c52818fSSatish Balay 10730c52818fSSatish Balay . TAOLINESEARCH_HALTED_USER - user can set this reason to stop line search 10740c52818fSSatish Balay . TAOLINESEARCH_HALTED_OTHER - any other reason 10750c52818fSSatish Balay 10760c52818fSSatish Balay + TAOLINESEARCH_SUCCESS - successful line search 10770c52818fSSatish Balay 10780c52818fSSatish Balay Level: developer 10790c52818fSSatish Balay 10800c52818fSSatish Balay @*/ 1081e4cb33bbSBarry Smith PetscErrorCode TaoLineSearchGetSolution(TaoLineSearch ls, Vec x, PetscReal *f, Vec g, PetscReal *steplength, TaoLineSearchConvergedReason *reason) 10820c52818fSSatish Balay { 10830c52818fSSatish Balay PetscErrorCode ierr; 1084f06e3bfaSBarry Smith 10850c52818fSSatish Balay PetscFunctionBegin; 10860c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 10870c52818fSSatish Balay PetscValidHeaderSpecific(x,VEC_CLASSID,2); 10880c52818fSSatish Balay PetscValidPointer(f,3); 10890c52818fSSatish Balay PetscValidHeaderSpecific(g,VEC_CLASSID,4); 10900c52818fSSatish Balay PetscValidIntPointer(reason,6); 10910c52818fSSatish Balay if (ls->new_x) { 10920c52818fSSatish Balay ierr = VecCopy(ls->new_x,x);CHKERRQ(ierr); 10930c52818fSSatish Balay } 10940c52818fSSatish Balay *f = ls->new_f; 10950c52818fSSatish Balay if (ls->new_g) { 10960c52818fSSatish Balay ierr = VecCopy(ls->new_g,g);CHKERRQ(ierr); 10970c52818fSSatish Balay } 10980c52818fSSatish Balay if (steplength) { 10990c52818fSSatish Balay *steplength=ls->step; 11000c52818fSSatish Balay } 11010c52818fSSatish Balay *reason = ls->reason; 11020c52818fSSatish Balay PetscFunctionReturn(0); 11030c52818fSSatish Balay } 11040c52818fSSatish Balay 11050c52818fSSatish Balay #undef __FUNCT__ 11060c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchGetStartingVector" 11070c52818fSSatish Balay /*@ 11080c52818fSSatish Balay TaoLineSearchGetStartingVector - Gets a the initial point of the line 11090c52818fSSatish Balay search. 11100c52818fSSatish Balay 11110c52818fSSatish Balay Not Collective 11120c52818fSSatish Balay 11130c52818fSSatish Balay Input Parameter: 11140c52818fSSatish Balay . ls - the TaoLineSearch context 11150c52818fSSatish Balay 11160c52818fSSatish Balay Output Parameter: 11170c52818fSSatish Balay . x - The initial point of the line search 11180c52818fSSatish Balay 11190c52818fSSatish Balay Level: intermediate 11200c52818fSSatish Balay @*/ 11210c52818fSSatish Balay PetscErrorCode TaoLineSearchGetStartingVector(TaoLineSearch ls, Vec *x) 11220c52818fSSatish Balay { 11230c52818fSSatish Balay PetscFunctionBegin; 11240c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 11250c52818fSSatish Balay if (x) { 11260c52818fSSatish Balay *x = ls->start_x; 11270c52818fSSatish Balay } 11280c52818fSSatish Balay PetscFunctionReturn(0); 11290c52818fSSatish Balay } 11300c52818fSSatish Balay 11310c52818fSSatish Balay #undef __FUNCT__ 11320c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchGetStepDirection" 11330c52818fSSatish Balay /*@ 11340c52818fSSatish Balay TaoLineSearchGetStepDirection - Gets the step direction of the line 11350c52818fSSatish Balay search. 11360c52818fSSatish Balay 11370c52818fSSatish Balay Not Collective 11380c52818fSSatish Balay 11390c52818fSSatish Balay Input Parameter: 11400c52818fSSatish Balay . ls - the TaoLineSearch context 11410c52818fSSatish Balay 11420c52818fSSatish Balay Output Parameter: 11430c52818fSSatish Balay . s - the step direction of the line search 11440c52818fSSatish Balay 11450c52818fSSatish Balay Level: advanced 11460c52818fSSatish Balay @*/ 11470c52818fSSatish Balay PetscErrorCode TaoLineSearchGetStepDirection(TaoLineSearch ls, Vec *s) 11480c52818fSSatish Balay { 11490c52818fSSatish Balay PetscFunctionBegin; 11500c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 11510c52818fSSatish Balay if (s) { 11520c52818fSSatish Balay *s = ls->stepdirection; 11530c52818fSSatish Balay } 11540c52818fSSatish Balay PetscFunctionReturn(0); 11550c52818fSSatish Balay 11560c52818fSSatish Balay } 11570c52818fSSatish Balay 11580c52818fSSatish Balay #undef __FUNCT__ 11590c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchGetFullStepObjective" 11600c52818fSSatish Balay /*@ 11610c52818fSSatish Balay TaoLineSearchGetFullStepObjective - Returns the objective function value at the full step. Useful for some minimization algorithms. 11620c52818fSSatish Balay 11630c52818fSSatish Balay Not Collective 11640c52818fSSatish Balay 11650c52818fSSatish Balay Input Parameter: 11660c52818fSSatish Balay . ls - the TaoLineSearch context 11670c52818fSSatish Balay 11680c52818fSSatish Balay Output Parameter: 11690c52818fSSatish Balay . f - the objective value at the full step length 11700c52818fSSatish Balay 11710c52818fSSatish Balay Level: developer 11720c52818fSSatish Balay @*/ 11730c52818fSSatish Balay 11740c52818fSSatish Balay PetscErrorCode TaoLineSearchGetFullStepObjective(TaoLineSearch ls, PetscReal *f_fullstep) 11750c52818fSSatish Balay { 11760c52818fSSatish Balay PetscFunctionBegin; 11770c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 11780c52818fSSatish Balay *f_fullstep = ls->f_fullstep; 11790c52818fSSatish Balay PetscFunctionReturn(0); 11800c52818fSSatish Balay } 11810c52818fSSatish Balay 11820c52818fSSatish Balay #undef __FUNCT__ 11830c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchSetVariableBounds" 11840c52818fSSatish Balay /*@ 11850c52818fSSatish Balay TaoLineSearchSetVariableBounds - Sets the upper and lower bounds. 11860c52818fSSatish Balay 1187441846f8SBarry Smith Logically Collective on Tao 11880c52818fSSatish Balay 11890c52818fSSatish Balay Input Parameters: 11900c52818fSSatish Balay + ls - the TaoLineSearch context 11910c52818fSSatish Balay . xl - vector of lower bounds 11920c52818fSSatish Balay - xu - vector of upper bounds 11930c52818fSSatish Balay 11940c52818fSSatish Balay Note: If the variable bounds are not set with this routine, then 1195e270355aSBarry Smith PETSC_NINFINITY and PETSC_INFINITY are assumed 11960c52818fSSatish Balay 11970c52818fSSatish Balay Level: beginner 11980c52818fSSatish Balay 11990c52818fSSatish Balay .seealso: TaoSetVariableBounds(), TaoLineSearchCreate() 12000c52818fSSatish Balay @*/ 12010c52818fSSatish Balay PetscErrorCode TaoLineSearchSetVariableBounds(TaoLineSearch ls,Vec xl, Vec xu) 12020c52818fSSatish Balay { 12030c52818fSSatish Balay PetscFunctionBegin; 12040c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 12050c52818fSSatish Balay PetscValidHeaderSpecific(xl,VEC_CLASSID,2); 12060c52818fSSatish Balay PetscValidHeaderSpecific(xu,VEC_CLASSID,3); 12070c52818fSSatish Balay ls->lower = xl; 12080c52818fSSatish Balay ls->upper = xu; 12090c52818fSSatish Balay ls->bounded = 1; 12100c52818fSSatish Balay PetscFunctionReturn(0); 12110c52818fSSatish Balay } 12120c52818fSSatish Balay 12130c52818fSSatish Balay #undef __FUNCT__ 12140c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchSetInitialStepLength" 12150c52818fSSatish Balay /*@ 12160c52818fSSatish Balay TaoLineSearchSetInitialStepLength - Sets the initial step length of a line 12170c52818fSSatish Balay search. If this value is not set then 1.0 is assumed. 12180c52818fSSatish Balay 12190c52818fSSatish Balay Logically Collective on TaoLineSearch 12200c52818fSSatish Balay 12210c52818fSSatish Balay Input Parameters: 12220c52818fSSatish Balay + ls - the TaoLineSearch context 12230c52818fSSatish Balay - s - the initial step size 12240c52818fSSatish Balay 12250c52818fSSatish Balay Level: intermediate 12260c52818fSSatish Balay 12270c52818fSSatish Balay .seealso: TaoLineSearchGetStepLength(), TaoLineSearchApply() 12280c52818fSSatish Balay @*/ 12290c52818fSSatish Balay PetscErrorCode TaoLineSearchSetInitialStepLength(TaoLineSearch ls,PetscReal s) 12300c52818fSSatish Balay { 12310c52818fSSatish Balay PetscFunctionBegin; 12320c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 12330c52818fSSatish Balay ls->initstep = s; 12340c52818fSSatish Balay PetscFunctionReturn(0); 12350c52818fSSatish Balay } 12360c52818fSSatish Balay 12370c52818fSSatish Balay #undef __FUNCT__ 12380c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchGetStepLength" 12390c52818fSSatish Balay /*@ 12400c52818fSSatish Balay TaoLineSearchGetStepLength - Get the current step length 12410c52818fSSatish Balay 12420c52818fSSatish Balay Not Collective 12430c52818fSSatish Balay 12440c52818fSSatish Balay Input Parameters: 12450c52818fSSatish Balay . ls - the TaoLineSearch context 12460c52818fSSatish Balay 12470c52818fSSatish Balay Output Parameters 12480c52818fSSatish Balay . s - the current step length 12490c52818fSSatish Balay 12500c52818fSSatish Balay Level: beginner 12510c52818fSSatish Balay 12520c52818fSSatish Balay .seealso: TaoLineSearchSetInitialStepLength(), TaoLineSearchApply() 12530c52818fSSatish Balay @*/ 12540c52818fSSatish Balay PetscErrorCode TaoLineSearchGetStepLength(TaoLineSearch ls,PetscReal *s) 12550c52818fSSatish Balay { 12560c52818fSSatish Balay PetscFunctionBegin; 12570c52818fSSatish Balay PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1); 12580c52818fSSatish Balay *s = ls->step; 12590c52818fSSatish Balay PetscFunctionReturn(0); 12600c52818fSSatish Balay } 12610c52818fSSatish Balay 12620c52818fSSatish Balay #undef __FUNCT__ 12630c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchRegister" 12640c52818fSSatish Balay /*MC 12650c52818fSSatish Balay TaoLineSearchRegister - Adds a line-search algorithm to the registry 12660c52818fSSatish Balay 12670c52818fSSatish Balay Not collective 12680c52818fSSatish Balay 12690c52818fSSatish Balay Input Parameters: 12700c52818fSSatish Balay + sname - name of a new user-defined solver 12710c52818fSSatish Balay - func - routine to Create method context 12720c52818fSSatish Balay 12730c52818fSSatish Balay Notes: 12740c52818fSSatish Balay TaoLineSearchRegister() may be called multiple times to add several user-defined solvers. 12750c52818fSSatish Balay 12760c52818fSSatish Balay Sample usage: 12770c52818fSSatish Balay .vb 12780c52818fSSatish Balay TaoLineSearchRegister("my_linesearch",MyLinesearchCreate); 12790c52818fSSatish Balay .ve 12800c52818fSSatish Balay 12810c52818fSSatish Balay Then, your solver can be chosen with the procedural interface via 12820c52818fSSatish Balay $ TaoLineSearchSetType(ls,"my_linesearch") 12830c52818fSSatish Balay or at runtime via the option 12840c52818fSSatish Balay $ -tao_ls_type my_linesearch 12850c52818fSSatish Balay 12860c52818fSSatish Balay Level: developer 12870c52818fSSatish Balay 12880c52818fSSatish Balay .seealso: TaoLineSearchRegisterDestroy() 12890c52818fSSatish Balay M*/ 12900c52818fSSatish Balay PetscErrorCode TaoLineSearchRegister(const char sname[], PetscErrorCode (*func)(TaoLineSearch)) 12910c52818fSSatish Balay { 12920c52818fSSatish Balay PetscErrorCode ierr; 12930c52818fSSatish Balay PetscFunctionBegin; 12940c52818fSSatish Balay ierr = PetscFunctionListAdd(&TaoLineSearchList, sname, (void (*)(void))func);CHKERRQ(ierr); 12950c52818fSSatish Balay PetscFunctionReturn(0); 12960c52818fSSatish Balay } 12970c52818fSSatish Balay 12980c52818fSSatish Balay #undef __FUNCT__ 12990c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchRegisterDestroy" 13000c52818fSSatish Balay /*@C 13010c52818fSSatish Balay TaoLineSearchRegisterDestroy - Frees the list of line-search algorithms that were 13020c52818fSSatish Balay registered by TaoLineSearchRegister(). 13030c52818fSSatish Balay 13040c52818fSSatish Balay Not Collective 13050c52818fSSatish Balay 13060c52818fSSatish Balay Level: developer 13070c52818fSSatish Balay 13080c52818fSSatish Balay .seealso: TaoLineSearchRegister() 13090c52818fSSatish Balay @*/ 13100c52818fSSatish Balay PetscErrorCode TaoLineSearchRegisterDestroy(void) 13110c52818fSSatish Balay { 13120c52818fSSatish Balay PetscErrorCode ierr; 13130c52818fSSatish Balay PetscFunctionBegin; 13140c52818fSSatish Balay ierr = PetscFunctionListDestroy(&TaoLineSearchList);CHKERRQ(ierr); 13150c52818fSSatish Balay TaoLineSearchInitialized = PETSC_FALSE; 13160c52818fSSatish Balay PetscFunctionReturn(0); 13170c52818fSSatish Balay } 13180c52818fSSatish Balay 13190c52818fSSatish Balay #undef __FUNCT__ 13200c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchAppendOptionsPrefix" 13210c52818fSSatish Balay /*@C 13220c52818fSSatish Balay TaoLineSearchAppendOptionsPrefix - Appends to the prefix used for searching 13230c52818fSSatish Balay for all TaoLineSearch options in the database. 13240c52818fSSatish Balay 13250c52818fSSatish Balay 13260c52818fSSatish Balay Collective on TaoLineSearch 13270c52818fSSatish Balay 13280c52818fSSatish Balay Input Parameters: 13290c52818fSSatish Balay + ls - the TaoLineSearch solver context 13300c52818fSSatish Balay - prefix - the prefix string to prepend to all line search requests 13310c52818fSSatish Balay 13320c52818fSSatish Balay Notes: 13330c52818fSSatish Balay A hyphen (-) must NOT be given at the beginning of the prefix name. 13340c52818fSSatish Balay The first character of all runtime options is AUTOMATICALLY the hyphen. 13350c52818fSSatish Balay 13360c52818fSSatish Balay 13370c52818fSSatish Balay Level: advanced 13380c52818fSSatish Balay 13390c52818fSSatish Balay .seealso: TaoLineSearchSetOptionsPrefix(), TaoLineSearchGetOptionsPrefix() 13400c52818fSSatish Balay @*/ 13410c52818fSSatish Balay PetscErrorCode TaoLineSearchAppendOptionsPrefix(TaoLineSearch ls, const char p[]) 13420c52818fSSatish Balay { 1343f06e3bfaSBarry Smith return PetscObjectAppendOptionsPrefix((PetscObject)ls,p); 13440c52818fSSatish Balay } 13450c52818fSSatish Balay 13460c52818fSSatish Balay #undef __FUNCT__ 13470c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchGetOptionsPrefix" 13480c52818fSSatish Balay /*@C 13490c52818fSSatish Balay TaoLineSearchGetOptionsPrefix - Gets the prefix used for searching for all 13500c52818fSSatish Balay TaoLineSearch options in the database 13510c52818fSSatish Balay 13520c52818fSSatish Balay Not Collective 13530c52818fSSatish Balay 13540c52818fSSatish Balay Input Parameters: 13550c52818fSSatish Balay . ls - the TaoLineSearch context 13560c52818fSSatish Balay 13570c52818fSSatish Balay Output Parameters: 13580c52818fSSatish Balay . prefix - pointer to the prefix string used is returned 13590c52818fSSatish Balay 13600c52818fSSatish Balay Notes: On the fortran side, the user should pass in a string 'prefix' of 13610c52818fSSatish Balay sufficient length to hold the prefix. 13620c52818fSSatish Balay 13630c52818fSSatish Balay Level: advanced 13640c52818fSSatish Balay 13650c52818fSSatish Balay .seealso: TaoLineSearchSetOptionsPrefix(), TaoLineSearchAppendOptionsPrefix() 13660c52818fSSatish Balay @*/ 13670c52818fSSatish Balay PetscErrorCode TaoLineSearchGetOptionsPrefix(TaoLineSearch ls, const char *p[]) 13680c52818fSSatish Balay { 1369f06e3bfaSBarry Smith return PetscObjectGetOptionsPrefix((PetscObject)ls,p); 13700c52818fSSatish Balay } 13710c52818fSSatish Balay 13720c52818fSSatish Balay #undef __FUNCT__ 13730c52818fSSatish Balay #define __FUNCT__ "TaoLineSearchSetOptionsPrefix" 13740c52818fSSatish Balay /*@C 13750c52818fSSatish Balay TaoLineSearchSetOptionsPrefix - Sets the prefix used for searching for all 13760c52818fSSatish Balay TaoLineSearch options in the database. 13770c52818fSSatish Balay 13780c52818fSSatish Balay 13790c52818fSSatish Balay Logically Collective on TaoLineSearch 13800c52818fSSatish Balay 13810c52818fSSatish Balay Input Parameters: 13820c52818fSSatish Balay + ls - the TaoLineSearch context 13830c52818fSSatish Balay - prefix - the prefix string to prepend to all TAO option requests 13840c52818fSSatish Balay 13850c52818fSSatish Balay Notes: 13860c52818fSSatish Balay A hyphen (-) must NOT be given at the beginning of the prefix name. 13870c52818fSSatish Balay The first character of all runtime options is AUTOMATICALLY the hyphen. 13880c52818fSSatish Balay 13890c52818fSSatish Balay For example, to distinguish between the runtime options for two 13900c52818fSSatish Balay different line searches, one could call 13910c52818fSSatish Balay .vb 13920c52818fSSatish Balay TaoLineSearchSetOptionsPrefix(ls1,"sys1_") 13930c52818fSSatish Balay TaoLineSearchSetOptionsPrefix(ls2,"sys2_") 13940c52818fSSatish Balay .ve 13950c52818fSSatish Balay 13960c52818fSSatish Balay This would enable use of different options for each system, such as 13970c52818fSSatish Balay .vb 13980c52818fSSatish Balay -sys1_tao_ls_type mt 13990c52818fSSatish Balay -sys2_tao_ls_type armijo 14000c52818fSSatish Balay .ve 14010c52818fSSatish Balay 14020c52818fSSatish Balay Level: advanced 14030c52818fSSatish Balay 14040c52818fSSatish Balay .seealso: TaoLineSearchAppendOptionsPrefix(), TaoLineSearchGetOptionsPrefix() 14050c52818fSSatish Balay @*/ 14060c52818fSSatish Balay 14070c52818fSSatish Balay PetscErrorCode TaoLineSearchSetOptionsPrefix(TaoLineSearch ls, const char p[]) 14080c52818fSSatish Balay { 1409f06e3bfaSBarry Smith return PetscObjectSetOptionsPrefix((PetscObject)ls,p); 14100c52818fSSatish Balay } 1411