Showing results for 
Search instead for 
Did you mean: 

Non-Default Data Type Benifit

With regards to the Intel Compiler (or if the code is used by another compiler), is there any benifit to using non-default data types beyond different memory storage?

For example default Logical (KIND=4) uses 32 bits of memory, but a Logical (KIND=1) only uses 8 bits of memory. To me it would seem better to always declare the logical variable as being LOGICAL(KIND=1) since it is just holding a TRUE/FALSE value.

Is there any penalty when doing this (such as the compiler is more optimized for processing 32 bits compared to 8 bits).


Another example is if I know I am only going to have an integer variable that is set to only -1, 0, and 1, would it be better to declare it as INTEGER(1) compared to INTEGER (which would default the kind to 4)? 

I have a simulation model that has very large LOGICAL and INTEGER arrays that are used mostly as flags (hence the -1, 0, and 1 example) and while it would be nice to reduce the memory foot print, the execution speed is my main concern.


Would there be a speed difference between any of the following, say I had to process it in a lot with setting its value to -1, 0, or 1 and the checking those values later and changing them again?



I guess ultimately, with enough RAM, is there any benefit for declaring the smaller "kind" versions even though the full range of the default kind types are never used?

0 Kudos
1 Reply
Valued Contributor II

If I understand it correctly,

If I understand it correctly, using default-size data types is faster due to alignment issues. But if you have very large logical arrays, you might consider using bit arrays - not something that is supported by Fortran per se, but easily emulated:

Make a derived type, containing a large integer array with a few procedures to get and set individual bits in the elements of the array. The derived type is not essential, but it allows you to hide many details. For getting and setting these bits ,you can use the standard bit manipulation routines, IBSET, etc. As long as you look at separate bits and not require counts or the like, that should be fast enough.

0 Kudos