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

To compile and run a sample:

  1. Configure your development environment using the steps described in Configure Your System.
  2. Download the sample using the oneAPI CLI Samples Browser.
  3. 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. Navigate to the install directory.
  3. If you have not done so already, source setvars.sh.
  4. 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. Scroll down to see the full list of samples. Select one of these samples for your first project:
    Toolkit Sample Name
    Intel® oneAPI Base Toolkit Vector Add
    Intel® oneAPI HPC Toolkit Matrix Multiplication
    Intel® oneAPI IoT Toolkit IoT Hello World
    Intel® oneAPI DL Framework Developer Toolkit CCL Getting Started

  7. After you select a sample, press Enter.
  8. 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.
  9. 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.