# What does PetscBagSetFromOptions() do?

I'm writing a program that uses PETSc and SLEPc, and I was looking for a convienient way to read in options from the command line. The description of PetscBagSetFromOptions() in the official documentation says it "allows setting options from a bag". Does this mean that if I create a bag with a variety of PetscFoo elements I can read in my program's parameters from the command line without having to use PetscOptionsGetInt() and other functions like it?

-

## 1 Answer

It appears from the code, linked on the very page you have described, that PetscBagSetFromOptions literally just goes through the bag's item names and checks to see if they are in the options database (by appending - in front and using PetscOptionsInt, PetscOptionsReal, etc.).

It's silly that the linked examples, however, use this redundantly with the PetscOptionsXXX routines, so I can see why this might be confusing.

Requests like this may be sent to petsc-users@mcs.anl.gov.

-
Do you mean it sets the items in the bag by their names, or just checks to see if they are in the options database? I don't know enough about PetscOptionsBegin() and PetscOptionsSometype() to tell the difference from the source. –  Dan Mar 13 '12 at 0:04
It uses the values if they are set in the options database (via the command line, environment variable, configuration file, etc). –  Jed Brown Mar 13 '12 at 2:51
@Jed Brown: Thanks! –  Dan Mar 13 '12 at 4:05