|
PAPI
5.0.1.0
|
00001 /***************************************************************************** 00002 * This example demonstrates the usage of the high level function PAPI_flops * 00003 * which measures the number of floating point operations executed and the * 00004 * MegaFlop rate(defined as the number of floating point operations per * 00005 * microsecond). To use PAPI_flops you need to have floating point operations* 00006 * event supported by the platform. * 00007 *****************************************************************************/ 00008 00009 /***************************************************************************** 00010 * The first call to PAPI_flops initializes the PAPI library, set up the * 00011 * counters to monitor PAPI_FP_OPS 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 operations, and the * 00014 * Mflops/s rate since the last call to PAPI_flops. * 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,mflops; 00026 long long flpops; 00027 float ireal_time, iproc_time, imflops; 00028 long long iflpops; 00029 int retval; 00030 00031 /*********************************************************************** 00032 * if PAPI_FP_OPS is a derived event in your platform, then your * 00033 * platform must have at least three counters to support PAPI_flops, * 00034 * because PAPI needs one counter to cycles. So in UltraSparcIII, even * 00035 * the platform supports PAPI_FP_OPS, but UltraSparcIII only has two * 00036 * available hardware counters and PAPI_FP_OPS is a derived event in * 00037 * this platform, so PAPI_flops returns an error. * 00038 ***********************************************************************/ 00039 if((retval=PAPI_flops(&ireal_time,&iproc_time,&iflpops,&imflops)) < PAPI_OK) 00040 { 00041 printf("Could not initialise PAPI_flops \n"); 00042 printf("Your platform may not support floating point operation event.\n"); 00043 printf("retval: %d\n", retval); 00044 exit(1); 00045 } 00046 00047 your_slow_code(); 00048 00049 00050 if((retval=PAPI_flops( &real_time, &proc_time, &flpops, &mflops))<PAPI_OK) 00051 { 00052 printf("retval: %d\n", retval); 00053 exit(1); 00054 } 00055 00056 00057 printf("Real_time: %f Proc_time: %f Total flpops: %lld MFLOPS: %f\n", 00058 real_time, proc_time,flpops,mflops); 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