---
name: "PAPI_set_cmp_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_cmp_granularity"
---

# PAPI\_set\_cmp\_granularity(3)

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

## NAME

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

## SYNOPSIS

## Detailed Description

**C Prototype:**

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

**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

*cidx* An integer identifier for a component. By convention, component 0 is always the cpu component.

**Return values**

*PAPI\_OK* \
 *PAPI\_EINVAL* One or more of the arguments is invalid. \
 *PAPI\_ENOCMP* The argument cidx is not a valid component.

**PAPI\_set\_cmp\_granularity** sets the default counting granularity for all new event sets, and requires an explicit component argument. Event sets that are already in existence are not affected.

To change the granularity of an existing event set, please see **PAPI\_set\_opt**. The reader should note that the granularity of an event set affects only the mode in which the counter continues to run.

**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_cmp_granularity(PAPI_GRN_PROC, 0);
if (ret != PAPI_OK) handle_error(ret);
ret = PAPI_create_eventset(&EventSet);
if (ret != PAPI_OK) handle_error(ret);
```

**See also**

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

## Author

Generated automatically by Doxygen for PAPI from the source code.
