|
Packit |
577717 |
/*****************************************************************************
|
|
Packit |
577717 |
* This example demonstrates the usage of the high level function PAPI_ipc *
|
|
Packit |
577717 |
* which measures the number of instructions executed per cpu cycle *
|
|
Packit |
577717 |
*****************************************************************************/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*****************************************************************************
|
|
Packit |
577717 |
* The first call to PAPI_ipc initializes the PAPI library, set up the *
|
|
Packit |
577717 |
* counters to monitor PAPI_TOT_INS and PAPI_TOT_CYC events, and start the *
|
|
Packit |
577717 |
* counters. Subsequent calls will read the counters and return total real *
|
|
Packit |
577717 |
* time, total process time, total instructions, and the instructions per *
|
|
Packit |
577717 |
* cycle rate since the last call to PAPI_ipc. *
|
|
Packit |
577717 |
*****************************************************************************/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
#include "papi.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
main()
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
float real_time, proc_time,ipc;
|
|
Packit |
577717 |
long long ins;
|
|
Packit |
577717 |
float real_time_i, proc_time_i, ipc_i;
|
|
Packit |
577717 |
long long ins_i;
|
|
Packit |
577717 |
int retval;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if((retval=PAPI_ipc(&real_time_i,&proc_time_i,&ins_i,&ipc_i)) < PAPI_OK)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
printf("Could not initialise PAPI_ipc \n");
|
|
Packit |
577717 |
printf("retval: %d\n", retval);
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
your_slow_code();
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if((retval=PAPI_ipc( &real_time, &proc_time, &ins, &ipc))
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
printf("retval: %d\n", retval);
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
printf("Real_time: %f Proc_time: %f Total instructions: %lld IPC: %f\n",
|
|
Packit |
577717 |
real_time, proc_time,ins,ipc);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* clean up */
|
|
Packit |
577717 |
PAPI_shutdown();
|
|
Packit |
577717 |
exit(0);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int your_slow_code()
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
int i;
|
|
Packit |
577717 |
double tmp=1.1;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
for(i=1; i<2000; i++)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
tmp=(tmp+100)/i;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|