Blame src/examples/PAPI_flips.c

Packit 577717
/*****************************************************************************
Packit 577717
 * This example demonstrates the usage of the high level function PAPI_flips *
Packit 577717
 * which measures the number of floating point instructions executed and the *
Packit 577717
 * MegaFlop rate(defined as the number of floating point instructions per    *
Packit 577717
 * microsecond). To use PAPI_flips you need to have floating point           *
Packit 577717
 * instructions event supported by the platform.                             * 
Packit 577717
 *****************************************************************************/
Packit 577717
Packit 577717
/*****************************************************************************
Packit 577717
 * The first call to PAPI_flips initializes the PAPI library, set up the     *
Packit 577717
 * counters to monitor PAPI_FP_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 floating point instructions, and the      *
Packit 577717
 * Mflins/s rate since the last call to PAPI_flips.                          *
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,mflips;
Packit 577717
  long long flpins;
Packit 577717
  float ireal_time, iproc_time, imflips;
Packit 577717
  long long iflpins;
Packit 577717
  int retval;
Packit 577717
Packit 577717
  /***********************************************************************
Packit 577717
   * if PAPI_FP_INS is a derived event in your platform, then your       * 
Packit 577717
   * platform must have at least three counters to support PAPI_flips,   *
Packit 577717
   * because PAPI needs one counter to cycles. So in UltraSparcIII, even *
Packit 577717
   * the platform supports PAPI_FP_INS, but UltraSparcIII only have two  *
Packit 577717
   * available hardware counters and PAPI_FP_INS is a derived event in   *
Packit 577717
   * this platform, so PAPI_flops returns an error.                      *
Packit 577717
   ***********************************************************************/
Packit 577717
Packit 577717
  if((retval=PAPI_flips(&ireal_time,&iproc_time,&iflpins,&imflips)) < PAPI_OK)
Packit 577717
  { 
Packit 577717
    printf("Could not initialise PAPI_flips \n");
Packit 577717
    printf("Your platform may not support floating point instruction event.\n");    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_flips( &real_time, &proc_time, &flpins, &mflips))
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 flpins: %lld MFLIPS: %f\n", 
Packit 577717
         real_time, proc_time,flpins,mflips);
Packit 577717
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