Skip to content

Coding Style

Rob Falgout edited this page Nov 2, 2021 · 18 revisions

This document outlines coding style guidelines for hypre.

The coding style for hypre was based originally on those developed in the ISE project in CASC in 1998, but it was not strictly enforced.

Indentation

Indentation is automated using Artistic Style (astyle) and the configuration file src/config/astylerc. The basic style used is Allman with 3 spaces of indentation and a maximum line length of 100 characters.

Developers are encouraged to install astyle and use it before committing new code. To do this, ensure that astyle is in your path and run the src/config/astyle-apply.sh script as follows (for example) from the src directory (note that the script will also generate the _hypre_*.h header files):

config/astyle-apply.sh .

Also consider installing the pre-commit git hook in src/config/githooks to do this automatically on each git commit.

Naming Conventions

Functions and macros with parameters should be named as follows:

HYPRE_MixedCase(...)          /* User interface routines */
hypre_MixedCase(...)          /* Internal non-user routines */

Macros without parameters should be named as follows:

HYPRE_ALL_CAPS          /* User interface macros */
hypre_ALL_CAPS          /* Internal non-user macros */

Types should be named as follows:

HYPRE_MixedCase          /* User interface types */
hypre_MixedCase          /* Internal non-user types */

It is preferred that variables be named as follows so that it is easy to distinguish variables from functions and macros:

lower_case_with_underscores

Functions

Function parameters should be ordered as: input, input/output, output. One exception is that hypre object names should always appear first in the argument list. For example, a routine for setting the coefficients of a matrix object should look like as follows, even though matrix_object is an input/output parameter:

HYPRE_SetMatrixCoeffs(matrix_object, ...)

Functions should have integer return values to indicate error codes.

Fortran

Fortran 90/95 limits function names to 31 characters and this is the current practice in hypre's Fortran interface. The last argument in Fortran interface functions should be an integer error code.

Clone this wiki locally