Part-1 | Step-by-Step Guide: Installing WRF on Windows Subsystem for Linux (WSL)
- Subhadip Datta
- Feb 9
- 7 min read
Updated: Feb 11
The Weather Research and Forecasting (WRF) Model is a sophisticated numerical weather prediction system designed for both atmospheric research and operational forecasting applications. Installing and running WRF in a Debian-based WSL (Windows Subsystem for Linux) environment requires careful attention to system requirements to ensure optimal performance.
✅ Advantages of Running WRF on WSL2
Linux Environment on Windows – WSL2 provides a full Linux kernel, making it possible to run WRF without needing a separate Linux machine.
Better Performance than WSL1 – WSL2 has a real Linux kernel with improved performance over WSL1, especially for applications that require extensive system calls.
Easier Setup – No need for dual booting or virtualization (like VirtualBox or VMware).
Supports Parallel Computing – With proper MPI configuration, you can run WRF in parallel mode on WSL2.
⚠️ Potential Issues & Limitations
Performance Constraints – WSL2 does not provide full native performance compared to running WRF on a dedicated Linux server or HPC cluster.
MPI & Parallel Processing Challenges – Some users report that MPICH and OpenMPI do not always work optimally due to networking limitations in WSL2.
Disk I/O Speed – File system operations in WSL2 can be slower compared to a native Linux environment, especially if you're running WRF on the Windows file system (/mnt/c/).
Graphics and Visualization – While GUI applications are now supported in WSL2, visualization tools like ncview or Matplotlib may require additional setup (X11 forwarding, VcXsrv, etc.).
Limited GPU Support – WRF does not natively utilize GPU, but if you're using CUDA for preprocessing or post-processing, WSL2 has experimental support for NVIDIA GPUs.
🚀 How to Optimize WRF in WSL2
Use Linux File System (/home/username/WRF_MODEL) instead of /mnt/c/ for better performance.
Allocate More Resources – Increase WSL2 memory, CPU, and swap settings in .wslconfig for better efficiency.
Fine-Tune MPI Configuration – If running WRF in parallel, test different MPI versions (MPICH/OpenMPI) for best compatibility.
Use External Storage for Large Datasets – To reduce disk I/O overhead.
System Requirements
1. Hardware Requirements:
Processor: A multi-core processor is recommended to handle the computational demands of WRF. For instance, an Intel i7 processor has been suggested as a suitable choice.
Memory (RAM): The amount of RAM required depends on the complexity of your simulations. For short-term simulations with modest domain sizes, a system with 8 GB of RAM may suffice. However, for more extensive simulations or higher resolutions, increasing the RAM to 16 GB or more is advisable.
Storage: Ensure adequate storage space for the WRF model code, input data, and output files. A minimum of 100 GB of free disk space is recommended, though this may vary based on your specific use case.
2. Software Requirements:
Operating System: A stable Debian-based Linux distribution running within WSL. Ensure your system is updated to the latest version to maintain compatibility with required libraries and tools.
Compilers:
Fortran Compiler: A Fortran 90/95 compiler is essential for building WRF. The GNU Fortran compiler (gfortran) is commonly used and compatible with WRF.
C Compiler: A standard C compiler like gcc is required for compiling various components of the WRF system.
Libraries:
netCDF: The Network Common Data Form (netCDF) library is crucial for WRF's I/O operations. Ensure both the C and Fortran interfaces of netCDF are installed.
MPI Library: For parallel processing capabilities, an MPI library such as MPICH or OpenMPI is necessary. This is important even if you plan to run WRF on a single node.
Additional Libraries: Depending on your specific requirements, other libraries like zlib, HDF5, and JasPer may be needed. These support various functionalities within WRF.
Scripting Languages:
Perl: Used in WRF's configuration and compilation scripts.
Python: While not mandatory, Python is often used for pre- and post-processing tasks in WRF workflows.
3. Additional Considerations:
Parallel Computing: WRF is designed to take advantage of parallel computing environments. Utilizing multiple processor cores can significantly reduce simulation times. Ensure that your system's hardware and software configurations support parallel execution.
System Updates: Regularly update your
Installation Guide under Windows Subsystem for Linux (WSL)
1. Install WSL
wsl --install -d Debian
Create a username and password for the Linux system.
Update the newly installed system:
sudo apt-get update
sudo apt-get upgrade
To install GUI apps, follow this tutorial: Microsoft WSL GUI Apps Guide
2. Setup Required Directories
In the user's home directory, create the following directories:
mkdir WRF_MODEL
mkdir TESTS
mkdir WRF_MODEL/LIBRARIES
mkdir WRF_MODEL/INPUT_DATA
Ensure system packages are updated:
sudo apt-get update
sudo apt-get install build-essential wget gfortran cpp gcc g++ csh perl libtool-bin -y
sudo apt-get upgrade
Check if packages are installed:
which build-essential wget gfortran cpp gcc g++ csh perl
Expected output:
/usr/bin/wget
/usr/bin/gfortran
/usr/bin/cpp
/usr/bin/gcc
/usr/bin/g++
/usr/bin/csh
/usr/bin/perl
Test the compilers: Compiler Test Guide
3. Install Other Dependencies
sudo apt-get update
sudo apt-get install libjson-c-dev valgrind -y
wget https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh
bash Anaconda3-2023.09-0-Linux-x86_64.sh
4. Install Required Libraries
Navigate to the libraries directory:
cd WRF_MODEL/LIBRARIES
Download necessary source files:
wget https://github.com/pmodels/mpich/releases/download/v3.4.3/mpich-3.4.3.tar.gz
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/zlib-1.2.11.tar.gz
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/libpng-1.2.50.tar.gz
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/jasper-1.900.1.tar.gz
wget https://docs.hdfgroup.org/archive/support/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.0/src/hdf5-1.12.0.tar.gz
wget https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.8.1.tar.gz -O netcdf-c-4.8.1.tar.gz
wget https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.5.4.tar.gz -O netcdf-fortran-4.5.4.tar.gz
5. Configure Environment Variables
Open the configuration file:
nano ~/.bashrc
Add these lines:
# WRF Configuration Setting
# Compilers
export CC=/usr/bin/gcc
export CXX=/usr/bin/g++
export FC=/usr/bin/gfortran
export FCFLAGS="-m64"
export F77=/usr/bin/gfortran
export FFLAGS="-m64"
# Directory
export DIR=/home/<username>/WRF_MODEL/LIBRARIES
export WRF_DIR=/home/<username>/WRF_MODEL//WRF
export MPICH=$DIR/mpich
export NETCDF=$DIR/netcdf
export JASPERLIB=$DIR/grib2/lib
export JASPERINC=$DIR/grib2/include
export PATH=$DIR/grib2/bin:$MPICH/bin:$NETCDF/bin:$PATH
# Libraries
export LD_LIBRARY_PATH=$DIR/grib2/lib:$LD_LIBRARY_PATH
export LDFLAGS="-L$DIR/grib2/lib"
export CPPFLAGS="-I$DIR/grib2/include"
Save and exit: Ctrl+O, Enter, Ctrl+X Apply changes:
source ~/.bashrc
6. Install Libraries (run section by section):
tar xzvf mpich-3.4.3.tar.gz
cd mpich-3.4.3
export FFLAGS=-fallow-argument-mismatch
./configure --prefix=$DIR/mpich --with-device=ch3:nemesis --enable-fast=all,O3 --disable-float --enable-threads=multiple
make check
make install
cd ..
tar xzvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=$DIR/grib2
make check
make install
cd ..
tar xzvf libpng-1.2.50.tar.gz
cd libpng-1.2.50
./configure --prefix=$DIR/grib2
make check
make install
cd ..
tar xzvf jasper-1.900.1.tar.gz
cd jasper-1.900.1
# Configuration and install
./configure --prefix=$DIR/grib2
make check
make install
cd ..
tar xzvf hdf5-1.12.0.tar.gz
cd hdf5-1.12.0
CC=mpicc FC=mpif90 F77=mpif77 CXX=mpicxx ./configure --prefix=$DIR/grib2 --with-zlib=$DIR/grib2 --enable-hl --enable-fortran --enable-parallel
make check
make install
cd ..
tar xzvf netcdf-c-4.8.1.tar.gz
cd netcdf-c-4.8.1
CC=mpicc FC=mpif90 F77=mpif77 CXX=mpicxx CPPFLAGS=-I$DIR/grib2/include LDFLAGS=-L$DIR/grib2/lib ./configure --prefix=$DIR/netcdf --with-hdf5=$DIR/grib2 --disable-dap --enable-netcdf-4 --enable-netcdf4 --enable-shared --enable-static --enable-large-file-tests --enable-parallel-tests --enable-hdf5 --enable-nczarr
make check
make install
libtool --finish $DIR/netcdf/lib
export CPPFLAGS="-I$DIR/netcdf/include -I$DIR/grib2/include"
export LDFLAGS="-L$DIR/netcdf/lib -L$DIR/grib2/lib"
export LD_LIBRARY_PATH=$DIR/netcdf/lib:$DIR/grib2/lib:$LD_LIBRARY_PATH
export LIBS="-lnetcdf -lz -lhdf5_hl -lhdf5 -lm"
cd ..
tar xzvf netcdf-fortran-4.5.4.tar.gz
cd netcdf-fortran-4.5.4
CC=mpicc FC=mpif90 F77=mpif77 CXX=mpicxx CPPFLAGS="-I$DIR/netcdf/include -I$DIR/grib2/include" LDFLAGS="-L$DIR/netcdf/lib -L$DIR/grib2/lib" ./configure --prefix=$DIR/netcdf --enable-shared --enable-static --enable-large-file-tests --disable-fortran-type-check
make check
make install
cd ..
e. Now update the .bashrc file. Replace lines below.
# Libraries
export LD_LIBRARY_PATH=$DIR/grib2/lib:$LD_LIBRARY_PATH
export LDFLAGS="-L$DIR/grib2/lib"
export CPPFLAGS="-I$DIR/grib2/include"
With below lines.
# Libraries
export CPPFLAGS="-I$DIR/netcdf/include -I$DIR/grib2/include"
export LDFLAGS="-L$DIR/netcdf/lib -L$DIR/grib2/lib"
export LD_LIBRARY_PATH=$DIR/netcdf/lib:$DIR/grib2/lib:$LD_LIBRARY_PATH
export LIBS="-lnetcdf -lz -lhdf5_hl -lhdf5 -lm"
f. Follow this link to test if all the libraries are working properly or not:
Download the WRF and WPS source codes:
cd ~/WRF_MODEL/
git clone https://github.com/wrf-model/WRF
git clone https://github.com/wrf-model/WPS
Now build WRF first:
source ~/.bashrc
cd WRF
./configure
Choose 34 from the list below:
------------------------------------------------------------------------
Please select from among the following Linux x86_64 options:
1. (serial) 2. (smpar) 3. (dmpar) 4. (dm+sm) PGI (pgf90/gcc)
5. (serial) 6. (smpar) 7. (dmpar) 8. (dm+sm) PGI (pgf90/pgcc): SGI MPT
9. (serial) 10. (smpar) 11. (dmpar) 12. (dm+sm) PGI (pgf90/gcc): PGI accelerator
13. (serial) 14. (smpar) 15. (dmpar) 16. (dm+sm) INTEL (ifort/icc)
17. (dm+sm) INTEL (ifort/icc): Xeon Phi (MIC architecture)
18. (serial) 19. (smpar) 20. (dmpar) 21. (dm+sm) INTEL (ifort/icc): Xeon (SNB with AVX mods)
22. (serial) 23. (smpar) 24. (dmpar) 25. (dm+sm) INTEL (ifort/icc): SGI MPT
26. (serial) 27. (smpar) 28. (dmpar) 29. (dm+sm) INTEL (ifort/icc): IBM POE
30. (serial) 31. (dmpar) PATHSCALE (pathf90/pathcc)
32. (serial) 33. (smpar) 34. (dmpar) 35. (dm+sm) GNU (gfortran/gcc)
36. (serial) 37. (smpar) 38. (dmpar) 39. (dm+sm) IBM (xlf90_r/cc_r)
40. (serial) 41. (smpar) 42. (dmpar) 43. (dm+sm) PGI (ftn/gcc): Cray XC CLE
44. (serial) 45. (smpar) 46. (dmpar) 47. (dm+sm) CRAY CCE (ftn $(NOOMP)/cc): Cray XE and XC
48. (serial) 49. (smpar) 50. (dmpar) 51. (dm+sm) INTEL (ftn/icc): Cray XC
52. (serial) 53. (smpar) 54. (dmpar) 55. (dm+sm) PGI (pgf90/pgcc)
56. (serial) 57. (smpar) 58. (dmpar) 59. (dm+sm) PGI (pgf90/gcc): -f90=pgf90
60. (serial) 61. (smpar) 62. (dmpar) 63. (dm+sm) PGI (pgf90/pgcc): -f90=pgf90
64. (serial) 65. (smpar) 66. (dmpar) 67. (dm+sm) INTEL (ifort/icc): HSW/BDW
68. (serial) 69. (smpar) 70. (dmpar) 71. (dm+sm) INTEL (ifort/icc): KNL MIC
72. (serial) 73. (smpar) 74. (dmpar) 75. (dm+sm) AMD (flang/clang) : AMD ZEN1/ ZEN2/ ZEN3 Architectures
76. (serial) 77. (smpar) 78. (dmpar) 79. (dm+sm) INTEL (ifx/icx) : oneAPI LLVM
80. (serial) 81. (smpar) 82. (dmpar) 83. (dm+sm) FUJITSU (frtpx/fccpx): FX10/FX100 SPARC64 IXfx/Xlfx
Enter selection [1-83] :
Now you have to choose the scenario you want to use:
em_real (3d real case)
em_quarter_ss (3d ideal case)
em_b_wave (3d ideal case)
em_les (3d ideal case)
em_heldsuarez (3d ideal case)
em_tropical_cyclone (3d ideal case)
em_hill2d_x (2d ideal case)
em_squall2d_x (2d ideal case)
em_squall2d_y (2d ideal case)
em_grav2d_x (2d ideal case)
em_seabreeze2d_x (2d ideal case)
em_scm_xy (1d ideal case)
./compile em_real >& log.compile
If you have multi processor and want to leverage it, you can mention the number of processor would like to use. Example: ./compile [-j n] case_name where n is number of processor, default is 2. See below:
./compile -j 8 em_real
Compilation should take about 20-30 minutes.
Once the compilation completes, to check whether it was successful, you need to look for executables in the WRF/main directory:
ls -ls main/*.exe
If you compiled a real case, you should see:
wrf.exe (model executable)
real.exe (real data initialization)
ndown.exe (one-way nesting)
tc.exe (for tc bogusing--serial only)
These executables are linked to 2 different directories:
WRF/run
WRF/test/em_real
You can choose to run WRF from either directory.
Building WPS
cd ~/WRF_MODEL/WPS
source ~/.bashrc
./clean
export JASPERLIB=$DIR/grib2/lib
export JASPERINC=$DIR/grib2/include
export WRF_DIR=/home/<username>/WRF_MODEL/WRF
./configure
Now choose 3 from the list, or according to your selection for WRF model
Now compile WPS:
./compile >& log.compile
Geography Data:
cd ~/WRF_MODEL
wget https://www2.mmm.ucar.edu/wrf/src/wps_files/geog_high_res_mandatory.tar.gz
gunzip geog*.tar.gz
tar -xf geog*.tar
cd WPS
nano namelist.wps
replace: geog_data_path = /home/<username>/WRF_MODEL/WPS_GEOG
When you are done making your changes, press ctrl + O and hit ENTER to save the changes. Close nano by press ctrl + X
Follow this website to download input data and store in INPUT_DATA folder in WRF_MODEL folder.
mkdir INPUT_DATA
Kommentare