View previous topic :: View next topic |
Author |
Message |
mecej4
Joined: 31 Oct 2006 Posts: 1888
|
Posted: Fri Aug 04, 2017 9:24 pm Post subject: |
|
|
Fortran provides other facilities to do what you used FORALL for; among them are array expressions, array constructors and and array assignments. Your entire code could be rewritten as
Code: |
PROGRAM example
IMPLICIT NONE
INTEGER :: irows, nrows = 5
INTEGER, ALLOCATABLE :: array(:)
ALLOCATE(array(nrows))
array=2*[(irows, irows = 1,nrows)]
PRINT*, array
DEALLOCATE(array)
END PROGRAM
|
The expression within brackets is an array constructor based on an implied DO loop, and that expression is an array expression even after the multiplication by 2. The statement on that line is an array assignment. |
|
Back to top |
|
|
viroxa
Joined: 28 Jul 2017 Posts: 78
|
Posted: Fri Aug 04, 2017 10:18 pm Post subject: |
|
|
Good to know, thanks! And how could one handle more complex functions? |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1888
|
Posted: Fri Aug 04, 2017 11:45 pm Post subject: |
|
|
That would depend on the nature of the function, so it is not easy to give a universal prescription.
You could program your complicated function using simple code at first, get it to produce correct results, and then look into making the code faster by vectorization, parallelization and other methods. |
|
Back to top |
|
|
viroxa
Joined: 28 Jul 2017 Posts: 78
|
Posted: Sat Aug 05, 2017 12:14 pm Post subject: |
|
|
OK, thanks! |
|
Back to top |
|
|
|