---
name: "PAPI_num_counters"
section: "3"
platform: "linux"
package: "libpapi-dev"
version: "5.7.0+dfsg-2"
release: "Debian 10 (Buster)"
platforms: ["linux"]
url: "https://new.carta.tech/PAPI_num_counters"
---

# PAPI\_num\_counters(3)

Get the number of hardware counters available on the system.

## NAME

PAPI\_num\_counters -

Get the number of hardware counters available on the system.

## SYNOPSIS

## Detailed Description

```
@par C Interface:
int PAPI_num_counters( void );
```

**Postcondition:**

Initializes the library to PAPI\_HIGH\_LEVEL\_INITED if necessary.

**Return values:**

*PAPI\_EINVAL* **papi.h** is different from the version used to compile the PAPI library. \
 *PAPI\_ENOMEM* Insufficient memory to complete the operation. \
 *PAPI\_ESYS* A system or C library call failed inside PAPI, see the errno variable.

**Examples:**

```
* int num_hwcntrs;
* //  The installation does not support PAPI
* if ((num_hwcntrs = PAPI_num_counters()) < 0 )
*   handle_error(1);
* //  The installation supports PAPI, but has no counters
* if ((num_hwcntrs = PAPI_num_counters()) == 0 )
*   fprintf(stderr,"Info:: This machine does not provide hardware counters.0);
*
```

**PAPI\_num\_counters()** returns the optimal length of the values array for the high level functions. This value corresponds to the number of hardware counters supported by the current CPU component.

**Note:**

This function only works for the CPU component. To determine the number of counters on another component, use the low level **PAPI\_num\_cmp\_hwctrs()**.

## Author

Generated automatically by Doxygen for PAPI from the source code.
