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

LOGICAL size choice

ereisch
New Contributor II
668 Views

Is there an optimal size choice for local variables of LOGICAL data types for efficiency on x86 or x86_64 platforms?  I understand the desire to pad alignment of structures or arrays of structures for efficiency, but do non-array stack variables access any quicker for 1-byte vs. 4-byte accesses?  Same question for INTEGER*1 or INTEGER*2 vs. INTEGER*4 -- is there any reason to not compress the variable size to the smallest needed to store the expected data?

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
663 Views

The instructions for manipulating LOGICALs work better when the data is 32-bit aligned. Unless you have hundreds of thousands of these, the default size is the better choice.

View solution in original post

0 Kudos
2 Replies
Steve_Lionel
Honored Contributor III
664 Views

The instructions for manipulating LOGICALs work better when the data is 32-bit aligned. Unless you have hundreds of thousands of these, the default size is the better choice.

0 Kudos
jimdempseyatthecove
Honored Contributor III
643 Views

I agree with Steve with one (rare exception). This is for the special case where your highly exercized procedure (subroutine or function) is on the edge of fitting everything in L1 cache .AND. where you have the opportunity to reclaim some cache lines by packing your logicals and smaller integers. I would suggest you not use the smaller sizes until after you reach the VTune phase and notice/determine a potential for gain.

For hundreds of thousands of logicals, you might consider bit fields. YMMV

Jim Dempsey

0 Kudos
Reply