๐ป Fortran Source Code Library
We currently offer 172 open-source, production-grade Fortran codes for offline testing. Run calculations locally on your own machine, view code structure, read technical explanations, and download compilation packages including sample input files.
Gustafson's Law (Parallel Scaling)
Core Numerical Engine in Fortran 90 โข 31 total downloads
gustafson.f90
! =========================================================================
! Source File: gustafson.f90
! =========================================================================
!==============================================================================
! ThermoFluidCalc โ Calculator #31 : Gustafson's Law
!==============================================================================
! S(N) = 1 + f*(N-1) (scaled speedup / weak scaling)
! Alternatively: S = s + f*N where s = 1-f
! Comparison with Amdahl: S_amdahl = 1/((1-f)+f/N)
! Reference : Gupta, ยง5.8, Eq. 5.95
! Build: gfortran -O2 -o gustafson gustafson.f90
!==============================================================================
program gustafson
implicit none
integer, parameter :: dp = selected_real_kind(15,307)
integer, parameter :: MX = 10000
integer :: mode, N, Nmin, Nmax, npts, i
real(dp) :: f, Sg, Sa, Eg, Ea, df, fv, dN
read(*,*) mode
select case(mode)
! MODE 1 : Single point โ both laws
case(1)
backspace(5); read(*,*) mode, f, N
if(f<0) f=0; if(f>1) f=1; if(N<1) N=1
Sg = 1.0_dp + f*real(N-1,dp)
Eg = Sg / real(N,dp)
Sa = 1.0_dp / ((1.0_dp-f) + f/real(N,dp))
Ea = Sa / real(N,dp)
write(*,'(A,I1)') 'MODE=', mode
write(*,'(A)') 'MODE_NAME=Single Point'
write(*,'(A,F10.6)') 'F=', f
write(*,'(A,I8)') 'N=', N
write(*,'(A,F12.4)') 'S_GUSTAFSON=', Sg
write(*,'(A,F10.4)') 'E_GUSTAFSON=', Eg
write(*,'(A,F12.4)') 'S_AMDAHL=', Sa
write(*,'(A,F10.4)') 'E_AMDAHL=', Ea
! MODE 2 : N sweep โ both laws
case(2)
backspace(5); read(*,*) mode, f, Nmin, Nmax, npts
if(f<0) f=0; if(f>1) f=1
if(Nmin<1) Nmin=1; if(Nmax<Nmin) Nmax=Nmin
if(npts<2) npts=2; if(npts>MX) npts=MX
write(*,'(A,I1)') 'MODE=', mode
write(*,'(A)') 'MODE_NAME=N Sweep'
write(*,'(A,F10.6)') 'F=', f
dN = real(Nmax-Nmin,dp)/real(npts-1,dp)
write(*,'(A)') 'DATA_START'
do i = 0, npts-1
N = Nmin + nint(real(i,dp)*dN)
if(N<1) N=1
Sg = 1.0_dp + f*real(N-1,dp)
Sa = 1.0_dp / ((1.0_dp-f) + f/real(N,dp))
Eg = Sg / real(N,dp)
write(*,'(I8,A,F12.4,A,F12.4,A,F10.6)') N, ',', Sg, ',', Sa, ',', Eg
end do
write(*,'(A)') 'DATA_END'
! MODE 3 : f sweep โ both laws for fixed N
case(3)
backspace(5); read(*,*) mode, N, npts
if(N<1) N=1; if(npts<2) npts=2; if(npts>MX) npts=MX
write(*,'(A,I1)') 'MODE=', mode
write(*,'(A)') 'MODE_NAME=f Sweep'
write(*,'(A,I8)') 'N=', N
df = 1.0_dp/real(npts-1,dp)
write(*,'(A)') 'DATA_START'
do i = 0, npts-1
fv = real(i,dp)*df
Sg = 1.0_dp + fv*real(N-1,dp)
Sa = 1.0_dp / ((1.0_dp-fv) + fv/real(N,dp))
write(*,'(F10.6,A,F12.4,A,F12.4)') fv, ',', Sg, ',', Sa
end do
write(*,'(A)') 'DATA_END'
case default
write(*,'(A)') 'ERROR=Invalid mode (1-3).'; stop
end select
end program gustafson
Solver Description
Calculate scaled speedup for parallel applications where workload size grows with processing power.
Key Numerical Methods & Architecture
- Input Redirection: Reads parameters sequentially from standard input (`stdin`) using Fortran sequential read (`read(*,*)`), ensuring modular integration.
- Modular Design: Formulated using pure mathematical routines, separation of equations from output formatting, and precise numerical solvers (e.g. bisection, Newton-Raphson).
- Standard Compliant: Written in clean, standards-compliant Fortran 90 to ensure cross-compiler compatibility.
๐ ๏ธ Local Compilation
To test this code on your machine, compile the source code file(s) using a standard Fortran compiler (e.g., `gfortran`).
Compilation Command:
gfortran -O3 gustafson.f90 -o gustafson
Execution Command:
Execute the program by feeding the sample input file into the program using stdin redirection:
gustafson < input.txt
๐ฅ Downloads & Local Files
Preview of the required input file (input.txt):
! f_in\nN (processors)
0.9
! Parameter 2
8
0.9
! Parameter 2
8