I just tried Windows Subsystem for Linux (WSL) to run Fortran programs. Here are my impressions, which are positive.
You can install WSL on Windows 10, which gives you a bash terminal. Then you can install gfortran 4.8.4 using sudo apt-get install gfortran . There are more recent versions of gfortran that I will look into installing on WSL. One of my programs compiled with GNU Fortran (GCC) 8.0.0 20170430 from
equation.com freezes on Windows for certain inputs. That program, with the same inputs, runs fine with gfortran on WSL. Great! With other inputs, the program on Windows takes 31 s with gfortran and 24 s with Intel Fortran, but it only takes 17 s with gfortran on WSL (all programs compiled with -O2).
I am pleased that on WSL, my program compiled by gfortran run faster and more robustly. On WSL, you can see the Windows file system. What is c:\fortran on Windows is /mnt/c/fortran on WSL. You do not need to make separate copies of source code for Windows and WSL. If you have data files in c:\data, your WSL program needs to translate that into /mnt/c/data . Using the get_command_argument of Fortran 2003, you could determine at run-time whether Windows or WSL is being used (is the executable a.exe or a.out?) and translate Windows directories to WSL when needed. For now I am storing data files in the same directory as the code.
WSL does not run Linux GUI programs by default, and I find editing source code on it inconvenient. But it looks like a good way to run console-based Fortran programs.
For the program below
http://www.60bits.net/msu/mycomp/bench.htm the time taken is 3.7 s on gfortran/Windows and 3.8 s on gfortran/WSL . Even if gfortran/WSL is not faster than gfortran/Windows, there may not be an appreciable speed penalty.
PROGRAM RANPI
c Program to compute PI by probability.
c By Mark Riordan 24-DEC-1986;
c Original version apparently by Don Shull.
c To be used as a CPU benchmark.
write(*,*) 'Starting PI...'
ztot = 0.0
low = 1
ixran = 1907
yran = 5813.0
ymult = 1307.0
ymod = 5471.0
itot = 120000000 ! scaled up 100 from original program
DO 100 j=1,itot
c X and Y are two uniform random numbers between 0 and 1.
c They are computed using two linear congruential generators.
c A mix of integer and real arithmetic is used to simulate a
c real program. Magnitudes are kept small to prevent 32-bit
c integer overflow and to allow full precision even with a 23-bit
c mantissa.
iprod = 27611 * ixran
ixran = iprod - 74383*(iprod/74383)
x = float(ixran) / 74383.0
prod = ymult * yran
yran = (prod - ymod*int(prod/ymod))
y = yran / ymod
Z = X*x + Y*y
call myadd(ztot,z)
IF ( Z .LE. 1.0 ) THEN
low = low + 1
ENDIF
100 continue
write(*,9000) x,y,low,j
9000 format(' x=',f8.5,' y=',f8.5,' low=',i7,' j=',i7)
Pi = 4.0 * float(low)/float(Itot)
write(*,*) 'Pi = ',pi,' ztot = ',ztot,' itot = ',itot
STOP
END
subroutine myadd(sum,addend)
c Simple adding subroutine thrown in to allow subroutine
c calls/returns to be factored in as part of the benchmark.
sum = sum + addend
return
end