---
name: "PAPI_set_granularity"
section: "3"
platform: "linux"
package: "libpapi-dev"
version: "7.1.0-5+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/PAPI_set_granularity"
---

# PAPI\_set\_granularity(3)

Set the default counting granularity for eventsets bound to the cpu component.

## NAME

PAPI\_set\_granularity - Set the default counting granularity for eventsets bound to the cpu component.

## SYNOPSIS

## Detailed Description

**C Prototype:**

\#include \<**papi.h**\> \
\
  int **PAPI\_set\_granularity( int granularity )**;

**Parameters**

*--* granularity one of the following constants as defined in the **papi.h** header file

- •

  PAPI\_GRN\_THR -- Count each individual thread

- •

  PAPI\_GRN\_PROC -- Count each individual process

- •

  PAPI\_GRN\_PROCG -- Count each individual process group

- •

  PAPI\_GRN\_SYS -- Count the current CPU

- •

  PAPI\_GRN\_SYS\_CPU -- Count all CPUs individually

- •

  PAPI\_GRN\_MIN -- The finest available granularity

- •

  PAPI\_GRN\_MAX -- The coarsest available granularity

**Return values**

*PAPI\_OK* \
 *PAPI\_EINVAL* One or more of the arguments is invalid.

**PAPI\_set\_granularity** sets the default counting granularity for all new event sets created by **PAPI\_create\_eventset**. This call implicitly sets the granularity for the cpu component (component 0) and is included to preserve backward compatibility.

**Example:**

```
int ret;
// Initialize the library
ret = PAPI_library_init(PAPI_VER_CURRENT);
if (ret > 0 && ret != PAPI_VER_CURRENT) {
  fprintf(stderr,"PAPI library version mismatch!\n");
  exit(1);
}
if (ret < 0) handle_error(ret);
// Set the default granularity for the cpu component
ret = PAPI_set_granularity(PAPI_GRN_PROC);
if (ret != PAPI_OK) handle_error(ret);
ret = PAPI_create_eventset(&EventSet);
if (ret != PAPI_OK) handle_error(ret);
```

**See also**

**PAPI\_set\_cmp\_granularity** **PAPI\_set\_domain** **PAPI\_set\_opt** **PAPI\_get\_opt**

## Author

Generated automatically by Doxygen for PAPI from the source code.
