1
7

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 1 year has passed since last update.

Visual Studio CodeでIntel oneAPIを使った開発をするための設定方法

Last updated at Posted at 2022-06-09

はじめに

Visual Studio CodeでIntel oneAPIを使った開発をするための設定方法を紹介します。

参考:Using Visual Studio Code with Intel® oneAPI Toolkits User Guide

拡張機能のインストール

MarketplaceからIntel oneAPIのための拡張機能「Extension Pack for Intel(R) oneAPI Toolkits」をインストールします。

WSLを使う場合

常にIntel oneAPIを使って開発を行う場合は、~/.profileまたは~/.bash_profileに以下の行を加えて、常に環境設定が行われるようにします。

. /opt/intel/oneapi/setvars.sh &> /dev/null

そうでない場合は、前述の拡張機能をインストールすると、「Environment Configurator for Intel(R) oneAPI Toolkits」という拡張機能がインストールされるので、VSCodeを開いた後に以下の手順でIntel oneAPIの環境設定を有効にします。

  1. Ctrl+Shift+Pでコマンドパレットを開く。
  2. 「Intel oneAPI」と入力する。
  3. 「Intel oneAPI: Initialize default environment variables.」を選択する。

新しいターミナルやプロセスから環境設定が反映されます。

CMakeとの連携

まずVisual Studio Codeの拡張機能「CMake Tools」をインストールします。そのあと、以下の2つの方法でIntelコンパイラを使ってコンパイルするように設定できます。

settings.jsonで設定する方法

プロジェクトディレクトリの.vscode/settings.jsonにて、プロジェクトで常にIntel Compiler ClassicまたはIntel Compilerを使うように環境変数として設定します。Intel Compiler Classicの場合は

settings.json
{
    "cmake.configureEnvironment": {
        "C": "/opt/intel/oneapi/compiler/latest/linux/bin/intel64/icc",
        "CXX": "/opt/intel/oneapi/compiler/latest/linux/bin/intel64/icpc",
        "FC": "/opt/intel/oneapi/compiler/latest/linux/bin/intel64/ifort"
    }
}

Intel Compilerの場合は

settings.json
{
    "cmake.configureEnvironment": {
        "C": "/opt/intel/oneapi/compiler/latest/linux/bin/icx",
        "CXX": "/opt/intel/oneapi/compiler/latest/linux/bin/icpx",
        "FC": "/opt/intel/oneapi/compiler/latest/linux/bin/ifx"
    }
}

この方法ではコンパイラを切り替えることができないので、次に紹介するCMake Kitsを使った方法をおすすめします。

CMake Kitsを設定する方法

プロジェクトディレクトリの.vscode/cmake-kits.jsonにて、下記の様にIntel Compilerの設定を行います(パスはWSLの例)。

cmake-kits.json
[
    {
        "name": "Intel Compiler Classic",
        "compilers": {
            "C": "/opt/intel/oneapi/compiler/latest/linux/bin/intel64/icc",
            "CXX": "/opt/intel/oneapi/compiler/latest/linux/bin/intel64/icpc",
            "Fortran": "/opt/intel/oneapi/compiler/latest/linux/bin/intel64/ifort"
        }
    },
    {
        "name": "Intel Compiler",
        "compilers": {
            "C": "/opt/intel/oneapi/compiler/latest/linux/bin/icx",
            "CXX": "/opt/intel/oneapi/compiler/latest/linux/bin/icpx",
            "Fortran": "/opt/intel/oneapi/compiler/latest/linux/bin/ifx"
        }
    }
]

参考:CMake Tools | CMake Kits

設定した後は、コマンドパレットを開き、「CMake: Select a kit」を選択し、上記のいずれかのKitを選択してください。その後ConfigureとBuildを行うと、選択したコンパイラーでコンパイルされます。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?