%===================================================================================
\section{Fortran example problems}\label{s:ex_fortran}
%===================================================================================

The {\F} example problem programs supplied with the {\cvode}
package are all written in standard {\F}77 and use double precision
arithmetic.  Before running any of these examples, the user should
make sure that the {\F} data types for real and integer variables
appropriately match the {\CC} types.  See \S\ref{ss:fcdata} in the
{\cvode} User Document for details.

\subsection{A serial example: fcvDiurnal\_kry}\label{ss:fcvDiurnal} 
The \id{fcvDiurnal\_kry} example is a {\F} equivalent of the \id{cvDiurnal\_kry} problem.
(In fact, it was derived from an earlier {\F} example program for VODPK.)

The main program begins with a call to \id{INITKX}, which sets problem
parameters, loads these into arrays \id{IPAR} and \id{RPAR} for use by other
routines, and loads \id{Y} (here called \id{U0}) with its initial values.
\id{Main} calls \id{FNVINITS}, \id{FSUNSPGMRINIT}, \id{FSUNSPGMRSETGSTYPE}, 
\id{FCVMALLOC}, \id{FCVLSINIT}, and \id{FCVLSSETPREC},
to initialize the {\nvecs} module, the {\sunlinsolspgmr} module, the
main solver memory, and the {\cvls} interface, 
and to specify user-supplied preconditioner setup and solve routines.
It calls \id{FCVODE} in a loop over \id{TOUT} values, with printing of
selected solution values and performance data (from the \id{IOUT}  and \id{ROUT}
arrays).  At the end, it prints a number of performance counters, and
frees memory with calls to \id{FCVFREE}.

In \id{fcvDiurnal\_kry.f}, the \id{FCVFUN} routine is a straghtforward implementation
of the discretized form of Eqns. (\ref{cvDiurnalpde}).  In \id{FCVPSET}, the
block-diagonal part of the Jacobian, $J_{bd}$, is computed (and copied to
\id{P}) if \id{JOK} = 0, but is simply copied from \id{BD} to \id{P} if
\id{JOK} = 1.  In both cases, the preconditioner matrix $P$ is formed from 
$J_{bd}$ and its $2 \times 2$ blocks are LU-factored.  In \id{FCVPSOL},
the solution of a linear system $Px = z$ is solved by doing backsolve
operations on the blocks.  Subordinate routines are used to isolate
these evaluation, factorization, and backsolve operations.
The remainder of \id{fcvDiurnal\_kry.f} consists of
routines from LINPACK and the BLAS needed for matrix and vector operations.

The following is sample output from \id{fcvDiurnal\_kry}, using a $10 \times 10$ mesh.
The performance of {\fcvode} here is quite similar to that of {\cvode} on
the \id{cvDiurnal\_kry} problem, as expected.

%%
\includeOutput{fcvDiurnal\_kry}{../../examples/cvode/fcmix_serial/fcvDiurnal_kry.out}
%%

%-----------------------------------------------------------------------------------

\subsection{A parallel example: fcvDiag\_kry\_bbd\_p}\label{ss:fcvDiag_bbd_p}

This example, \id{fcvDiag\_kry\_bbd\_p}, uses a simple diagonal ODE system to illustrate
the use of {\fcvode} in a parallel setting.  The system is
\begin{equation} \label{diagode}
\dot{y}_i = - \alpha ~i~ y_i ~~~ (i = 1,\ldots, N)
\end{equation}
on the time interval $0 \leq t \leq 1$.  In this case, we use $\alpha = 10$
and $N = 10*$\id{NPES}, where \id{NPES} is the number of processors
and is specified at run time.  The linear solver to be used is
{\spgmr} with the {\cvbbdpre} (band-block-diagonal) preconditioner.
Since the system Jacobian is diagonal, the half-bandwidths specified
are all zero.  The problem is solved twice --- with preconditioning on
the left, then on the right.

The source file for this problem begins with MPI calls to initialize
MPI and to get the number of processors and local processor index.
\id{FNVINITP} is called to initialize the MPI-parallel {\nvector}
module, while \id{FSUNSPGMRINIT} and \id{FSUNSPGMRSETGSTYPE} are
called to initialize the {\spgmr} {\sunlinsol} module.
Following the call to \id{FCVMALLOC}, the linear solver and
preconditioner are attached to {\cvode} with calls to
\id{FCVLSINIT} and \id{FCVBBDINIT}.  In a loop over \id{TOUT} 
values, it calls \id{FCVODE} and prints the step and $f$ evaluation counters.
After that, it computes and prints the maximum global error, and all the
relevant performance counters.  Those specific to {\cvbbdpre} are obtained
by a call to \id{FCVBBDOPT}.  To prepare for the second run, the program
calls \id{FCVREINIT}, \id{FCVBBDREINIT}, and \id{FSUNSPGMRSETPRECTYPE}, 
in addition to resetting the initial conditions.  Finally, it frees
memory and terminates MPI. Notice that in the \id{FCVFUN} routine, the
local processor index \id{MYPE} and the local vector size \id{NLOCAL}
are used to form the global index values needed to evaluate the
right-hand side of Eq. (\ref{diagode}). 

The following is a sample output from \id{fcvDiag\_kry\_bbd\_p}, with \id{NPES} = 4.
As expected, the performance is identical for left vs right preconditioning.

%%
\includeOutput{fcvDiag\_kry\_bbd\_p}{../../examples/cvode/fcmix_parallel/fcvDiag_kry_bbd_p.out}
%%

%-----------------------------------------------------------------------------------
