Blame src/examples/PAPI_hw_info.c

Packit 577717
/****************************************************************************
Packit 577717
 * This is a simple low level example for getting information on the system *
Packit 577717
 * hardware. This function PAPI_get_hardware_info(), returns a pointer to a *
Packit 577717
 * structure of type PAPI_hw_info_t, which contains number of CPUs, nodes,  *
Packit 577717
 * vendor number/name for CPU, CPU revision, clock speed.                   *
Packit 577717
 ****************************************************************************/
Packit 577717
Packit 577717
#include <stdio.h>
Packit 577717
#include <stdlib.h>
Packit 577717
#include "papi.h" /* This needs to be included every time you use PAPI */
Packit 577717
Packit 577717
int main()
Packit 577717
{
Packit 577717
   const PAPI_hw_info_t *hwinfo = NULL;
Packit 577717
   int retval;
Packit 577717
  
Packit 577717
   /*************************************************************************** 
Packit 577717
   *  This part initializes the library and compares the version number of the*
Packit 577717
   * header file, to the version of the library, if these don't match then it *
Packit 577717
   * is likely that PAPI won't work correctly.If there is an error, retval    *
Packit 577717
   * keeps track of the version number.                                       *
Packit 577717
   ***************************************************************************/
Packit 577717
Packit 577717
Packit 577717
   if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT )
Packit 577717
   {
Packit 577717
      printf("Library initialization error! \n");
Packit 577717
      exit(1);
Packit 577717
   }
Packit 577717
     
Packit 577717
   /* Get hardware info*/      
Packit 577717
   if ((hwinfo = PAPI_get_hardware_info()) == NULL)
Packit 577717
   {
Packit 577717
      printf("PAPI_get_hardware_info error! \n");
Packit 577717
      exit(1);
Packit 577717
   }
Packit 577717
   /* when there is an error, PAPI_get_hardware_info returns NULL */
Packit 577717
Packit 577717
Packit 577717
   printf("%d CPU  at %f Mhz.\n",hwinfo->totalcpus,hwinfo->mhz);
Packit 577717
   printf(" model string is %s \n", hwinfo->model_string);
Packit 577717
Packit 577717
   /* clean up */ 
Packit 577717
   PAPI_shutdown();
Packit 577717
Packit 577717
   exit(0);
Packit 577717
Packit 577717
}
Packit 577717