This version (2022/06/20 09:01) was approved by msiegel.

This is an old revision of the document!


#include <stdio.h>
#include <stdlib.h>
#include "papi.h"

main()
{
   // PAPI variables
   // best is to analyze one particular event at a time
   int eventset;
   long long value, time0, time1, cyc0, cyc1;
       
   // PAPI Initialization
   eventset = PAPI_NULL;
   if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) {
      printf("PAPI init error !\n");
      exit(993);
   }
   // PAPI Event Set Creation
   if (PAPI_create_eventset(&eventset) != PAPI_OK) {
      printf("PAPI event set creation error !\n");
      exit(994);
   }
   // PAPI Specify a Particular Target Event to Analyze
   //   PAPI_TOT_CYC         Total cycles executed
   //   PAPI_FP_OPS          Floating point operations executed
   //   PAPI_L1_DCM          Level 1 data cache misses
   //   PAPI_L2_DCM          Level 2 data cache misses
   //   for other events see /opt/sw/x86_64/glibc-2.12/ivybridge-ep/papi/5.4.3/gnu-4.4.7/include/papiStdEventDefs.h
   //
   if (PAPI_add_event(eventset, PAPI_FP_OPS) != PAPI_OK) {
      printf("PAPI event set adding error !\n");
      exit(995);
   }
   // PAPI Time Estimators Initialization
   time0 = PAPI_get_real_usec();
   cyc0 = PAPI_get_real_cyc();
   // PAPI Counting Start
   if (PAPI_start(eventset) != PAPI_OK) {
      printf("PAPI start error !\n");
      exit(996);
   }
   
   //*** Here follows the original code section to be analyzed ***
   
   // PAPI Counting Stop
   if (PAPI_stop(eventset, &value) != PAPI_OK) {
      printf("PAPI stop error !\n");
      exit(997);
   }
   // PAPI Time Estimators Stop
   time1 = PAPI_get_real_usec();
   cyc1 = PAPI_get_real_cyc();
   // PAPI Results
   printf("PAPI event count %lld\n", value);
   printf("PAPI time passed in usec %lld\n", time1 - time0);
   printf("PAPI cycles passed %lld\n", cyc1 - cyc0);
   // PAPI Free Event Set
   if (PAPI_cleanup_eventset(eventset) != PAPI_OK) {
      printf("PAPI event set cleanup error !\n");
      exit(998);
   }
   if (PAPI_destroy_eventset(&eventset) != PAPI_OK) {
      printf("PAPI event set destruction error !\n");
      exit(999);
   }
   // PAPI Finalize
   PAPI_shutdown();
 }
  • doku/papi_ll_c.1467723834.txt.gz
  • Last modified: 2024/10/24 10:21
  • (external edit)