LoginSignup
1
0

More than 1 year has passed since last update.

領域気象モデルWRF-ARWのインストールversion2【macOS】

Last updated at Posted at 2023-04-27

を書き換えようと思ったら、思い切って最初からやり直そう、ということでversion2。
大前提として、必要なlibraryはすべてmacportsを使ってBuildしているよ。

1. 環境とlibrary準備

1.1 動作環境

OS:macOS High Ventura
プロセッサ:Apple M2
メモリ:24GB
※Library関連は省略。全てmacportsでインストール。
※Libraryは、全て同じバージョンのコンパイラでインストールしたものを使う。

1.2 library

WRFの公式ページを確認すると以下のものが必要(2023年4月25日現在)

mpich
netcdf-c
netcdf-fortran
Jasper
libpng
zlib
hdf5
szip

※下記にJasperについてメモあり。

mpichの代わりに、openmpiでも可能。
なので、ここではopenmpiをBuildした時を例にして表示する。

$ sudo port install openmpi
--->  Computing dependencies for openmpi
The following dependencies will be installed:  openmpi-default
Continue? [Y/n]: Y
--->  Fetching distfiles for openmpi-default
--->  Attempting to fetch openmpi-4.1.4.tar.bz2 from https://distfiles.macports.org/openmpi
--->  Verifying checksums for openmpi-default                                        
--->  Extracting openmpi-default
--->  Applying patches to openmpi-default
--->  Configuring openmpi-default
--->  Building openmpi-default                           
--->  Staging openmpi-default into destroot              
--->  Installing openmpi-default @4.1.4_0+gcc12          
--->  Activating openmpi-default @4.1.4_0+gcc12
--->  Cleaning openmpi-default
--->  Fetching archive for openmpi
--->  Attempting to fetch openmpi-4.1.4_0.darwin_22.arm64.tbz2 from https://packages.macports.org/openmpi
--->  Attempting to fetch openmpi-4.1.4_0.darwin_22.arm64.tbz2.rmd160 from https://packages.macports.org/openmpi
--->  Installing openmpi @4.1.4_0
--->  Activating openmpi @4.1.4_0
--->  Cleaning openmpi
--->  Updating database of binaries
--->  Scanning binaries for linking errors
--->  No broken files found.                             
--->  No broken ports found.
--->  Some of the ports you installed have notes:
  openmpi-default has the following notes:
    The mpicc wrapper (and friends) are installed as:
      /opt/local/bin/mpicc-openmpi-mp (likewise mpicxx, ...)
    
    To make openmpi-default's wrappers the default (what you get when you execute 'mpicc' etc.) please run:
      sudo port select --set mpi openmpi-mp-fortran

mpiのセレクトをしておしまい。

$ sudo port select --set mpi openmpi-mp-fortran

といった感じで、sudo port install hogehogeで他のlibraryも入れていく。

1.3 並列計算について

詳細は省略。頑張ってください。

コンパイル時に4パターンから選択する必要がある。
①serial:For a single processor job (serial)
②smpar:For using OpenMP shared-memory parallelization:共有メモリ型 [OpenMPなど]
③dmpar:For using distributed-memory parallelization (dmpar) options:分散メモリ型 [MPIなど, フリーではMPICH, LAMなど]
smparとdmparはmultiple processors用
④dm+sm:For combination of shared-memory and distributed memory options

まぁ…頑張って。笑

1.4 Jasperについて

何も考えずにmacportsでJasperをインストールするとjasper @4.0.0_0あたりが入るけど、1.900.1台じゃないとWRF(WPS)がコンパイルできない。
これ注意。Macportsでの過去バージョンの入れ方は別記事にする。

2.インストール

2.1ソースコードのダウンロード

今は完全にgithubでバージョン管理されている。
2023年4月25日現在、バージョンは4.5。
WRF(WPS)をインストールしたい任意のディレクトリ内でgit cloneする。

$ git clone https://github.com/wrf-model/WRF.git
$ git clone https://github.com/wrf-model/WPS.git

