I have two guesses, but I don't know if they are accurate. Please contact us:
1. The values element seems to have to be 64-bit. In FORTRAN, INTEGER (kind = 8) or INTEGER (8 ).
2. Only two event_codes can be added at a time.
program papitest implicit none#include "f90papi.h" integer, parameter::N = 5000 integer x(N,N),y(N,N),z(N,N) integer check,event_set,event_code integer i, j integer(kind=8) values(4) do j = 1, N do i = 1, N x(i,j) = i + j y(i,j) = i + 1 z(i,j) = 0 enddo enddo do i = 1, 4 values(i) = -1 enddo! print *, values ! initialize the PAPI library check = PAPI_VER_CURRENT call PAPIF_library_init(check) ! create the eventset event_set = PAPI_NULL call PAPIF_create_eventset(event_set, check) event_code = PAPI_L1_DCH ! Total L1 Data Cache hits call PAPIF_add_event(event_set, event_code, check) event_code = PAPI_L1_DCM ! Total L1 Data Cache misses call PAPIF_add_event(event_set, event_code, check)! event_code = PAPI_TLB_DM ! TLB misses! call PAPIF_add_event(event_set, event_code, check) ! start counting call PAPIF_start(event_set, check) do j = 1,N do i = 1,N z(i,j) = x(i,j)+y(i,j) end do end do ! stop counting call PAPIF_stop(event_set, values, check) print *,'L1 cache hits:',values(1) print *,'L1 cache misses:',values(2) print *,'L1 cache hit rates:', & values(1) *100 / (values(1) + values(2)) ! reset the PAPI counters call PAPIF_reset(event_set, check) call PAPIF_shutdown end
[root@c0106 simple]# gfortran hello.F -o hello -lpapi[root@c0106 simple]# ./hello L1 cache hits: 331640400 L1 cache misses: 4697189 L1 cache hit rates: 98[root@c0106 simple]#