|
PAPI
5.0.1.0
|
00001 /***************************************************************************** 00002 * This example demonstrates the usage of the high level function PAPI_flips * 00003 * which measures the number of floating point instructions executed and the * 00004 * MegaFlop rate(defined as the number of floating point instructions per * 00005 * microsecond). To use PAPI_flips you need to have floating point * 00006 * instructions event supported by the platform. * 00007 *****************************************************************************/ 00008 00009 /***************************************************************************** 00010 * The first call to PAPI_flips initializes the PAPI library, set up the * 00011 * counters to monitor PAPI_FP_INS and PAPI_TOT_CYC events, and start the * 00012 * counters. Subsequent calls will read the counters and return total real * 00013 * time, total process time, total floating point instructions, and the * 00014 * Mflins/s rate since the last call to PAPI_flips. * 00015 *****************************************************************************/ 00016 00017 00018 #include <stdio.h> 00019 #include <stdlib.h> 00020 #include "papi.h" 00021 00022 00023 main() 00024 { 00025 float real_time, proc_time,mflips; 00026 long long flpins; 00027 float ireal_time, iproc_time, imflips; 00028 long long iflpins; 00029 int retval; 00030 00031 /*********************************************************************** 00032 * if PAPI_FP_INS is a derived event in your platform, then your * 00033 * platform must have at least three counters to support PAPI_flips, * 00034 * because PAPI needs one counter to cycles. So in UltraSparcIII, even * 00035 * the platform supports PAPI_FP_INS, but UltraSparcIII only have two * 00036 * available hardware counters and PAPI_FP_INS is a derived event in * 00037 * this platform, so PAPI_flops returns an error. * 00038 ***********************************************************************/ 00039 00040 if((retval=PAPI_flips(&ireal_time,&iproc_time,&iflpins,&imflips)) < PAPI_OK) 00041 { 00042 printf("Could not initialise PAPI_flips \n"); 00043 printf("Your platform may not support floating point instruction event.\n"); printf("retval: %d\n", retval); 00044 exit(1); 00045 } 00046 00047 your_slow_code(); 00048 00049 00050 if((retval=PAPI_flips( &real_time, &proc_time, &flpins, &mflips))<PAPI_OK) 00051 { 00052 printf("retval: %d\n", retval); 00053 exit(1); 00054 } 00055 00056 00057 printf("Real_time: %f Proc_time: %f Total flpins: %lld MFLIPS: %f\n", 00058 real_time, proc_time,flpins,mflips); 00059 00060 exit(0); 00061 } 00062 00063 int your_slow_code() 00064 { 00065 int i; 00066 double tmp=1.1; 00067 00068 for(i=1; i<2000; i++) 00069 { 00070 tmp=(tmp+100)/i; 00071 } 00072 return 0; 00073 } 00074