こんなのが出たら正解。

terminal
Cloning into 'WRF'...
remote: Enumerating objects: 62611, done.
remote: Counting objects: 100% (205/205), done.
remote: Compressing objects: 100% (112/112), done.
remote: Total 62611 (delta 103), reused 147 (delta 93), pack-reused 62406
Receiving objects: 100% (62611/62611), 266.60 MiB | 3.18 MiB/s, done.
Resolving deltas: 100% (48564/48564), done.
Updating files: 100% (4758/4758), done.

2.2 WRFのインストール

2.2.1 .wrfrcの作成

NetCDFなどのパスを通す。
.profileとか.zprofileとかにいきなり書き込んでも問題はないが、基本的にはWRFをインストールする時だけ読ませれば良いので、.wrfrcを作成して読み込ませるようにしている。
上手く行ってから、zprofileに。

.wrfrc
### Jasper
export JASPERBIN="/opt/local/bin"
export JASPERINC="/opt/local/include"
export JASPERLIB="/opt/local/lib"

### NetCDF
export NETCDF="/opt/local/" 
export LD_LIBRARY_PATH=$NETCDF/lib:

### Compiler
export FC=gfortran
export F90=gfortran
export F77=gfortran
export CC=gcc
export CXX=g++

### WRF
export WRF_EM_CORE=1
export WRFIO_NCD_LARGE_FILE_SUPPORT=1 
export OMP_NUM_THREADS=4 

### macOS
export MACOSX_DEPLOYMENT_TARGET=13.0

作った.wrfrcを読み込む。

terminal
$ source .wrfrc

2.2.2 netcdf4を使うために、Makefileを書き換える

terminal
$ vi WRF/external/io_netcdf/makefile
WRFV3/external/io_netcdf/makefile
書き換え前
(7行目) LIBS = -L$(NETCDFPATH)/lib -lnetcdf
書き換え後
(7行目) LIBS = -L$(NETCDFPATH)/lib -lnetcdff -lnetcdf

※行数は参考。

###2.2.3 configureの実行
configureを実行する。

terminal
$ ./configure
terminal
checking for perl5... found /opt/local/bin/perl5 (perl5)
Will use NETCDF in dir: /opt/local/
ADIOS2 not set in environment. Will configure WRF for use without.
HDF5 not set in environment. Will configure WRF for use without.
PHDF5 not set in environment. Will configure WRF for use without.
Will use 'time' to report timing information


If you REALLY want Grib2 output from WRF, modify the arch/Config.pl script.
Right now you are not getting the Jasper lib, from the environment, compiled into WRF.

------------------------------------------------------------------------
Please select from among the following Darwin ARCH options:

  1. (serial)   2. (smpar)   3. (dmpar)   4. (dm+sm)   PGI (pgf90/pgcc)
  5. (serial)   6. (smpar)   7. (dmpar)   8. (dm+sm)   INTEL (ifort/icc)
  9. (serial)  10. (smpar)  11. (dmpar)  12. (dm+sm)   INTEL (ifort/clang)
 13. (serial)               14. (dmpar)                GNU (g95/gcc)
 15. (serial)  16. (smpar)  17. (dmpar)  18. (dm+sm)   GNU (gfortran/gcc)
 19. (serial)  20. (smpar)  21. (dmpar)  22. (dm+sm)   GNU (gfortran/clang)
 23. (serial)               24. (dmpar)                IBM (xlf90_r/cc)
 25. (serial)  26. (smpar)  27. (dmpar)  28. (dm+sm)   PGI (pgf90/pgcc): -f90=pgf90
 29. (serial)  30. (smpar)  31. (dmpar)  32. (dm+sm)   INTEL (ifort/icc): Open MPI
 33. (serial)  34. (smpar)  35. (dmpar)  36. (dm+sm)   GNU (gfortran/gcc): Open MPI

Enter selection [1-36] : 36
------------------------------------------------------------------------
Compile for nesting? (1=basic, 2=preset moves, 3=vortex following) [default 1]: 1

