Docsity

Fortran 90 Lab: Run-time Memory Allocation and Array Processing - Prof. Charles Pruett, Lab Reports of Mathematics

Toggle sidebar
bg1
Math 248 LABORATORY ASSIGNMENT
Run-time Memory Allocation
and
Array Processing in Fortran 90
(Pruett)
•C) Enter and compile the FORTRAN 90 program on the reverse
side. (You need not copy all the comments.) Run the program for
n= 4, n= 32, and n= 500. Answer the following questions:
•C) What advantage to you the user does run-time memory alloca-
tion have over compile-time allocation?
•C) What does a “broadcasting” array assignment do?
•B) Modify your program to include 3 run-time allocatable 1D
arrays: A,B, and C, each assumed to be of the same (as yet unde-
termined) size. Initialize array Aas before. Initialize array Bwith
the broadcast assignment B= 3.0. Add the FORTRAN statement
C=A+Bjust before the WRITE loop. Compile, run for several val-
ues of n, and describe the effect of the statement immediately above.
•B) Change the FORTRAN statement
C=A+B
to
C=A∗B
Describe the outcome of this modification. Is this operation the same
as a dot product?
•A) Modify your program to read two dimensions mand n. Allocate
memory such that arrays Aand Care of size mand Bis of size n.
Compile the program and run it 3 times: a) for m=n, b) for m < n,
and for c) for m>n. Describe your results.
•A+) Add an allocation status check to your allocation procedures.
pf2

Partial preview of the text

Download Fortran 90 Lab: Run-time Memory Allocation and Array Processing - Prof. Charles Pruett and more Lab Reports Mathematics in PDF only on Docsity!

Math 248 LABORATORY ASSIGNMENT Run-time Memory Allocation and Array Processing in Fortran 90 (Pruett)

  • C) Enter and compile the FORTRAN 90 program on the reverse side. (You need not copy all the comments.) Run the program for n = 4, n = 32, and n = 500. Answer the following questions:
  • C) What advantage to you the user does run-time memory alloca- tion have over compile-time allocation?
  • C) What does a “broadcasting” array assignment do?
  • B) Modify your program to include 3 run-time allocatable 1D arrays: A, B, and C, each assumed to be of the same (as yet unde- termined) size. Initialize array A as before. Initialize array B with the broadcast assignment B = 3.0. Add the FORTRAN statement C = A + B just before the WRITE loop. Compile, run for several val- ues of n, and describe the effect of the statement immediately above.
  • B) Change the FORTRAN statement

C = A + B

to C = A ∗ B Describe the outcome of this modification. Is this operation the same as a dot product?

  • A) Modify your program to read two dimensions m and n. Allocate memory such that arrays A and C are of size m and B is of size n. Compile the program and run it 3 times: a) for m = n, b) for m < n, and for c) for m > n. Describe your results.
  • A+) Add an allocation status check to your allocation procedures.

PROGRAM arrays_1d ! !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! ! Trivial program to demonstrate 1) run-time memory ! allocation, and 2) "broadcasting" initialization of ! 1D arrays (vectors) ! ! AUTHOR: Dr. D. Pruett, JMU Math ! CREDITS: None ! !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! IMPLICIT NONE INTEGER :: i,n ! ! Vector is declared to be a 1D array, but its dimension ! is left ambiguous at compile time ! REAL, DIMENSION(:), ALLOCATABLE :: Vector

WRITE (,) ’ Enter array length, n ’ READ (,) n ! ! allocate memory for array Vector ! ALLOCATE (Vector(1:n))! size of Vector is established at run time ! ! initialize array Vector ! Vector = 2.1! by "broadcasting" ! ! output array Vector by index ! DO i = 1,n WRITE (,) i, Vector(i) END DO ! ! return allocated memory to the memory pool ! DEALLOCATE (Vector)! be a good citizen; "thanks for the memories"

STOP

END PROGRAM arrays_1d