PAPIC:PAPI set granularity.3
From PAPIDocs
Jump to: navigation, search


  • PAPI_set_granularity - set the default counting granularity for eventsets bound to the cpu component
  • PAPI_set_cmp_granularity - set the default counting granularity for eventsets bound to the specified component


C Interface

#include <papi.h>
int PAPI_set_granularity(int  granularity );
int PAPI_set_cmp_granularity(int  granularity, int  cidx  );

Fortran Interface

#include fpapi.h
PAPIF_set_granularity(C_INT  granularity,  C_INT  check )


PAPI_set_granularity sets the default counting granularity for all new event sets created by PAPI_create_eventset (3). This call implicitly sets the granularity for the cpu component (component 0) and is included to preserve backward compatibility.

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 the PAPI_set_opt (3) man page. The reader should note that the granularity of an event set affects only the mode in which the counter continues to run.


cidx -- An integer identifier for a component. By convention, component 0 is always the cpu component. 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 CPU's individually
PAPI_GRN_MIN The finest available granularity
PAPI_GRN_MAX The coarsest available granularity


PAPI_EINVAL One or more of the arguments is invalid.

PAPI_ENOEVST The event set specified does not exist.

PAPI_ENOCMP The argument cidx is not a valid component.

PAPI_EISRUN The event set is currently counting events.


int retval;
/* Initialize the library */
retval = PAPI_library_init(PAPI_VER_CURRENT);
if (retval > 0 && retval != PAPI_VER_CURRENT) {
  fprintf(stderr,"PAPI library version mismatch!\n");
if (retval < 0)
/* Set the default granularity for the cpu component */
if ((retval = PAPI_set_cmp_granularity(PAPI_GRN_PROC,0)) != PAPI_OK)
if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)


This function has no known bugs.

See Also

PAPI_set_domain(3), PAPI_set_opt(3), PAPI_get_opt(3)