This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Type Alignment
- From: Jeff Squyres <jsquyres at open-mpi dot org>
- To: Richard E Maine <Richard dot Maine at nasa dot gov>
- Cc: Janne Blomqvist <jblomqvi at cc dot hut dot fi>, fortran at gcc dot gnu dot org, Craig Rasmussen <crasmussen at lanl dot gov>, "Christopher D. Rickett" <crickett at lanl dot gov>
- Date: Tue, 21 Feb 2006 17:32:01 -0500
- Subject: Re: Type Alignment
- References: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 <20060221211223.GQ1854@vipunen.hut.fi> <7944c9e1a0b447bb612cc365f2c6d7b1@nasa.gov>
To clarify, we are perfectly happy to use sequenced derived
datatypes. Our goal is only to find out what the alignment of a
given type is. Over time, we independently grew 2 different tests
for type alignment (the F77 and F90 tests that Craig sent), and only
recently [accidentally] noticed that they were returning different
answers.
Here's what we need:
1. What is a reliable / correct test to determine the alignment of a
Fortran type? (I don't care a whit about the previous tests -- if
they're wrong, we'll throw them out)
2. Will this alignment be the same between compatible Fortran 77 and
Fortran 90 compilers? (e.g., compilers of the same vendor/version,
or, in a trivial case, using the same "gfortran" to compile f77 and
f90 compilation units)
3. Am I reading these replies correctly that the *alignment* of a
type may change depending on whether a derived type is sequenced or
not? I can understand how members might be re-ordered in memory by
the compiler (and that's not a problem for us), but can it really
change the datatype's alignment? If so, this could be a Big Problem
for us.
Thanks for your time.
On Feb 21, 2006, at 5:19 PM, Richard E Maine wrote:
On Feb 21, 2006, at 1:12 PM, Janne Blomqvist wrote:
There is no rule stating that aligment must be the same for common
and
derived types, so perhaps both your tests are correct. Common is
limited in the sense that storage association is required to work,
but
for a derived type the compiler is free to align in whatever way it
thinks provides the best performance. Unless you make the derived
type
a sequence type, in which case the derived type should also obey the
rules of storage association.
For nonsequence derived types, it is worse than that. Not only can
the compiler align things in any way, it can even re-order them. It
is *VERY* plausible that a compiler might do something like re-
order to put the things with the largest alignment requirements
first, thus minimizing padding requirements. I think I might have
seen compilers that did such reordering, though I wouldn't swear to
it.
--
Richard Maine | Good judgment comes from experience;
Richard.Maine@nasa.gov | experience comes from bad judgment.
| -- Mark Twain
--
{+} Jeff Squyres
{+} The Open MPI Project
{+} http://www.open-mpi.org/