Module Symbol Files
Rafik_Zurob 270003B2DK Visits (9840)
You might have noticed that the compiler creates files with the mod file extension. These are what we call module symbol files.
A module symbol file contains information about the specification part of a Fortran module. The file name is made of the module name followed by the mod extension. For example, if your Fortran module is called weather, the compiler will generate a module symbol file called weather.mod. The same module symbol file can be used in 32-bit and 64-bit compilations, provided you add the required information to it.
Let's look at an example:
$ cat test.f module m integer i contains subroutine sub print *, i end subroutine end module $ cat main.f use m i = 10 call sub end
This contrived example has two files: test.f and main.f. test.f defines a module m that has a module variable and a module procedure. main.f uses module m, initializes the variable and calls the module procedure.
Compiling test.f generates two files: m.mod and test.o. m.mod contains information about module variable i, and the interface of module procedure sub. test.o contains the object code for module procedure sub.
$ xlf95 test.f -c ** m === End of Compilation 1 === 1501-510 Compilation successful for file test.f. $ ls m.mod main.f test.f test.o $
The module symbol file also contains information about the version of the compiler that generated it, the date of compilation, and the bit modes the module symbol file supports. You can access this information via the what command on AIX, or the strings -a m.mod | grep '(#)' command on Linux.
$ what m.mod m.mod: Module symbol file for module:m Bit mode:32 Produced by:IBM XL Fortran for AIX, V13.1 (5724-X15) Version 13.01.0000.0009 03/08/12 17:45:14 From file:test.f
Using the module symbol file
When it sees a USE statement, the compiler automatically searches for a module symbol file matching the name and bit mode of the module name specified in the
$ xlf95 main.f -c ** _main === End of Compilation 1 === 1501-510 Compilation successful for file main.f.
Since the module symbol file above only supports 32-bit mode, it won't work in 64-bit mode:
$ xlf95 main.f -c -q64 "main.f", line 1.5: 1514-267 (S) The current program unit has a different setting for the -q64 option than was specified in the module m. Unexpected errors may result. ** _main === End of Compilation 1 === 1501-511 Compilation failed for file main.f.
To add support for 64-bit mode, recompile the module with -q64. If you don't delete the existing module symbol file, the 64-bit specification information will be added to it.
$ what m.mod m.mod: Module symbol file for module:m Bit mode:32 Produced by:IBM XL Fortran for AIX, V13.1 (5724-X15) Version 13.01.0000.0009 03/08/12 17:45:14 From file:test.f Module symbol file for module:m Bit mode:64 Produced by:IBM XL Fortran for AIX, V13.1 (5724-X15) Version 13.01.0000.0009 03/08/12 17:45:43 From file:test.f
With this, the module symbol file can be used in 64-bit mode as well:
$ xlf95 main.f -c -q64 ** _main === End of Compilation 1 === 1501-510 Compilation successful for file main.f.
If your module symbol file is not in the current directory, you can use the
$ ls main.f mydir test.f $ xlf95 test.f -c -qmoddir=mydir ** m === End of Compilation 1 === 1501-510 Compilation successful for file test.f. $ ls main.f mydir test.f test.o $ ls mydir m.mod $ xlf95 main.f -c -Imydir ** _main === End of Compilation 1 === 1501-510 Compilation successful for file main.f.
The module symbol file is only used in the compilation step. It doesn't have to be available during linking. For our example above, only test.o and main.o are needed for linking.
When writing dependency lists in Makefiles, it's usually a good idea to include the module symbol file as a dependency for files that contain USE statements for that module. For example, if you have a constants module containing parameters but no module procedures, XLF will sometimes only generate a constant.mod but not an object file. Adding constants.mod to the dependency list of the file containing USE constants solves this.
You can use old module symbol files with newer compilers. XLF 13.1 still supports the module symbol files created by XLF 3.1! However, the compiler will reject module symbol files that were created using newer compilers or on different platforms. For example, module files created by XLF 12.1 on AIX 5.3 can be used by XLF 13.1 on any AIX version. They can't be used by XLF 11.1 on AIX or by any XLF compiler on Linux. In those situations, you'll get the following message:
"main.f", line 1.5: 1514-220 (S) Module symbol file for module m is in a format not recognized by this compiler. Please compile the module with this compiler. 1501-511 Compilation failed for file main.f.