2
$\begingroup$

I've been trying to use a PetscBag to read in a number of options I want to pass to a program I'm writing. Before I came across the documentation for PetscBag, I was planning on using a struct and a function that would take the struct and use PetscOptionsGetSometype() to set all the values in the struct.

I figured that PetscBag would save some code, but seeing as each variable in the PetscBag has to use PetscOptionsRegisterSometype(), it looks to be just as much code to use the PetscBag as not to use it.

On the other hand, I don't know that much about how the struct I was going to use would work when run with MPI.

What should a PetscBag be used for? What advantages do they have over vanilla structs?

$\endgroup$

1 Answer 1

3
$\begingroup$

Items in a PetscBag are self-documenting though the associated help strings (seen when you run with -help and with PetscBagView(), can be overridden at run-time through the options database (-prefix_fieldname 4.2e7), and are serializable in ASCII and portable binary. With a normal struct, you have to write code to take input, supply help, and serialize (including dealing with backward compatibility as you add new fields).

It's a reasonable thing to use for a collection of problem-specific data, e.g. specification of a physical model configuration. It's not a good place to put "problem-sized data" such as an unstructured mesh or high-dimensional observational data.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.