PETSC Style Guide ================= The PETSc team uses certain conventions to make the source code consistent and hence easier to maintain. We will interchangeably use the terminology *subclass*, *implementation*, or *type* [1]_ to refer to a concrete realization of an abstract base class. For example, ``KSPGMRES`` is a type for the base class ``KSP``. Names ----- Consistency of names for variables, functions, and so on is extremely important. We use several conventions #. All function names and enum types consist of acronyms or words, each of which is capitalized, for example, ``KSPSolve()`` and ``MatGetOrdering()``. #. All enum elements and macro variables are named with all capital letters. When they consist of several complete words, there is an underscore between each word. For example, ``MATFINALASSEMBLY``. #. Functions that are private to PETSc (not callable by the application code) either - have an appended ``Private`` (for example, ``StashValuesPrivate``) or - have an appended ``Subtype`` (for example, ``MatMultSeqAIJ``). In addition, functions that are not intended for use outside of a particular file are declared ``static``. Also see item [styleitem:petscextern] in Section [sec:stylepetsc]. #. Function names in structures (for example, ``matops``) are the same as the base application function name without the object prefix and are in small letters. For example, ``MatMultTranspose()`` has a structure name of ``multtranspose``. #. Names of implementations of class functions should begin with the function name, an underscore, and the name of the implementation, for example, ``KSPSolveGMRES()``. #. Each application-usable function begins with the name of the class object, followed by any subclass name, for example, ``ISInvertPermutation()``, ``MatMult()``, or ``KSPGMRESSetRestart()``. #. Functions that PETSc provides as defaults for user-providable functions end with ``Default`` (for example, ``KSPMonitorDefault()`` or ``PetscSignalHandlerDefault()``). #. Options database keys are lower case, have an underscore between words, and match the function name associated with the option without the word “set” or “get”, for example, ``-kspgmresrestart``. #. Specific ``XXXType`` values (for example, ``MATSEQAIJ``) do not have an underscore in them unless they refer to another package that uses an underscore, for example, ``MATSOLVERSUPERLUDIST``. Coding Conventions and Style ---------------------------- Within the PETSc source code, we adhere to the following guidelines so that the code is uniform and easily maintained. C Formatting ~~~~~~~~~~~~ #. *No* tabs are allowed in *any* of the source code. #. All PETSc function bodies are indented two characters. #. Each additional level of loops, ``if`` statements, and so on is indented two more characters. #. Wrapping lines should be avoided whenever possible. #. Source code lines do not have a hard length limit; generally, we like them less than 150 characters wide. #. The local variable declarations should be aligned. For example, use the style :: PetscScalar a; PetscInt i,j; instead of :: PetscScalar a; PetscInt i,j; /* Incorrect */ #. Assignment and comparison operations, for example, ``x = 22.0`` or ``x < 22.0``, should have single spaces around the operator. This convention is true even when assignments are given directly in a line that declares the variable, such as ``PetscReal r = 22.3``. The exception is when these symbols are used in a ``for`` loop; then, there should be no spaces, for example, ``for (i=0; i