Configuration successful! 

(中略)

*****************************************************************************
This build of WRF will use NETCDF4 with HDF5 compression
*****************************************************************************

※バージョンや並列計算の選択によって、表示される組み合わせが多少異なる。

2.2.4 コンパイル

terminal
$  ./compile em_real &> compile_dmsm.log

*時間がかかる。
ログを見ると

compile_dmsm.log
copying Registry/Registry.EM to Registry/Registry
 
============================================================================================== 
 
V4.5
git commit 21c72141142fc6c8d203d2bf79f1990e45a0aef8 1 file changed, 1 insertion(+), 1 deletion(-)
 
Compiling: WRF_EM_CORE  
WRFIO_NCD_LARGE_FILE_SUPPORT=1
 
Darwin na164109.ynu164.ynu.ac.jp 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:52 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8112 arm64
 
GNU Fortran (MacPorts gcc12 12.2.0_2+stdlib_flag) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 
============================================================================================== 
 
setting parallel make -j 2

(中略)

--->                  Executables successfully built                  <---
 
-rwxr-xr-x  1 user  staff  40131542  4 25 10:55 main/ndown.exe
-rwxr-xr-x  1 user  staff  40197365  4 25 10:55 main/real.exe
-rwxr-xr-x  1 user  staff  39648115  4 25 10:55 main/tc.exe
-rwxr-xr-x  1 user  staff  46844740  4 25 10:55 main/wrf.exe
 
==========================================================================

と出力される。
runの中を見ると

terminal
ls
BROADBAND_CLOUD_GODDARD.bin		LANDUSE.TBL				create_p3_lookupTable_1.f90-v5.4
CAM_ABS_DATA				MPTABLE.TBL				create_p3_lookupTable_2.f90-v5.3
CAM_AEROPT_DATA				README.namelist				eclipse_besselian_elements.dat
CAMtr_volume_mixing_ratio		README.physics_files			grib2map.tbl
CAMtr_volume_mixing_ratio.A1B		README.rasm_diag			gribmap.txt
CAMtr_volume_mixing_ratio.A2		README.tslist				ishmael-gamma-tab.bin
CAMtr_volume_mixing_ratio.RCP4.5	RRTMG_LW_DATA				ishmael-qi-qc.bin
CAMtr_volume_mixing_ratio.RCP6		RRTMG_LW_DATA_DBL			ishmael-qi-qr.bin
CAMtr_volume_mixing_ratio.RCP8.5	RRTMG_SW_DATA				kernels.asc_s_0_03_0_9
CAMtr_volume_mixing_ratio.SSP119	RRTMG_SW_DATA_DBL			kernels_z.asc
CAMtr_volume_mixing_ratio.SSP126	RRTM_DATA				masses.asc
CAMtr_volume_mixing_ratio.SSP245	RRTM_DATA_DBL				namelist.input
CAMtr_volume_mixing_ratio.SSP370	SOILPARM.TBL				namelist.output
CAMtr_volume_mixing_ratio.SSP585	SOILPARM.TBL_Kishne_2017		ndown.exe
CCN_ACTIVATE.BIN			STOCHPERT.TBL				ozone.formatted
CLM_ALB_ICE_DFS_DATA			URBPARM.TBL				ozone_lat.formatted
CLM_ALB_ICE_DRC_DATA			URBPARM_LCZ.TBL				ozone_plev.formatted
CLM_ASM_ICE_DFS_DATA			URBPARM_UZE.TBL				p3_lookupTable_1.dat-v5.4_2momI
CLM_ASM_ICE_DRC_DATA			VEGPARM.TBL				p3_lookupTable_1.dat-v5.4_3momI
CLM_DRDSDT0_DATA			aerosol.formatted			p3_lookupTable_2.dat-v5.3
CLM_EXT_ICE_DFS_DATA			aerosol_lat.formatted			real.exe
CLM_EXT_ICE_DRC_DATA			aerosol_lon.formatted			rsl.error.0000
CLM_KAPPA_DATA				aerosol_plev.formatted			rsl.out.0000
CLM_TAU_DATA				bulkdens.asc_s_0_03_0_9			tc.exe
ETAMPNEW_DATA				bulkradii.asc_s_0_03_0_9		termvels.asc
ETAMPNEW_DATA.expanded_rain		capacity.asc				tr49t67
ETAMPNEW_DATA.expanded_rain_DBL		co2_trans				tr49t85
ETAMPNEW_DATA_DBL			coeff_p.asc				tr67t85
GENPARM.TBL				coeff_q.asc				wind-turbine-1.tbl
HLC.TBL					constants.asc				wrf.exe

