I am trying to learn papi api to monitor the performance of various CPU events. To begin with, I ran one of the sample snippets that PAPI official documentation mentions. Below is the code
#include<stdio.h>
#include <unistd.h>
#include "papi.h"
#define NUM_EVENTS 2
int main()
{
int Events[NUM_EVENTS] = {PAPI_TOT_INS, PAPI_TOT_CYC};
int num1=1234;
int num2=9876;
int res1,res2;
long_long values[NUM_EVENTS];
/* Start counting events */
if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK)
printf("\nerror!!!\n");
//handle_error(1);
/* Do some computation here*/
res1=num1*num2;
printf("\n%d",res1);
/* Read the counters */
if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
printf("\nerror!!!\n");
/* Do some computation here */
res2=num1+num2;
printf("\n%d",res2);
/* Stop counting events */
if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK)
printf("\nerror!!!\n");
return 0;
}
I compiled it with the include files path as below
gcc -I/home/sabarna/Desktop/DEV/clockCycle/papi/src/ papi_try1.c -L/home/sabarna/Desktop/DEV/clockCycle/papi/src/ -lpapi
While executing a.out I am getting the error
/a.out: error while loading shared libraries: libpapi.so.5: cannot open shared object file: No such file or directory
I tried fixing this by exporting LD_PRELOAD but that didn't work. Could anyone please help me out? I have never used PAPI api before, so I am not sure whether I am compiling it in the right way.
There is no reason to pre-load that library, try defining/modifying LD_LIBRARY_PATH rather than LD_PRELOAD
-L/home/sabarna/Desktop/DEV/clockCycle/papi/src/
seems to indicate you compiled but do not installed it
if you set LD_xxx with /home/sabarna/Desktop/DEV/clockCycle/papi/src/
that means the lib must be in the directory /home/sabarna/Desktop/DEV/clockCycle/papi/src/
not elsewhere, so /home/sabarna/Desktop/DEV/clockCycle/papi/src/libpapy.so
and/or /home/sabarna/Desktop/DEV/clockCycle/papi/src/libpapy.so.<number>
exist