0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSL2 Ubuntu 24.04 におけるIntel oneAPIとNetCDF-Fortranのインストール

Last updated at Posted at 2025-09-26

Intel oneAPIのインストール

不要かもしれませんが,以下を実行しておきます.

sudo apt update
sudo apt -y install cmake pkg-config build-essential

aptでoneAPIの最新版をインストールします.2025年9月26日現在の公式ガイドに従います.GPUは使いません.
以下をまるごとターミナルへコピペし,Enterを押します.ハングアップしたように見えるのはrootのpassword入力待ち状態ですので,入力し,Enterを押します.

# download the key to system keyring
wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
| gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null

# add signed entry to apt sources and configure the APT client to use Intel repository:
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list

続けて,以下を一つずつターミナルにコピペしてEnterを押します.画面の指示に従って,Yの選択が必要です(デフォルトなので,Enterを押すだけです).公式ガイド通りではうまくいきませんでした.

sudo apt update
sudo apt install -y curl ca-certificates gnupg
# 1) Fetch and install Intel oneAPI APT signing key to a dedicated keyring
#    (apt-key is deprecated; use a keyring under /usr/share/keyrings)
curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
| sudo gpg --dearmor -o /usr/share/keyrings/oneapi-archive-keyring.gpg
# 2) (Optional) Verify the key contains the keyid BAC6F0C353D04109
gpg --show-keys --with-fingerprint /usr/share/keyrings/oneapi-archive-keyring.gpg
# 3) Ensure the repo entry uses `signed-by=` and exists only once
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" \
| sudo tee /etc/apt/sources.list.d/oneAPI.list > /dev/null
# 4) Clear stale lists for this repo (just in case) and update
sudo rm -f /var/lib/apt/lists/apt.repos.intel.com_oneapi* || true
sudo apt update
sudo apt install intel-oneapi-base-toolkit

次にIntel® oneAPI Toolkitsをインストールします.
以下をまるごとターミナルにコピペしてEnterを押します.

# download the key to system keyring
wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
| gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null

# add signed entry to apt sources and configure the APT client to use Intel repository:
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list

以下を一つずつターミナルにコピペし,Enterを押します.画面の指示に従って,Yの選択が必要です(デフォルトなので,Enterを押すだけです)

sudo apt update
sudo apt install intel-oneapi-hpc-toolkit

ここでエラーが出たら,以下を実行します.

# 1) Create the missing temp subdir and make it writable
sudo mkdir -p /tmp/oneapi
sudo chmod 1777 /tmp/oneapi
# 2) Re-run configuration for any packages left half-configured
sudo dpkg --configure -a
# 3) (Optional) Explicitly re-run the affected postinst by reinstalling the package
sudo apt --reinstall install intel-oneapi-ishmem-devel-1.4 intel-oneapi-ishmem-devel intel-oneapi-ishmem-1.4
sudo apt install intel-oneapi-hpc-toolkit

以上でインストール完了です.oneAPIの環境を有効にするため,以下を実行します.ターミナル起動時に有効にするなら,~/.bashrc に追記します.

source /opt/intel/oneapi/setvars.sh

ifx --version で以下のように起動できれば成功です.

$ ifx --version
ifx (IFX) 2025.2.1 20250806
Copyright (C) 1985-2025 Intel Corporation. All rights reserved.

NetCDFのインストール

真面目にインストールするのは大変骨がおれるので,簡易な方法を採用します.

最初に以下を順番に実行し,C版のNetCDFをaptでインストールします.icxでコンパイルしなくても問題ないようです.

sudo apt update
sudo apt install hdf5-tools hdf5-helpers libhdf5-dev libhdf5-doc libhdf5-serial-dev
sudo apt install libnetcdf-dev

nc-config --all を実行して,以下のようになれば成功です.

$ nc-config --all

This netCDF 4.9.2 has been built with the following features:

  --cc            -> /usr/bin/cc
  --cflags        -> -I/usr/include -I/usr/include/hdf5/serial
  --libs          -> -L/usr/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu/hdf5/serial -lnetcdf
  --static        -> -lhdf5_hl -lhdf5 -lcrypto -lcurl -lpthread -lsz -lz -ldl -lm -lxml2


  --has-dap          -> yes
  --has-dap2         -> yes
  --has-dap4         -> yes
  --has-nc2          -> yes
  --has-nc4          -> yes
  --has-hdf5         -> yes
...

さらに,ncdumpを使えるようにしましょう.

sudo apt install netcdf-bin

NetCDF-Fortranのインストール

準備が整ったので,NetCDF-FortranをoneAPIでビルドします.最初に以下の環境変数を設定します.