wrf.exe(hoge.exe)が実行できる状態であれば成功。

2.3 WPSのインストール

2.3.0 .wrfrcを書き換える

WRFのディレクトリ名を変えた時は、.wrfrcにWRFのパスを書き込んで、再度読み込む必要がある。

terminal
export WRF_DIR=/Users/hogehoge/model/WRF-4.5
terminal
$ source .wrfrc

2.3.1 configureの実行

configureを実行する。

terminal
$ ./configure
terminal
Will use NETCDF in dir: /opt/local/
Using WRF I/O library in WRF build identified by $WRF_DIR: /Users/hogehoge/model/WRF-4.5
Found Jasper environment variables for GRIB2 support...
  $JASPERLIB = /opt/local/lib
  $JASPERINC = /opt/local/include
------------------------------------------------------------------------
Please select from among the following supported platforms.

   1.  Darwin Intel PGI compiler   (serial)
   2.  Darwin Intel PGI compiler   (serial_NO_GRIB2)
   3.  Darwin Intel PGI compiler   (dmpar)
   4.  Darwin Intel PGI compiler   (dmpar_NO_GRIB2)
   5.  Darwin Intel PGI compiler; optional DM -f90=pgf90   (serial)
   6.  Darwin Intel PGI compiler; optional DM -f90=pgf90   (serial_NO_GRIB2)
   7.  Darwin Intel PGI compiler; optional DM -f90=pgf90   (dmpar)
   8.  Darwin Intel PGI compiler; optional DM -f90=pgf90   (dmpar_NO_GRIB2)
   9.  Darwin Intel Intel compiler   (serial)
  10.  Darwin Intel Intel compiler   (serial_NO_GRIB2)
  11.  Darwin Intel Intel compiler   (dmpar)
  12.  Darwin Intel Intel compiler   (dmpar_NO_GRIB2)
  13.  Darwin Intel g95 compiler     (serial)
  14.  Darwin Intel g95 compiler     (serial_NO_GRIB2)
  15.  Darwin Intel g95 compiler     (dmpar)
  16.  Darwin Intel g95 compiler     (dmpar_NO_GRIB2)
  17.  Darwin Intel gfortran/gcc    (serial)
  18.  Darwin Intel gfortran/gcc    (serial_NO_GRIB2)
  19.  Darwin Intel gfortran/gcc    (dmpar)
  20.  Darwin Intel gfortran/gcc    (dmpar_NO_GRIB2)
  21.  Darwin Intel gfortran/clang    (serial)
  22.  Darwin Intel gfortran/clang    (serial_NO_GRIB2)
  23.  Darwin Intel gfortran/clang    (dmpar)
  24.  Darwin Intel gfortran/clang    (dmpar_NO_GRIB2)
  25.  Darwin PPC xlf    (serial)
  26.  Darwin PPC xlf    (serial_NO_GRIB2)
  27.  Darwin PPC xlf gcc3.3 SystemStubs   (serial)
  28.  Darwin PPC xlf gcc3.3 SystemStubs   (serial_NO_GRIB2)
  29.  Darwin PPC g95    (serial)
  30.  Darwin PPC g95    (serial_NO_GRIB2)
  31.  Darwin PPC g95    (dmpar)
  32.  Darwin PPC g95    (dmpar_NO_GRIB2)

