Warning on derived type definition

Warning on derived type definition

I have encounter following warning:
-------------------------------------------
Warning: The structure contains one or misaligned fields. [C]
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?

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

Dangerous? No. But it can degrade performance. This topic is discussed in the Performance chapter of the Visual Fortran Programmer's Guide.

Steve

Steve - Intel Developer Support

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

Jugoslav
www.xeffort.com

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today