Performing Endian Conversion on ERDC Cray Systems

The storage in memory of multibyte variables, like longs, floats, reals, and integers, has different byte ordering depending on the system's architecture, which is identified by the endianness of the system. Little Endian byte ordering has the most significant byte ordered last, where Big Endian byte ordering has the most significant byte ordered first. The type of processor used in a system generally indicates the endianness of the system.

Cray Compiler Environment (CCE)

The CCE compiler has a "-h byteswapio" flag to swap the byte ordering. This compiler is only available on Cray Inc. architectures. Note: all routines compiled with this option will process all binary files, input or output, as big-endian.

Cray CCE also provides access to the FFIO Assign library, which includes the assign command. This command associates options with Fortran unit numbers and file names for use during the library open processing.

For example, in a file in the job execution directory or a project directory, place the endian-ness of the file(s) to be read and the corresponding unit number (s). The file is named assign_file, and two big-endian files are read in at units 1 and 30.

cat > assign_file << EOF
assign -N swap_endian u:1
assign -N swap_endian u:30
EOF

Then, prior to issuing the aprun command in the job script, define the $FILENV environment variable to point to that file, here named assign_file as immediately above:

export FILENV=/path/to/file/assign_file

Read the man page on the assign command for a detailed explanation of its use.

Intel Compiler

The Intel compiler has a "-convert big_endian" flag to read and write big-endian files. To use the Intel compiler on the Cray X Series systems, you need to swap your programming environment from CCE (which is the default) to Intel. For example:

module swap PrgEnv-cray PrgEnv-intel
% ifort -convert big_endian convert_data.f90

GNU Compiler Collection (GNU)

The GNU Fortran compiler has a "-fconvert=swap" flag to swap the byte ordering. Note: all routines compiled with this option will process binary files with opposite byte ordering. To use the GNU compiler on the Cray X Series systems, you need to swap your programming environment from CCE (which is the default) to GNU. For example:

module swap PrgEnv-cray PrgEnv-gnu
% ftn -fconvert=swap convert_data.f90