[CSC 335] Fortran Example
Andrew J. Pounds
pounds_aj at mercer.edu
Tue Nov 14 10:36:12 EST 2023
To compile the fortran you need to use the following on cobra
gfortran ztest.f -llapack -lblas
On 11/14/23 10:14, Andrew J. Pounds wrote:
>
> And here is a way to solve problem 2 on the homework using Fortran and
> the LAPACK library.
>
> program ztest
>
> parameter (N=10)
>
> double complex A(N,N), B(N,N), C(N,N)
>
> double precision pi
> integer ipiv(N), info
> double complex work(64*N), sum
> double complex alpha, beta
> double precision gamma
>
> alpha = dcmplx(1.0D0,0.0D0)
> beta = dcmplx(0.0D0,0.0D0)
>
> pi = dacos(-1.0D0)
>
> do 10 i = 1, N
> do 20 j = 1, N
> gamma = dsqrt(dcos(dble(i**2*j)*pi/dble(N**3))**2+
> + dsin(2.0D0*dble(i**2*j)*pi/dble(N**3))**2)
> A(j,i) = dcmplx(
> + dcos(dble(i**2*j)*pi/dble(N**3))/gamma,
> + dsin(2.0D0*dble(i**2*j)*pi/dble(N**3))/gamma)
> B(j,i) = A(j,i)
> 20 continue
> 10 continue
>
> call ZGETRF( N, N, B, N, IPIV, INFO )
> call ZGETRI( N, B, N, IPIV, WORK, -1, INFO )
> LWORK = int(dble(work(1)))
> call ZGETRI( N, B, N, IPIV, WORK, LWORK, INFO )
>
> call ZGEMM ( 'N', 'N', N, N, N, alpha, A, N,
> + B, N, beta, C, N)
>
> sum = dcmplx(0.0D0,0.0D0)
> do 30 i = 1, N
> sum = sum + c(i,i)
> 30 continue
>
> print *, sum
>
>
> end
>
>
>
> --
> *Andrew J. Pounds, Ph.D.*
> /Professor of Chemistry and Computer Science/
> /Director of the Computational Science Program/
> /Mercer University, Macon, GA, 31207 (478) 301-5627 /
--
*Andrew J. Pounds, Ph.D.*
/Professor of Chemistry and Computer Science/
/Director of the Computational Science Program/
/Mercer University, Macon, GA, 31207 (478) 301-5627 /
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://theochem.mercer.edu/pipermail/csc335/attachments/20231114/03a2cfbe/attachment.html>
More information about the csc335
mailing list