Fortran Programs with Modules

A module is a type of program unit that contains specifications of such entities as data objects, parameters, structures, procedures, and operators. These specifications and definitions can be used by one or more program units. Partial or complete access to the module entities is provided by the USE statement. Typical applications of modules are the specification of global data or the specification of a derived type and its associated operations.

For detailed information about Fortran modules, refer to Chapter 7 in the Intel Fortran Programmer's Reference.

The programs in which modules are defined support such compilation mechanisms as  parallel invocations with make files for Inter-procedural optimizations of multiple files and of the whole program.  The programs that require modules located in multiple directories, can be compiled using the -Idir option to locate the .mod files (modules) that should be included in the program.

The current version of the Intel® Fortran Compiler does not support VAX
STRUCTURES or Cray pointers within the Fortran modules.

Specifying the .mod Files Location

With the -module[path] option, you can specify the directory where you need to store the .mod files. The option has the following versions:


The path specifies the directory to rout the module files to.


The module files are placed in the same directory as the object files. Should a path be specified with the -object option, that location would also be used for the .mod files.


The module files are placed in the same directory where the source files are being compiled.

You need to ensure that the module files are created before they are referenced by another program or subprogram.

Compiling Programs with Modules

If a file being compiled has one or more modules defined in it, the compiler generates one or more .mod files. For example, a file a.f90 contains modules defined as follows:

module test
integer:: a
subroutine foo()
end subroutine
end module

module foobar
end module

The compile command:

prompt>ifc -c a.f90

generates the following three files:

The names of the .mod files are in uppercase; the name of the program file is not changed in the object file.

The .mod files contain the necessary information regarding the modules that have been defined in the program a.f90.

If the program does not contain a module, no .mod file is generated. For example, test2.f90 does not contain any modules. The compile command:

prompt>ifc -c test2.f90

produces just an object file, test2.o.

Working with Multimodule Programs

By default, the ifc (IA-32 compiler) or efc (ItaniumŪ compiler) command compiles each program unit for multimodule usage in the FCE. There are two ways (described below) of working with multimodule programs depending on the scale of your project.

Small-Scale Projects

In a small-scale project, the source files are in a single directory, so module management is not an issue. A simple way to compile and use modules is to incorporate a module before a program unit that references it  with USE. In this case, sources may be compiled and linked in the same way as FORTRAN 77 sources; for example if file1.f90 contains one or more modules and file2.f90 contains one or more program units that call these modules with the USE statement. The sources may be compiled and linked by the commands:

IA-32 applications:

prompt>ifc file1.f90 file2.f90 or

prompt>ifc -c file1.f90 (where the -c option stops the compilation after an .o file has been created)

prompt>ifc file1.o file2.f90

ItaniumŪ-based applications:

Use efl instead of ifl command, the rest is the same.

Searching and Locating the .mod Files in Large-Scale Projects

To manage modules in a large-scale software project, when the .mod files could be produced in different directories, the Intel® Fortran Compiler uses the -Idir option to specify the location of the .mod files.  For example, your program mod_def.f90 resides in directory /usr/yourdir/test/t, and this program contains a module defined as follows:

file: mod_def.f90
module definedmod
end module

The compile command:

prompt>ifc -c mod_def.f90

produces two files: mod_def.o and DEFINEDMOD.mod in directory /usr/yourdir/test/t.

If you need to use the above .mod file in another directory, for example, in directory /usr/yourdir/test/t2, where the program foo needs to use the DEFINEDMOD.mod file, implement the use statement as follows:

file: use_mod_def.f90
program foo
end program

To compile the above program, issue command:

prompt>ifc -c use_mod_def.f90 -I/usr/yourdir/test/t

where the -Idir  option provides the compiler with the path to search and locate the DEFINEDMOD.mod file.

Parallel Invocations with Makefile

The programs in which modules are defined, support the compilation mechanisms, such as parallel invocations with makefile for inter-procedural optimizations of multiple files. Consider the following code.

module foo
end module

subroutine bar()
use foo
end subroutine

subroutine foobar ()
use foo
end subroutine

The makefile to compile the above code looks like this:

FOO.mod: test1.o
ifc -c test1.f90
test2.o: FOO.mod
ifc -c test2.f90
test3.o: FOO.mod
ifc -c test3.f90