Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28456 Discussions

Warning on derived type definition

hillyuan
Beginner
310 Views
I have encounter following warning:
-------------------------------------------
Warning: The structure contains one or misaligned fields.
TYPE :: C
------------------------------------------
when compiling following simple program

*******************************************
PROGRAM test

TYPE :: C
SEQUENCE
INTEGER :: A
DOUBLE PRECISION :: B(5)
END TYPE C

END PROGRAM
*******************************************

It looks strange for me for such error. Could anyone tell me why and if it is dangerous?
0 Kudos
4 Replies
durisinm
Novice
310 Views
I believe that the message is warning about the misalignment of the fields in your C structure on the appropriate boundaries. You should be able to fix this by ordering the variables within the structure by size. In your case, switch the declaration order of variables B and A. B is DOUBLE PRECISION, so each array element takes up eight bytes. A is most likely an INTEGER*4 and takes up only four bytes. Always list CHARACTER variables last. This goes for COMMON blocks as well as TYPEs.

There is a Fortran project setting that allows you to change the alignment boundary from one to four to eight bytes, and I think that the default is one.

Is misalignment dangerous? I'm not sure what the effects of misalignment are, but I believe in always keeping the compiler happy to avoid trouble.

Mike
0 Kudos
Steven_L_Intel1
Employee
310 Views
Dangerous? No. But it can degrade performance. This topic is discussed in the Performance chapter of the Visual Fortran Programmer's Guide.

Steve
0 Kudos
Jugoslav_Dujic
Valued Contributor II
310 Views
There is a Fortran project setting that allows you to change the alignment boundary from one to four to eight bytes, and I think that the default is one.

The default is "natural", which IIRC means eight on the PC. However, for SEQUENCEd types that seems to be one:


The default value (unless /fast is specified) is /align:nosequence, which means that components of derived types with the SEQUENCE property will be packed, regardless of whatever alignment rules are currently in use. Specifying /fast sets /align:sequence.
In the visual development environment, specify Allow SEQUENCE Types to be Padded for Alignment in the Fortran Data Compiler Option Category.



Is misalignment dangerous? I'm not sure what the effects of misalignment are,

Primarily, the performance penalty. When encountering misaligned data, the compiler (or processor?) must produce code to align it, do something with it, and "unalign" it back if necessary. Also, one must take care about it when doing mixed-language programming -- the general rule of thumb, as Mike said, is to always declare members in order of decreasing size.

but I believe in always keeping the compiler happy to avoid trouble.

Amen to that.

Jugoslav
0 Kudos
hillyuan
Beginner
310 Views
Thanks a lot.
The performance chapter of Visual Fortran Programmer's Guide gives a detailed description of this problem. I think I have understood it now.

Hill
0 Kudos
Reply