Run a Sample Project Using the Command Line

Intel® oneAPI HPC Toolkit

Note

An internet connection is required to download the samples for oneAPI toolkits. If you are using an offline system, download the samples from a system that is internet connected and transfer the sample files to your offline system. The samples can be downloaded from here:

Intel® oneAPI HPC Toolkit Code Samples

Note

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. You can find the samples browser in the <install-dir>/dev-utilities/latest/bin folder on your development host system.

  1. Open a terminal window.
  2. If you did not complete the steps in Option 2: One time set up for setvars.sh, navigate to the install directory, which is typically /opt/intel/inteloneapi/ when installed as root or sudo, and ~/intel/inteloneapi/ when not installed as a super user. If you customized the installation folder, the setvars.sh is in your custom folder.
  3. Set system variables by running setvars:
    source setvars.sh

    Note

    The setvars.sh script can also be managed using a configuration file. For more details, see Using a Configuration File to Manage Setvars.sh

  4. In the same terminal window, run the application (it should be in your PATH):

    oneapi-cli

    The oneAPI CLI menu appears:

  5. Move the arrow key down to select Create a project , then press Enter
  6. Select the language for your sample. For your first project, select cpp, then press Enter. The toolkit samples list appears.

7. Select the Matrix Multiplication sample.

8. After you select a sample, press Enter.

9. Enter an absolute or a relative directory path to create your project. Provide a directory and project name. The Project Name is the name of the sample you chose in the previous step.

10. Press Tab to select Create, then press Enter:

The directory path is printed to the command line.

Now that you have the samples downloaded, compile and run the sample with CMake*

Compile and Run a Sample Using Make*

Note

The Matrix Multiplier sample does not require CMake*, but manny of the other samples do require CMake. 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

Create 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
For more complete information about compiler optimizations, see our Optimization Notice.