Have u ever used PAPI?
Because PAPI support the kernel version >2.6.32(perf-events), I choose it to test my code.
Why I only get the same number(result) no matter what event-code I chose,such as PAPI_TOT_INS,PAPI_BR_INS,etc..
#include <stdio.h>
#include "papi.h"
int main(){
int i,j,k;
int a[300][300];
int b[300][300];
int c[300][300];
for(i=0;i<300;i++){
for(j=0;j<300;j++){
a[i][j]=1;
b[i][j]=2;
c[i][j]=0;
}
}
int Events[1]={PAPI_TOT_INS};//={PAPI_BR_INS,PAPI_BR_MSP};
long_long values[1];//values[0]=0;
PAPI_start_counters(Events,1);
for(i=0;i<300;i++){
for(j=0;j<300;j++){
for(k=0;k<300;k++){
c[i][j]+=a[i][k]*b[k][j];
}
}
}
printf("r is %d\n",c[0][0]);
PAPI_read_counters(values,1);
printf("events is %lld\n",values[0]);
for(i=0;i<300;i++){
for(j=0;j<300;j++){
for(k=0;k<300;k++){
a[i][j]+=b[i][k]*c[k][j];
}
}
}
PAPI_accum_counters(values,1);
printf("events is %lld\n",values[0]);
for(i=0;i<300;i++){
for(j=0;j<300;j++){
for(k=0;k<300;k++){
a[i][j]+=b[i][k]*c[k][j];
}
}
}
PAPI_stop_counters(values,1);
printf("events is %lld\n",values[0]);
return 0;
}
My thinking:
1.My pc(uname -a): Linux xunzhang-virtual-machine 2.6.35-28-generic #49-Ubuntu SMP Tue Mar ... X86_64 GNU/Linux
how can I(command) see my kernel's support of perf-events? I just use the default conclusion that >2.6.32....
2.I just use my virtual machine in my MAC, does this effect??..
Say something to guide/help me. Thanks!!
AFAIK, High level PAPI calls do not call foe explicit initialization. I have the same problem as you have. If you've solved it, can you please let me know how?