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

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

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


 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值