Godric Seer
Godric Seer

Reputation: 379

Intel Fortran Compiler with large file size

I have a large piece of legacy code that is written in Fortran 77. I am compiling it and running it with the Intel Fortran Compiler (Version 11?). I recently ran into an issue where the output file reached just shy of 2GB in size, and the output stopped getting written to disk.

I have hunted around looking to see if this is part of the Fortran 77 standard, or if I am simply missing a compiler flag or something, but haven't found anything that points towards my problem.

Changing the write statements isn't an option, since the legacy code is on the order of several hundred thousand lines. Worst case scenario is that every few days I go in and truncate the earlier portions of the output to a different file, but I would prefer that I not have to do this.

Upvotes: 0

Views: 4002

Answers (1)

Hristo Iliev
Hristo Iliev

Reputation: 74485

The most probable reason for this kind of behaviour is the memory model in use. In 64-bit mode there are three memory models, distinguished by the addressing mode used:

  • small model - RIP-related addressing is used for everything, from calling functions to accessing data. RIP is the 64-bit instruction pointer register of x64 (the 64-bit extension of EIP), but the relative address can only be a signed 32-bit number (and there are some restrictions that prevent the use of the full signed integer range), hence the combined code + static data size is limited to about 2 GiB.
  • medium model - program code is limited to 2 GiB, hence RIP-related function calls, but data symbols are split in two types. Small data symbols are those that fit together with the code in the first 2 GiB and they are addressed using the same RIP-relative method as in the small model. Large data symbols are accessed using register addressing with the absolute address of the symbol loaded into a register, which is slower but there are no limits on the addressable memory.
  • large model - all symbols are accessed using absolute addressing. There are no restrictions on the code or data size.

Most compilers that can target x64, ifort included, accept the --mcmodel=model option that allows one to control the memory model used. The default model is small. The size of your object file means that there is an enormous quantity of initialised static data, possibly some very large initialised arrays (think DATA or BLOCK DATA statements) or many smaller arrays (I doubt that even 1 million code statements would generate 2 GiB of instructions code). Compiling with --mcmodel=medium or --mcmodel=large should solve the problem with the large object file size.

Note that linking together object codes that use different memory models is a recipe for disaster - the whole application should be compiled with the same memory model.

Upvotes: 3

Related Questions