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

Preferred Fortan

JohnNichols
Valued Contributor III
603 Views
h(1:3) = TriShell%h(1:3)
    em = TriShell%em

h and em are both arrays, which method of assignment is Fortran preferred now?  

0 Kudos
9 Replies
Steve_Lionel
Honored Contributor III
579 Views

Simpler is better. The first version makes the compiler work harder to optimize the assignment. It is also much clearer to the human reading the code.  I touched on this in Doctor, it hurts when I do this! - Doctor Fortran (stevelionel.com)

0 Kudos
jimdempseyatthecove
Honored Contributor III
579 Views

The newer Fortran standards default to realloc_lhs = .true.

When the destination array is allocatable, for example your em on lhs,

this may result in em being deallocated (if allocated) then allocated to the size of TriShell%em

This may (used to) occur even though em is the same size as TriShell%em.

Intel may have fixed this (tested for same size and bounds then avoid reallocation) with the newer ifort and/or ifx.

You can use:

   em(:) = TriShell%em

or

   em(:) = TriShell%em(:)

or

  use the explicit bounds for each array

 

This will assure no reallocation of lhs (should em be allocatable).

But expect error should em not be allocated .OR. size not the same.

 

Jim Dempsey

 

 

 

0 Kudos
JohnNichols
Valued Contributor III
552 Views

Steve:  

https://www-cs-faculty.stanford.edu/~knuth/address.html 

was more fun to read, you should definitely rewrite BIM or SIM or whatever.

If you know any of these people let them know.  

Jim:

It is English right?  LOL

use the explicit bounds for each array === I will. 

 

 

 

0 Kudos
Steve_Lionel
Honored Contributor III
548 Views

@JohnNichols wrote:

Steve:  

https://www-cs-faculty.stanford.edu/~knuth/address.html 

was more fun to read, you should definitely rewrite BIM or SIM or whatever.


 I wrote an extended MIX interpreter (I called it XIM, in IBM 360 assembler) in college (mid-70s), supporting floating point and all of the extensions he had proposed. Wrote a letter to Knuth about it, he wrote back with encouragement. I had also asked when volume 4 of TAOCP was coming out, he basically said "don't hold your breath".  I do now have the set that includes "volume 4A". Brings back memories, it does.

0 Kudos
AlHill
Super User
545 Views

@Steve_Lionel Wasn't MIX replaced by MMIX (a RISC machine)?

 

Also, in a letter I received in February 1990 from Knuth regarding volume 4 being published, he said "soon".

 

Doc (not an Intel employee or contractor)
[Maybe Windows 12 will be better]

0 Kudos
Steve_Lionel
Honored Contributor III
543 Views

@AlHill yes, much, much later.

0 Kudos
JohnNichols
Valued Contributor III
519 Views
0 Kudos
AlHill
Super User
505 Views

Yes.

 

Doc (not an Intel employee or contractor)
[Maybe Windows 12 will be better]

0 Kudos
Steve_Lionel
Honored Contributor III
512 Views

No - that was 45 years ago!

0 Kudos
Reply