num_devices

Defined in header <Kokkos_Core.hpp>

Usage

Kokkos::num_devices();

Returns the number of available devices on the system, or -1 if only host backends are enabled.

Interface

[[nodiscard]] int num_devices() noexcept
Returns:

The number of devices available to Kokkos, or -1 if only host backends are enabled.

Added in version 4.3.

Example

#include <Kokkos_Core.hpp>
#include <iostream>

int main(int argc, char* argv[]) {
  if (Kokkos::num_devices() == 0) {
    std::cerr << "no device available for execution\n";
    return 1;
  }
  Kokkos::initialize(argc, argv);
  // do stuff
  Kokkos::finalize();
  return 0;
}

Notes

Note

num_devices() is one of the few runtime functions that may be called before initialize() or after finalize().

See Also

See also

device_id

Returns the id of the device used by Kokkos

num_threads

Returns the number of threads used by Kokkos

print_configuration

Prints Kokkos configuration information to an output stream

initialize

Initialize the Kokkos execution environment

InitializationSettings

Settings for initializing Kokkos