- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
-------------------------------------------
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?
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dangerous? No. But it can degrade performance. This topic is discussed in the Performance chapter of the Visual Fortran Programmer's Guide.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
The performance chapter of Visual Fortran Programmer's Guide gives a detailed description of this problem. I think I have understood it now.
Hill
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page