- Code: Select all
#include <stdio.h>
#include <papi.h>
using namespace std;
int
papi_print_header( char *prompt, const PAPI_hw_info_t ** hwinfo )
{
if ( ( *hwinfo = PAPI_get_hardware_info( ) ) == NULL )
return ( PAPI_ESBSTR );
printf( "%s", prompt );
printf
( "--------------------------------------------------------------------------------\n" );
printf( "PAPI Version : %d.%d.%d.%d\n",
PAPI_VERSION_MAJOR( PAPI_VERSION ),
PAPI_VERSION_MINOR( PAPI_VERSION ),
PAPI_VERSION_REVISION( PAPI_VERSION ),
PAPI_VERSION_INCREMENT( PAPI_VERSION ) );
printf( "Vendor string and code : %s (%d)\n", ( *hwinfo )->vendor_string,
( *hwinfo )->vendor );
printf( "Model string and code : %s (%d)\n", ( *hwinfo )->model_string,
( *hwinfo )->model );
printf( "CPU Revision : %f\n", ( *hwinfo )->revision );
if ( ( *hwinfo )->cpuid_family > 0 )
printf
( "CPUID Info : Family: %d Model: %d Stepping: %d\n",
( *hwinfo )->cpuid_family, ( *hwinfo )->cpuid_model,
( *hwinfo )->cpuid_stepping );
printf( "CPU Megahertz : %f\n", ( *hwinfo )->mhz );
printf( "CPU Clock Megahertz : %d\n", ( *hwinfo )->clock_mhz );
if ( ( *hwinfo )->threads > 0 )
printf( "Hdw Threads per core : %d\n", ( *hwinfo )->threads );
if ( ( *hwinfo )->cores > 0 )
printf( "Cores per Socket : %d\n", ( *hwinfo )->cores );
if ( ( *hwinfo )->sockets > 0 )
printf( "Sockets : %d\n", ( *hwinfo )->sockets );
if ( ( *hwinfo )->nnodes > 0 )
printf( "NUMA Nodes : %d\n", ( *hwinfo )->nnodes );
printf( "CPUs per Node : %d\n", ( *hwinfo )->ncpu );
printf( "Total CPUs : %d\n", ( *hwinfo )->totalcpus );
printf( "Number Hardware Counters : %d\n",
PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ) );
printf( "Max Multiplex Counters : %d\n",
PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ) );
printf
( "--------------------------------------------------------------------------------\n" );
printf( "\n" );
return PAPI_OK;
}
void
validate_string( char *name, char *s )
{
if ( ( s == NULL ) || ( strlen( s ) == 0 ) ) {
char s2[1024] = "";
sprintf( s2, "%s was NULL or length 0", name );
cerr << "Failed at line " << __LINE__ << endl;
}
}
And added this simple main:
- Code: Select all
int main(int argc, char** argv)
{
int retval, i, j;
const PAPI_hw_info_t *hwinfo = NULL;
const PAPI_mh_info_t *mh;
retval = PAPI_library_init( PAPI_VER_CURRENT );
if ( retval != PAPI_VER_CURRENT )
cerr << "Failed at line " << __LINE__ << endl;
retval =
papi_print_header
( "Test case hwinfo.c: Check output of PAPI_get_hardware_info.\n",
&hwinfo );
if ( retval != PAPI_OK )
cerr << "Failed at line " << __LINE__ << endl;
}
I build it as follows:
- Code: Select all
g++ main.cpp -I /home/pchan/rabbit/papi/include /home/avelazqu/rabbit/papi/lib/libpapi.a
and when I run it, I get the following output:
- Code: Select all
Test case hwinfo.c: Check output of PAPI_get_hardware_info.
--------------------------------------------------------------------------------
PAPI Version : 4.4.0.0
Vendor string and code : (0)
Model string and code : (0)
CPU Revision : 0.000000
CPU Megahertz : 0.000000
CPU Clock Megahertz : 0
CPUs per Node : 0
Total CPUs : 0
Number Hardware Counters : 0
Max Multiplex Counters : 0
--------------------------------------------------------------------------------
I'm confused as to why it seems this is not working and how to get PAPI working on my system.