# Example: set HDF5 plugin path for this shell
export HDF5_PLUGIN_PATH="$(nc-config --plugindir)"

# 念のためランタイムローダにもパスを追加(必要なら)
export LD_LIBRARY_PATH="$(nc-config --libdir):$LD_LIBRARY_PATH"

また,man pageのインストールのため,以下の m4 もインストールしておきます.

sudo apt update
sudo apt install -y m4

~/Downloads で作業します.NetCDF-Fortranのソースコードを こちら で確認し,最新版を入手します.以下ではwgetで入手しました.バージョンは最新版に読み替えます.

cd ~/Downloads
wget https://downloads.unidata.ucar.edu/netcdf-fortran/4.6.2/netcdf-fortran-4.6.1.tar.gz
tar xf netcdf-fortran-4.6.2.tar.gz
cd netcdf-fortran-4.6.2

と言いたいところですが,以下の make checkエラーになりました.そこで,こちらのAssetsからversion 4.6.1のtar.gzをダウンロードしてコンパイルしました.以下はversion 4.6.1で表記しますが,4.6.2でうまくいくようになれば,読み替えます.

エディタで以下の内容のテキストファイル config-ifx-netcdff.sh をカレントディレクトリ(今の場合は,~/Downloads/netcdf-fortran-4.6.1)に作成します.最下行のバージョンはダウンロードしたソースコードに合わせます.

#!/bin/bash
# Building netcdf-fortran using oneAPI ifx
export CDFROOT="/usr"
export LD_LIBRARY_PATH="${CDFROOT}/lib:${LD_LIBRARY_PATH}"
export LDFLAGS="-L${CDFROOT}/lib -I${CDFROOT}/include"
#export OPTIM="-O2 -xHost -mcmodel=large -fPIC ${LDFLAGS}"
export OPTIM="-O2 -xHost -mcmodel=large -fPIC"
#
export CC=icx
export CXX=icpx
export FC=ifx
export F77=ifx
export F90=ifx
export CPP="icx -E -mcmodel=large"
export CXXCPP="icpx -E -mcmodel=large"
#export CPPFLAGS="-DNDEBUG -DpgiFortran ${LDFLAGS}"
export CPPFLAGS="-DNDEBUG"
#
export CFLAGS="${OPTIM}"
export CXXFLAGS="${OPTIM}"
export FCFLAGS="${OPTIM}"
export F77FLAGS="${OPTIM}"
export F90FLAGS="${OPTIM}"
#
# ./configure --prefix=/usr/local/netcdf-ifx/4.6.1 --enable-large-file-tests --with-pic
./configure \
  --prefix=/usr/local/netcdf-ifx/4.6.1 \
  --exec-prefix=/usr/local/netcdf-ifx/4.6.1 \
  --bindir=/usr/local/netcdf-ifx/4.6.1/bin \
  --enable-large-file-tests \
  --with-pic

config-ifx-netcdff.sh に実行権限を付与し,実行します.make check はテスト実行で,見にくいですが,緑で PASS: 2,赤で ERROR: 0 のようになっていれば成功です.

chmod a+x config-ifx-netcdff.sh
./config-ifx-netcdff.sh
make
make check
sudo make install

環境変数の設定

~/.bashrcPATHLD_LIBRARY_PATH を追記し,再ログインします.versionは実際のものに置き換えてください.

# NetCDF-Fortran using Intel oneAPI (ifx)
export PATH="/usr/local/netcdf-ifx/4.6.1/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/netcdf-ifx/4.6.1/lib:$LD_LIBRARY_PATH"

確認

nf-config --all を実行して以下のようになれば成功です.

$ nf-config --all

This netCDF-Fortran 4.6.1 has been built with the following features:

  --cc        -> icx
  --cflags    -> -I/usr/local/netcdf-ifx/4.6.1/include -DNDEBUG

  --fc        -> ifx
  --fflags    -> -I/usr/local/netcdf-ifx/4.6.1/include -I/usr/local/netcdf-ifx/4.6.1/include
  --flibs     -> -L/usr/local/netcdf-ifx/4.6.1/lib -lnetcdff -L/usr/lib -I/usr/include -lnetcdf -lnetcdf -lm
  --has-f90   ->
  --has-f03   -> yes

  --has-nc2   -> yes
  --has-nc4   -> yes

  --prefix    -> /usr/local/netcdf-ifx/4.6.1
  --includedir-> /usr/local/netcdf-ifx/4.6.1/include
  --version   -> netCDF-Fortran 4.6.1

注意: nf-config がインストールされなかったことがありました.原因不明ですが,ビルドしたディレクトリルートにnf-configが存在したので,手動でインストールしました.

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?