Enter selection [1-32] : 17
------------------------------------------------------------------------
Configuration successful. To build the WPS, type: compile
------------------------------------------------------------------------

※基本的にWPSではSerialを公式に推奨されている。
※バージョンや並列計算の選択によって、表示される組み合わせが多少異なる。

2.3.3 configure.wpsを書き換える

terminal
$ vi configure.wps
configure.wps
書き換え前
(48行目)  -L$(NETCDF)/lib -lnetcdff -lnetcdf
書き換え後
(48行目)  -L$(NETCDF)/lib -lnetcdff -lnetcdf -lgomp

※行数は参考。

2.3.4 コンパイル

terminal
$  ./compile &> compile_wps_serial.log &

※WRFほどではないけど少し時間がかかる。
ログを見ると

compile_wps_serial.log
============================================================================================== 
 
Version 4.5
 
Darwin hogehoge.local 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:52 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8112 arm64
 
GNU Fortran (MacPorts gcc12 12.2.0_2+stdlib_flag) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 
============================================================================================== 
 
 
**** Compiling WPS and all utilities ****
(中略)
/bin/rm -f int2nc.f90
/usr/bin/cpp -P -traditional -D_UNDERSCORE -DBYTESWAP -DIO_NETCDF -DBIT32 -DMACOS -DNO_SIGNAL  -D_UTIL int2nc.F > int2nc.f90
gfortran -ffree-form -O -fconvert=big-endian -frecord-marker=4 -I/Users/yoshioka/model/WRF-4.5/external/io_netcdf -I/Users/yoshioka/model/WRF-4.5/external/io_grib_share -I/Users/yoshioka/model/WRF-4.5/external/io_grib1 -I/Users/yoshioka/model/WRF-4.5/external/io_int -I/Users/yoshioka/model/WRF-4.5/inc -I/opt/local//include -c int2nc.f90
gfortran -o int2nc.exe  -I/Users/yoshioka/model/WRF-4.5/external/io_netcdf -I/Users/yoshioka/model/WRF-4.5/external/io_grib_share -I/Users/yoshioka/model/WRF-4.5/external/io_grib1 -I/Users/yoshioka/model/WRF-4.5/external/io_int -I/Users/yoshioka/model/WRF-4.5/inc -I/opt/local//include int2nc.o module_debug.o misc_definitions_module.o read_met_module.o cio.o -L/Users/yoshioka/model/WRF-4.5/external/io_grib1 -lio_grib1 -L/Users/yoshioka/model/WRF-4.5/external/io_grib_share -lio_grib_share -L/Users/yoshioka/model/WRF-4.5/external/io_int -lwrfio_int -L/Users/yoshioka/model/WRF-4.5/external/io_netcdf -lwrfio_nf -L/opt/local//lib -lnetcdff -lnetcdf -lgomp 
if [ -h int2nc.exe ] ; then \
		/bin/rm -f int2nc.exe ; \
	fi ; \
	if [ -h ../int2nc.exe ] ; then \
		/bin/rm -f ../int2nc.exe ; \
	fi ; \
	if [ -e src/int2nc.exe ] ; then \
		ln -sf src/int2nc.exe . ; \
	fi

と出力される。
WPSの中を見ると

terminal
$ ls
README				external			metgrid				ungrib
arch				geogrid				metgrid.exe			ungrib.exe
clean				geogrid.exe			metgrid.log			ungrib.log
compile				geogrid.log			namelist.wps			util
configure			link_grib.csh			namelist.wps.all_options
configure.wps			log.compile_serial		namelist.wps.fire
configure.wps.backup		namelist.wps.global

※geogrid.exe、ungrib.exe、metgrid.exeが実行できる状態であれば成功。

3. 最後に。

ちょっと手こずった。随時更新していきます。
macportsでやりましたが、他のパッケージ管理でも良いし、自力で入れてもOK。
パスを通すところを変えるだけです。
いずれにしても、jasperのバージョンには要注意。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0