- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I want to know if there exist a compiler option which automatically initialize every array with zeros rather than garbage values.
I know i can do this while running the program by using:
a(:,:,:)=0
but for some reason it takes a lot of time.
Thanks.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
!dir$ vector nontemporal
should speed up initialization of arrays which are larger than cache. Evidently, you will want to check for vectorization.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What about initialising an array of user-defined types? Do all elements of a type get initialised according to their basic type (REAL*8, INTEGER*4, CHARACTER, etc.)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When making array references, use:
A = 0.
rather than:
A(:,:,:) = 0.
For reasons I don't quite understand, the compiler sometimes isn't able to tell that these are the same and you can get extra code for the second case. This is being looked at.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
TYPE T_MyTypeThey can also be initialized using UDT and array constructors, like:
INTEGER:: i = 0
REAL:: r = 0.
CHARACTER(5):: s=""
REAL:: f = 3.16
END TYPE T_MyType
TYPE(T_MyType):: MT(100) = &
(/ (T_MyType(0,0.,"",3.16), k=1,100) /)
There are subtle differences: the expression below is executed only once, while default initialization takes place whenever an object of given type is created, which includes allocation and dummy arguments with INTENT(OUT) attribute.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I didn't state my question clearly. I need to know if there is a compiler option which sets all the arrays to zero so that i dont need to write statements like :
a=0 or a(:)=0
in the code. It will save my time and space in coding.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In Windows, you can usean API to do the job very efficiently:
CALL ZeroMemory (LOC(your_item), SIZEOF(your_item))
This is immediately useful with UDTs as well.
A (personal, and wholly unsolicited) comment on the OP's desire to "save time and space in coding": it is IMHO very badpractice to write code with hidden, implicitdependenceon other entities beyond the scope of the code itself (ie, default behavior of a particular compiler). The converse, having explicit and obvious in-codeinitializations of arrays and UTDs, is good practice, portable, and easy to understand and debug.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page