# Calling PDE Support Routines from Fortran 90

The calling interface for all the Intel MKL TT and PL routines is designed to be easily used in C. However, you can invoke each TT or PL routine directly from Fortran 90 if you are familiar with the inter-language calling conventions of your platform.

The TT or PL interface cannot be invoked from Fortran 77 due to restrictions imposed by the use of the Intel MKL FFT interface.

The inter-language calling conventions include, but are not limited to, the argument passing mechanisms for the language, the data type mappings from C to Fortran 90 and how C external names are decorated on the platform.

To promote portability and relieve a user of dealing with the calling conventions specifics, Fortran 90 header file mkl_trig_transforms.f90 for TT routines and mkl_poisson.f90 for PL routines, used together with mkl_dfti.f90, declare a set of macros and introduce type definitions intended to hide the inter-language calling conventions and provide an interface to the routines that looks natural in Fortran 90.

For example, consider a hypothetical library routine, foo, which takes a double-precision vector of length n. C users access such a function as follows:

int n;

double *x;

…

foo(x, &n);

As noted above, to invoke `foo`, Fortran 90 users would need to know what Fortran 90 data types correspond to C types `int` and `double` (or `float` in case of single-precision), what argument-passing mechanism the C compiler uses and what, if any, name decoration is performed by the C compiler when generating the external symbol `foo`. However, with the Fortran 90 header files mkl_trig_transforms.f90 / mkl_poisson.f90 and mkl_dfti.f90 included, the invocation of `foo` within a Fortran 90 program will look as follows:

- For TT interface,

  use mkl_dfti

  use mkl_trig_transforms

  INTEGER n

  DOUBLE PRECISION, ALLOCATABLE :: x

  …

  CALL FOO(x,n)

- For PL interface,

  use mkl_dfti

  use mkl_poisson

  INTEGER n

  DOUBLE PRECISION, ALLOCATABLE :: x

  …

  CALL FOO(x,n)

Note that in the above example, the header files mkl_trig_transforms.f90 / mkl_poisson.f90 and mkl_dfti.f90 provide a definition for the subroutine `FOO`. To ease the use of PL or TT routines in Fortran 90, the general approach of providing Fortran 90 definitions of names is used throughout the libraries. Specifically, if a name from a PL or TT interface is documented as having the C-specific name `foo`, then the Fortran 90 header files provide an appropriate Fortran 90 language type definition `FOO`.

One of the key differences between Fortran 90 and C is the language argument-passing mechanism: C programs use pass-by-value semantics and Fortran 90 programs use pass-by-reference semantics. The Fortran 90 headers ensure proper treatment of this difference. In particular, in the above example, the header files mkl_trig_transforms.f90 / mkl_poisson.f90 and mkl_dfti.f90 hide the difference by defining a macro FOO that takes the address of the appropriate arguments.

Parent topic: Partial Differential Equations Support