2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WRF4.3.3をubuntu 20.04.3/intel-mpi (oneapi)にてコンパイル

Last updated at Posted at 2022-01-30

領域気象ソフトWRFのコンパイルメモ

intel-mpiを使うのが初めてだったので、戸惑った箇所を中心にメモ (2022.04版)
※Intel oneAPI HPC Toolkit (Intel-MPI)の使用を前提としています。

環境

wrf4.3.3 (openmp/intel-mpi)
ubuntu 20.04.3
intel compiler/mpi (oneAPI 2022.1)
AMD Threadripper Pro (第三世代)

方針

ライブラリは/usr/local/intelにまとめる (gcc由来のものと混在を避ける)

注意点

  1. zlib: -fPICが必要(hdf5作成)
  2. hdf5: configure後に作成されるlibtoolを一部修正
    (sudo時のicc/ifort対応)
  3. WPS: configure.wps修正 (WRF_LIB, DM_FC, DM_CC, 後の2つはIntel-MPI対応)

setintel.sh

intelコンパイラ環境設定スクリプト (~/binに置く)

setintel.sh
export CC=icc
export CXX=icpc
export FC=ifort
export F77=ifort
export F90=ifort
export CFLAGS='-O3 -ip'
export CXXFLAGS='-O3 -ip'
export FFLAGS='-O3 -ip'
export CPP="icc -E"
export CXXCPP="icpc -E"
source /opt/intel/oneapi/setvars.sh
export LD_LIBRARY_PATH=/usr/local/intel/lib:${LD_LIBRARY_PATH#/usr/local/intel/lib:}
export LD_RUN_PATH=/usr/local/intel/lib:${LD_RUN_PATH#/usr/local/intel/lib:}
export LDFLAGS='-L/usr/local/intel/lib -I/usr/local/intel/include'
export CPPFLAGS='-I/usr/local/intel/include'
export PATH=/usr/local/intel/bin:${PATH#/usr/local/intel/bin:}
export NETCDF=/usr/local/intel
export MANPATH=/usr/local/intel/man:${MANPATH#/usr/local/intel/man:}
export PKG_CONFIG_PATH=/usr/local/intel/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig:${PKG_CONFIG_PATH}

実行するには

$ source ~/bin/setintel.sh

スクリプト前の"source"を忘れると機能しない。
ifortと入力して "ifort: ... no files specified ... -help"と出れば成功。
コンパイラ使用前やwrf.exe実行前などにログイン後一度だけ行なう。

関連ライブラリの準備

基本は

$ ./configure --prefix=/usr/local/intel
$ make
$ make check
$ sudo make install

zlib 1.2.11: configureのオプションに CFLAGS='-O3 -ip -fPIC'追加
szip 2.1.1
jasper 1.900.1
libpng 1.6.37
hdf5 1.12.1: configureオプション追加、libtool修正

$ ./configure --prefix=/usr/local/intel  \
--enable-fortran --enable-cxx --enable-hl  \
--with-szlib=/usr/local/intel --with-zlib=/usr/local/intel

configure実行後に作成されるファイルlibtool冒頭に一行追加

libtool (line30)
# along with this program.  If not, see ...
source /opt/intel/oneapi/setvars.sh

この操作をしないとsudo make install実行時に、コンパイラ関連のpathがsuに引き継がれず、エラー(ifort not found)になる。

netcdf c 4.8.1, fortran 4.5.4 (m4が必要): configureのオプション追加

$ ./configure CPPFLAGS="-I/usr/local/intel/include" --prefix=/usr/local/intel

ncl 6.6.2  aptを利用

$ sudo apt install ncl-ncarg
$ export NCARG_ROOT=/usr/share/ncarg

→ nclの塗りつぶしがうまく働かない時は(WPS/util/plotgrids_new.nclなど)
minicondaを使ってインストール(下記参照)

WRF/WPSコンパイル

ダウンロード

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

※カレントディレクトリの下にWRF, WPSが作成される

WRF (cshが必要)    コンパイルには数十分かかる

$ cd WRF
$ ./configure    # 16: intel compiler (dm+sm) を選択
$ ./compile em_real 2>&1 | tee log.compile

wrf.exe, real.exe, ndown.exeができていれば成功
導入したWRFのバージョンは、log.compileの7行目に記載 ("V4.3.3")

WPS
(1) configureを実行

cd ../WPS
export JASPERLIB=/usr/local/intel/lib
export JASPERINC=/usr/local/intel/include
export WRF_DIR=../WRF
./configure  # 19: intel compiler (dmpar)を選択

(2) 新たにできるconfigure.wpsを手で修正

configure.wps
WRF_LIB= ... -qopenmp   # 最後(-lnetcdfの後)に追加
  ...
DM_FC=mpiifort   # mpif90から変更。'mpiif90'は存在しないので注意
DM_CC=mpiicc     # mpiccから変更。  FC,CCは変更不要

DM_FC, DM_CCの変更は、Intel-MPIを使用する場合のみ
使わない時は、変更不要(mpif90, mpiccのまま)

修正をしないとそれぞれ次のエラーが出る
WRF_LIB     undefined reference to kmpc...
DM_FC,DM_CC  undefined reference to mpi_init ...

(3) コンパイル (WRFほどはかからない)

$ ./compile 2>&1 | tee log.compile

geogrid.exe, metgrid.exe, ungrib.exeができていれば成功
導入したWPSのバージョンは、log.compileの3行目に記載 ("Version 4.3.1")

他にデータファイルを下記からダウンロードして、WPS_GEOGに置く必要あり
(詳細はリンク先参照)
https://www2.mmm.ucar.edu/wrf/users/download/get_sources_wps_geog.html

関連リンク

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?