- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
INTEGER(1),DIMENSION(10000):: A INTEGER(2),DIMENSION(10000):: B INTEGER(4),DIMENSION(10000):: C INTEGER(8),DIMENSION(10000):: D LOGICAL(1),DIMENSION(10000):: CHK1 LOGICAL(2),DIMENSION(10000):: CHK2 LOGICAL(4),DIMENSION(10000):: CHK3
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?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
![](/skins/images/C4F7392A5C68ACA60290C9576F107044/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page