Wiki

Clone wiki

papi / PAPI-Timers


PAPI Timers

PAPI timers use the most accurate timers available on the platform in use. These timers can be used to obtain both real and virtual time on each supported platform. The real time clock runs all the time (e.g. a wall clock) and the virtual time clock runs only when the processor is running in user mode.

Real Time

Real time can be acquired in clock cycles and microseconds by calling the following low-level functions, respectively:

C:

PAPI_get_real_cyc()
PAPI_get_real_usec()

Fortran:

PAPIF_get_real_cyc(check)
PAPIF_get_real_usec(check)

Both of these functions return the total real time passed since some arbitrary starting point and are equivalent to wall clock time. Also, these functions always succeed (error-free) since they are guaranteed to exist on every PAPI supported platform.

In the following code example, PAPI_get_real_cyc and PAPI_get_real_usec are used to obtain the real time it takes to create an event set in clock cycles and microseconds, respectively:

#include <papi.h>

main()
{
    long_long start_cycles, end_cycles, start_usec, end_usec;
    int EventSet = PAPI_NULL;

    if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
    exit(1);

    /* Gets the starting time in clock cycles */
    start_cycles = PAPI_get_real_cyc();

    /* Gets the starting time in microseconds */
    start_usec = PAPI_get_real_usec();

    /*Create an EventSet */
    if (PAPI_create_eventset(&EventSet) != PAPI_OK)
    exit(1);
    /* Gets the ending time in clock cycles */
    end_cycles = PAPI_get_real_cyc();

    /* Gets the ending time in microseconds */
    end_usec = PAPI_get_real_usec();

    printf("Wall clock cycles: %lld\n", end_cycles - start_cycles);
    prinf("Wall clock time in microseconds: %lld\n", end_usec - start_usec); 
}

Possible Output

Wall clock cycles: 100173
Wall clock time in microseconds: 136

Virtual Time

Virtual time can be acquired in clock cycles and microseconds by calling the following low-level functions, respectively:

C:

PAPI_get_virt_cyc()
PAPI_get_virt_usec()

Fortran:

PAPIF_get_virt_cyc(check)
PAPIF_get_virt_usec(check)

Both of these functions return the total number of virtual units from some arbitrary starting point. Virtual units accrue every time a process is running in user-mode. Like the real time counters, these functions always succeed (error-free) since they are guaranteed to exist on every PAPI supported platform. However, the resolution can be as bad as 1/Hz as defined by the operating system on some platforms.

In the following code example, PAPI_get_virt_cyc and PAPI_get_virt_usec are used to obtain the virtual time it takes to create an event set in clock cycles and microseconds, respectively:

#include <papi.h>

main()
{
    long_long start_cycles, end_cycles, start_usec, end_usec;
    int EventSet = PAPI_NULL;

    if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
    exit(1);

    /* Gets the starting time in clock cycles */
    start_cycles = PAPI_get_virt_cyc();

    /* Gets the starting time in microseconds */
    start_usec = PAPI_get_virt_usec();

    /*Create an EventSet */
    if (PAPI_create_eventset(&EventSet) != PAPI_OK)
    exit(1);
    /* Gets the ending time in clock cycles */
    end_cycles = PAPI_get_virt_cyc();

    /* Gets the ending time in microseconds */
    end_usec = PAPI_get_virt_usec();

    printf("Virtual clock cycles: %lld\n", end_cycles - start_cycles);
    prinf("Virtual clock time in microseconds: %lld\n", end_usec - start_usec); 
}

Possible Output

Virtual clock cycles: 715408
Virtual clock time in microseconds: 976

Updated