Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Natural Alignment of Data

gelarimer
Beginner
561 Views
I have noticedin some example codes that integer*4 isused for variables that will always be small, such as do loop counters that will always be less than200 or parameters with values of single digits. Very rarely have I seen (or maybe I haven't been looking close enough) declarations of variables with mixed KIND. I thought this may have something to do with naturally aligning data in memory, but after reading theIVF on line user manual's sectionon aligning data Iam not sure.
Also, a related question: Is it possible to use the following as a Global variable when the rest of the Global variables (real and integer)are KIND = 4:
INTEGER(1), DIMENSION(999) :: giVariable
0 Kudos
3 Replies
Steven_L_Intel1
Employee
561 Views
INTEGER*4, or "default integer", is used most often because it is the most efficient integer type for the processor. The examples may use *4 out of habit (really should be (4) anyway) or to protect against the user modifying the default integer kind. It doesn't have much at all to do with alignment. Integer kinds of 2 or 1 require additional instructions to process and should be used sparingly.

You certainly CAN use such a declaration if it is appropriate for your application. It doesn't matter what you mix it with. The compiler will automatically chose allocation to naturally align local variables unless you override that with EQUIVALENCE or SEQUENCE.
0 Kudos
TimP
Honored Contributor III
561 Views
Although the *4 notation is not supported by standard Fortran, it will work on more compilers than the (4) notation. The standard actually requires use of selected_kind syntax to find out supported KINDs for a given compiler. There is no guarantee about KIND numbers being related to storage size.
As Steve says, integer(1) and integer*1 always work with ifort, with some efficiency tradeoffs, but in general, selected_int_kind(2) would be needed to find the smallest storage KIND which accepts -99 .le. n .le. 99.
0 Kudos
gelarimer
Beginner
561 Views
Thanks for the info and explanation.
0 Kudos
Reply