PETSc supports the use of complex numbers in application programs written in C, C++, and Fortran. To do so, we employ C++ versions of the PETSc libraries in which the basic ``scalar'' datatype, given in PETSc codes by Scalar, is defined as complex (or complex<double> for machines using templated complex class libraries). To work with complex numbers, the user should compile the PETSc libraries (including the Fortran interface library) and the application code with BOPT=[g_complex,O_complex] for debugging, optimized, and profiling versions, respectively. The file ${}PETSC_DIR/docs/installation.html provides detailed instructions for installing PETSc.
We recommend using optimized Fortran kernels for some key numerical routines with complex numbers (such as matrix-vector products, vector norms, etc.) instead of the default C++ routines. See the ``Complex Numbers'' section of the file ${}PETSC_DIR/docs/installation.html for details on building these kernels. This implementation exploits the maturity of Fortran compilers while retaining the identical user interface. For example, on rs6000 machines, the base single-node performance when using the Fortran kernels is 4-5 times faster than the default C++ code.
Recall that each variant of the PETSc libraries is stored in a different directory, given by ${}PETSC_DIR/lib/lib${}BOPT/${}PETSC_ARCH, according to the architecture and BOPT optimization variable. Thus, the libraries for complex numbers are maintained separately from those for real numbers. When using any of the complex numbers versions of PETSc, all vector and matrix elements are treated as complex, even if their imaginary components are zero. Of course, one can elect to use only the real parts of the complex numbers when using the complex versions of the PETSc libraries; however, when working only with real numbers in a code, one should use a version of PETSc for real numbers for best efficiency.
The program ${}PETSC_DIR/src/sles/examples/tutorials/ex11.c solves a linear system with a complex coefficient matrix. Its Fortran counterpart is ${}PETSC_DIR/src/sles/examples/tutorials/ex11f.F.