Get Started

  • 2021.2
  • 03/27/2021
  • Public Content

Build and Run a Sample Project Using the Command Line

Intel® oneAPI HPC Toolkit
If you have not already configured your development environment, go to Configure Your System then return to this page. If you have already completed the steps to configure your system, continue with the steps below.
Command line development can be done with a terminal window or done through Visual Studio Code*. For details on how to use VS Code locally, see Basic Usage of Visual Studio Code with oneAPI on Linux*. To use VS Code remotely, see Remote Visual Studio Code Development with oneAPI on Linux*.
To compile and run a sample:
  1. Download the sample using the oneAPI CLI Samples Browser.
  2. Compile and run the sample with
    Make*

Download Samples using the oneAPI CLI Samples Browser

Use the oneAPI CLI Samples Browser to browse the collection of online oneAPI samples. As you browse the oneAPI samples, you can copy them to your local disk as buildable sample projects. Most oneAPI sample projects are built using Make or CMake, so the build instructions are included as part of the sample in a README file. The oneAPI CLI utility is a single-file, stand-alone executable that has no dependencies on dynamic runtime libraries.
An internet connection is required to download the samples for oneAPI toolkits. For information on how to use this toolkit offline, see Developing with Offline Systems in the Troubleshooting section.
To watch a video presentation of how to create a project with the command line, see Exploring Intel® oneAPI Samples from the Command Line.
  1. Open a
    terminal
    window.
  2. If you did not complete the steps in One time set up for setvars.sh in the Configure Your System section,
    set
    system variables by
    sourcing
    setvars:
    For root or sudo installations:
    . <install_dir>/setvars.sh
    For local user installations:
    . ~/intel/oneapi/setvars.sh
    The command above assumes you installed to the default folder. If you customized the installation folder,
    setvars.sh
    is in your custom folder.
    The
    setvars.sh
    script can be managed using a configuration file, which is especially helpful if you need to initialize specific versions of libraries or the compiler, rather than defaulting to the "latest" version. For more details, see Using a Configuration File to Manage Setvars.sh.
    If you need to setup the environment in a non-POSIX shell, see
    oneAPI Development Environment Setup for more configuration options.
  3. In the same
    terminal
    window, run the application
    (it should be in your PATH)
    :
    oneapi-cli
    The oneAPI CLI menu appears:
  4. Move the arrow key down to select
    Create a project
    , then press
    Enter
    . The language selection will appear. If you installed
    Intel® oneAPI Base Toolkit
    , but you want to work with the
    Intel® oneAPI HPC Toolkit
    and samples, ensure the HPC toolkit is installed. If it is not installed, install the HPC toolkit, then return to step 1 of this procedure.
  5. Select the language for your sample. For your first project, select
    cpp
    , then press
    Enter
    . The toolkit samples list appears.
  6. Select the
    Matrix Mul
    sample which appears at the top of the list:
  7. After you select a sample, press
    Enter
    .
  8. Specify the location for the project. The default location includes the path from where the utility was run and the name of the project.
  9. Press
    Tab
    to select Create, then press
    Enter
    :
Now that you have the samples downloaded, compile and run the sample with

Build and Run a Sample Using Make*

The Matrix Multiplier sample does not require CMake*, but many of the other samples do. If you have not installed CMake, follow the directions Configure Your System.
Build the
matrix_mul
Program
using Make:
cd matrix_mul && make all
Run the Program
make run
Clean the Program
make clean

Build and Run a Project Based on a oneAPI Sample using CMake

To run a different sample using CMake, where
<sample_name>
is the name of the sample you want to run:
  1. If necessary, re-run the command-line utility and select a CMake project that contains a
    CMakeLists.txt
    file.
    cd <sample_name> &&
  2. Navigate to the build directory.
    mkdir build && cd build &&
  3. Build the program. Run CMake in the build directory to create the makefile. Use the newly created makefile to build the executable.
    cmake ../. && make VERBOSE=1
  4. Run the program.
    make run
  5. Clean the program.
    make clean

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.