用PAPI测试高速缓存命中率和TLB缺失率

来源:互联网 发布:安卓换字体软件 编辑:程序博客网 时间:2024/05/17 20:29

我的两个猜测,不知是否准确,欢迎交流:

1、values中元素好像必须是64位的,FORTRAN中integer(kind=8)或integer(8).

2、一次只能添加两个event_code,多了无效.

 

 

        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]#