|
 
|
|
Data Files and the Big Endian / Little Endian Issue
by Frank Mathew
Big Endian and little Endian are terms used to describe the two different orders in which a sequence of bytes within a multi-byte number are stored within a computer depending on the under lying architecture. Systems with the RISC architecture and others like IBM, SUN, SGI and Motorola machines use the Big Endian format. While Intel platforms and DEC Alpha platforms and some of the programs that run on them use the Little Endian format. “Big Endian” format means that the means that the high-order byte of the number is stored in memory at the lowest address, and the low-order byte at the highest address while the Little Endian format means that the low-order byte of the number is stored in memory at the lowest address, and the high-order byte at the highest address.
As long as a program is manipulating an input file that was created on the same system that the program was built and is running on, you don’t have to deal with this issue. But if the program is running on a system that follows the Little Endian storage format and if is dealing with data that was stored using the Big Endian format or vice versa then there will be a problem with the with the way the program interprets the data. To overcome this problem, while compiling the program it is possible to specify how the data files should be read and written to.
Consider a program running on a system that has the Little Endian storage format and dealing with a numeric data file that was created on a system with Big Endian storage format.
On Redwood (with the intel compiler):
Option 1: While compiling the program set the environment variable “UFMTENDIAN” to “big”.
For example: “export F_UFMTENDIAN=big”
Option 2: While compiling use the “convert” option of the compiler and set it to “big_endian”
For example: ifort –convert big_endian program_file_name/s
On Mimosa (With the Portland Group compiler):
Mimosa is again a Little Endian system, so if your program has to deal with unformatted data files from a big Endian system, specify the “-byteswapio” option to the compiler.
For example: pgf90 –byteswapio program_file_name/s
|