Example #1
0
int
main( int argc, char **argv )
{
	int i;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

// 	if ( ( retval =
// 		   PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
// 		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );


	printf( "\n----------------------------------\n" );
	printf( "For 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( "There are %d error codes defined\n", PAPI_NUM_ERRORS );
	printf( "----------------------------------\n" );
	for (i = 0; i < PAPI_NUM_ERRORS; i++) {
		char *errstr, *errdescr;
		errstr = PAPI_strerror( -i );
		errdescr = PAPI_descr_error( -i );
		printf( "Error code %4d: %-15s | %s\n", -i, errstr, errdescr );
	}
	printf( "----------------------------------\n\n" );
	exit( 1 );
}
int main(int argc, char **argv)
{
   int retval;
   long long elapsed_us, elapsed_cyc;
   const PAPI_hw_info_t *hw_info;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   hw_info = PAPI_get_hardware_info();
   if (hw_info == NULL)
     test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

   elapsed_us = PAPI_get_real_usec();

   elapsed_cyc = PAPI_get_real_cyc();

   printf("Testing real time clock. (CLOCK %d MHz, CPU %f MHz)\n",hw_info->clock_mhz,hw_info->mhz);
   printf("Sleeping for 10 seconds.\n");

   sleep(10);

   elapsed_us = PAPI_get_real_usec() - elapsed_us;

   elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;

   printf("%lld us. %lld cyc.\n",elapsed_us,elapsed_cyc);
   printf("%f Computed MHz.\n",(float)elapsed_cyc/(float)elapsed_us);

/* Elapsed microseconds and elapsed cycles are not as unambiguous as they appear.
   On Pentium III and 4, for example, cycles is a measured value, while useconds 
   is computed from cycles and mhz. MHz is read from /proc/cpuinfo (on linux).
   Thus, any error in MHz is propagated to useconds.
   Conversely, on ultrasparc useconds are extracted from a system call (gethrtime())
   and cycles are computed from useconds. Also, MHz comes from a scan of system info,
   Thus any error in gethrtime() propagates to both cycles and useconds, and cycles
   can be further impacted by errors in reported MHz.
   Without knowing the error bars on these system values, we can't really specify
   error ranges for our reported values, but we *DO* know that errors for at least
   one instance of Pentium 4 (torc17@utk) are on the order of one part per thousand.
   Newer multicore Intel processors seem to have broken the relationship between the
   clock rate reported in /proc/cpuinfo and the actual computed clock. To accomodate
   this artifact, the test no longer fails, but merely reports results out of range.
*/

   if (elapsed_us < 9000000)
	   printf("NOTE: Elapsed real time less than 9 seconds!\n");
   if (elapsed_us > 11000000)
     printf("NOTE: Elapsed real time greater than 11 seconds!\n");
   if ((float)elapsed_cyc < 9.0 * hw_info->mhz * 1000000.0) 
     printf("NOTE: Elapsed real cycles less than 9*MHz*1000000.0!\n");
   if ((float)elapsed_cyc > 11.0 * hw_info->mhz * 1000000.0) 
     printf("NOTE: Elapsed real cycles greater than 11*MHz*1000000.0!\n");
   
   test_pass(__FILE__, NULL, 0);
   exit(1);
}
int
main( int argc, char **argv )
{
	int i, rc, retval;
	pthread_t id[NUM_THREADS];
	pthread_attr_t attr;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	printf( "%s: Using %d threads\n\n", argv[0], NUM_THREADS );
	printf
		( "Does non-threaded overflow work with extraneous threads present?\n" );

	pthread_attr_init( &attr );
#ifdef PTHREAD_CREATE_UNDETACHED
	pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
#endif
#ifdef PTHREAD_SCOPE_SYSTEM
	retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
	if ( retval != 0 )
		test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
#endif

	for ( i = 0; i < NUM_THREADS; i++ ) {
		rc = pthread_create( &id[i], &attr, thread_fn, NULL );
		if ( rc )
			test_fail( __FILE__, __LINE__, "pthread_create", rc );
	}
	pthread_attr_destroy( &attr );

	mainloop( NUM_ITERS );

	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
Example #4
0
int
main( int argc, char **argv )
{
	int retval;
	int status;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "main PAPI_library_init", retval );

	if ( fork(  ) == 0 ) {
		retval = PAPI_library_init( PAPI_VER_CURRENT );
		if ( retval != PAPI_VER_CURRENT )
			test_fail( __FILE__, __LINE__, "forked PAPI_library_init", retval );
		exit( 0 );
	} else {
		wait( &status );
		if ( WEXITSTATUS( status ) != 0 )
			test_fail( __FILE__, __LINE__, "fork", WEXITSTATUS( status ) );
	}

	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
Example #5
0
void
papi_init( int argc, char **argv )
{
	const PAPI_hw_info_t *hwinfo = NULL;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */
	/*for(i=0;i<argc;i++) */

	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	retval = PAPI_set_debug( PAPI_VERB_ECONT );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );

	retval =
		papi_print_header
		( "Event Chooser: Available events which can be added with given events.\n",
		  0, &hwinfo );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );

	retval = PAPI_create_eventset( &EventSet );
	if ( retval != PAPI_OK ) {
		fprintf( stderr, "PAPI_create_eventset error\n" );
		exit( 1 );
	}
}
int main(int argc, char **argv)
{
   int retval;
   int preset;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   retval = PAPI_event_name_to_code("PAPI_FP_INS", &preset);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_event_name_to_code", retval);
   if (preset != PAPI_FP_INS)
      test_fail(__FILE__, __LINE__, "Wrong preset returned", retval);

   retval = PAPI_event_name_to_code("PAPI_TOT_CYC", &preset);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_event_name_to_code", retval);
   if (preset != PAPI_TOT_CYC)
      test_fail(__FILE__, __LINE__, "*preset returned did not equal PAPI_TOT_CYC",
                retval);

   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Example #7
0
int
main( int argc, char **argv )
{
	int retval;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	if ( ( argc > 1 ) && ( strcmp( argv[1], "xxx" ) == 0 ) ) {
		retval = PAPI_library_init( PAPI_VER_CURRENT );
		if ( retval != PAPI_VER_CURRENT )
			test_fail( __FILE__, __LINE__, "execed PAPI_library_init", retval );
	} else {
		retval = PAPI_library_init( PAPI_VER_CURRENT );
		if ( retval != PAPI_VER_CURRENT )
			test_fail( __FILE__, __LINE__, "main PAPI_library_init", retval );

		PAPI_shutdown(  );

		if ( execlp( argv[0], argv[0], "xxx", NULL ) == -1 )
			test_fail( __FILE__, __LINE__, "execlp", PAPI_ESYS );
	}

	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
int main(int argc, char **argv)
{
   int retval;

   const PAPI_component_info_t *cmpinfo;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   if ((cmpinfo = PAPI_get_component_info(0)) == NULL) 
     test_fail(__FILE__, __LINE__, "PAPI_get_component_info", retval);

   printf("name: %s\n",cmpinfo->name);
   printf("substrate_version: %s\n",cmpinfo->version);
   printf("support_version: %s\n",cmpinfo->support_version);
   printf("kernel_version: %s\n",cmpinfo->kernel_version);
   printf("num_cntrs: %d\n",cmpinfo->num_cntrs);
   printf("num_mpx_cntrs: %d\n",cmpinfo->num_mpx_cntrs);
   printf("num_preset_events: %d\n",cmpinfo->num_preset_events);           /* Number of counters the substrate supports */
   printf("num_native_events: %d\n",cmpinfo->num_native_events);           /* Number of counters the substrate supports */
   printf("default_domain: 0x%x (%s)\n",cmpinfo->default_domain,stringify_all_domains(cmpinfo->default_domain));
   printf("available_domains: 0x%x (%s)\n",cmpinfo->available_domains,stringify_all_domains(cmpinfo->available_domains));       /* Available domains */ 
   printf("default_granularity: 0x%x (%s)\n",cmpinfo->default_granularity,stringify_granularity(cmpinfo->default_granularity));
   /* The default granularity when this substrate is used */
   printf("available_granularities: 0x%x (%s)\n",cmpinfo->available_granularities,stringify_all_granularities(cmpinfo->available_granularities)); /* Available granularities */
   printf("itimer_sig: %d\n",cmpinfo->itimer_sig);     
   printf("itimer_num: %d\n",cmpinfo->itimer_num);     
   printf("itimer_ns: %d\n",cmpinfo->itimer_ns);      
   printf("itimer_res_ns: %d\n",cmpinfo->itimer_res_ns); 
   printf("hardware_intr_sig: %d\n",cmpinfo->hardware_intr_sig);      /* Width of opcode matcher if exists, 0 if not */
   printf("clock_ticks: %d\n",cmpinfo->clock_ticks);      
   printf("opcode_match_width: %d\n",cmpinfo->opcode_match_width);      /* Width of opcode matcher if exists, 0 if not */
/*   printf("reserved_ints[4]: %d\n",cmpinfo->reserved_ints[4]); */
   printf("hardware_intr: %d\n",cmpinfo->hardware_intr);         /* Needs hw overflow intr to be emulated in software*/
   printf("precise_intr: %d\n",cmpinfo->precise_intr);          /* Performance interrupts happen precisely */
   printf("posix1b_timers: %d\n",cmpinfo->posix1b_timers);          /* Performance interrupts happen precisely */
   printf("kernel_profile: %d\n",cmpinfo->kernel_profile);        /* Needs kernel profile support (buffered interrupts) to be emulated */
   printf("kernel_multiplex: %d\n",cmpinfo->kernel_multiplex);      /* In kernel multiplexing */
   printf("data_address_range: %d\n",cmpinfo->data_address_range);    /* Supports data address range limiting */
   printf("instr_address_range: %d\n",cmpinfo->instr_address_range);   /* Supports instruction address range limiting */
   printf("fast_counter_read: %d\n",cmpinfo->fast_counter_read);       /* Has a fast counter read */
   printf("fast_real_timer: %d\n",cmpinfo->fast_real_timer);       /* Has a fast real timer */
   printf("fast_virtual_timer: %d\n",cmpinfo->fast_virtual_timer);    /* Has a fast virtual timer */
   printf("attach: %d\n",cmpinfo->attach);    /* Has a fast virtual timer */
   printf("attach_must_ptrace: %d\n",cmpinfo->attach_must_ptrace);    /* Has a fast virtual timer */
   printf("edge_detect: %d\n",cmpinfo->edge_detect);    /* Has a fast virtual timer */
   printf("invert: %d\n",cmpinfo->invert);    /* Has a fast virtual timer */
   printf("profile_ear: %d\n",cmpinfo->profile_ear);     /* Supports data/instr/tlb miss address sampling */
   printf("cntr_groups: %d\n",cmpinfo->cntr_groups);           /* Underlying hardware uses counter groups */
   printf("cntr_umasks: %d\n",cmpinfo->cntr_umasks);           /* counters have unit masks */
   printf("cntr_IEAR_events: %d\n",cmpinfo->cntr_IEAR_events);      /* counters support instr event addr register */
   printf("cntr_DEAR_events: %d\n",cmpinfo->cntr_DEAR_events);      /* counters support data event addr register */
   printf("cntr_OPCM_events: %d\n",cmpinfo->cntr_OPCM_events);      /* counter events support opcode matching */

   test_pass(__FILE__, NULL, 0);
   exit(0);
}
int main(int argc, char **argv)
{
   int i, retval;
   long long elapsed_us, elapsed_cyc;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   hw_info = PAPI_get_hardware_info();
   if (hw_info == NULL)
     test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

   elapsed_us = PAPI_get_real_usec();

   elapsed_cyc = PAPI_get_real_cyc();

#if defined(_AIX)
   retval = PAPI_thread_init((unsigned long (*)(void)) (pthread_self));
   if (retval != PAPI_OK) {
      if (retval == PAPI_ESBSTR)
         test_skip(__FILE__, __LINE__, "PAPI_thread_init", retval);
      else
         test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval);
   }
#pragma ibm parallel_loop
#elif defined(sgi) && defined(mips)
   retval = PAPI_thread_init((unsigned long (*)(void)) (mp_my_threadnum));
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval);
   }
#pragma parallel
#pragma local(i)
#pragma pfor
#elif defined(sun) && defined(sparc)
   retval = PAPI_thread_init((unsigned long (*)(void)) (thr_self));
   if (retval != PAPI_OK) {
      test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval);
   }
#pragma MP taskloop private(i)
#else
#error "Architecture not included in this test file yet."
#endif
   for (i = 1; i < 3; i++)
      Thread(i, 10000000 * i);

   elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;

   elapsed_us = PAPI_get_real_usec() - elapsed_us;

   if (!TESTS_QUIET) {
      printf("Master real usec   : \t%lld\n", elapsed_us);
      printf("Master real cycles : \t%lld\n", elapsed_cyc);
   }
   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Example #10
0
int
main( int argc, char **argv )
{
	extern void dummy( void * );
	float matrixa[INDEX][INDEX], matrixb[INDEX][INDEX], mresult[INDEX][INDEX];
	float real_time, proc_time, ipc;
	long long ins;
	int retval;
	int i, j, k;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */


	/* Initialize the Matrix arrays */
	for( i = 0; i < INDEX; i++ ) {
	   for( j= 0; j < INDEX; j++ ) {
	       mresult[i][j] = 0.0;
	       matrixa[i][j] = matrixb[i][j] = ( float ) rand(  ) * ( float ) 1.1;
	   }
	}

	/* Setup PAPI library and begin collecting data from the counters */
	if ( ( retval = PAPI_ipc( &real_time, &proc_time, &ins, &ipc ) ) < PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_ipc", retval );

	/* Matrix-Matrix multiply */
	for ( i = 0; i < INDEX; i++ )
		for ( j = 0; j < INDEX; j++ )
			for ( k = 0; k < INDEX; k++ )
				mresult[i][j] = mresult[i][j] + matrixa[i][k] * matrixb[k][j];

	/* Collect the data into the variables passed in */
	if ( ( retval = PAPI_ipc( &real_time, &proc_time, &ins, &ipc ) ) < PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_ipc", retval );
	dummy( ( void * ) mresult );

	if ( !TESTS_QUIET ) {
		printf( "Real_time: %f Proc_time: %f Total ins: ", real_time,
				proc_time );
		printf( LLDFMT, ins );
		printf( " IPC: %f\n", ipc );
	}
   
           /* This should not happen unless the optimizer */
           /* gets too good                               */
        if (ins < INDEX*INDEX) {
	   test_fail( __FILE__, __LINE__, "Instruction count too low.", 
		      5 );
	}
           /* Something is broken, or else you have a really */
           /* slow processor                                 */
        if (ipc<0.01 ) {
	   test_fail( __FILE__, __LINE__, "IPC equals zero.", 
		      5 );
	}
   
	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
int main(int argc, char** argv) {
  int Events[NUM_EVENTS]; 
  const char* names[NUM_EVENTS] = {"OPEN_CALLS", "OPEN_FDS", "READ_CALLS", "READ_BYTES", "READ_USEC", "READ_ERR", "READ_INTERRUPTED", "READ_WOULD_BLOCK", "WRITE_CALLS","WRITE_BYTES","WRITE_USEC", "WRITE_WOULD_BLOCK"};
  long long values[NUM_EVENTS];

  /* Set TESTS_QUIET variable */
  tests_quiet( argc, argv );

  int version = PAPI_library_init (PAPI_VER_CURRENT);
  if (version != PAPI_VER_CURRENT) {
    fprintf(stderr, "PAPI_library_init version mismatch\n");
    exit(1);
  }

  if (!TESTS_QUIET) fprintf(stderr, "This program will read from stdin and echo it to stdout\n");
  int retval;
  int e;
  for (e=0; e<NUM_EVENTS; e++) {
    retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
    if (retval != PAPI_OK) {
      fprintf(stderr, "Error getting code for %s\n", names[e]);
      exit(2);
    } 
  }

  /* Start counting events */
  if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
    fprintf(stderr, "Error in PAPI_start_counters\n");
    exit(1);
  }

  int bytes = 0;
  char buf[1024];

 
//if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
//   handle_error(1);
//printf("After reading the counters: %lld\n",values[0]);

  while ((bytes = read(0, buf, 1024)) > 0) {
    write(1, buf, bytes);
  }


  /* Stop counting events */
  if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) {
    fprintf(stderr, "Error in PAPI_stop_counters\n");
  }
 
  if (!TESTS_QUIET) { 
    printf("----\n");
    for (e=0; e<NUM_EVENTS; e++)  
      printf("%s: %lld\n", names[e], values[e]);
  }
  test_pass( __FILE__, NULL, 0 );
  return 0;
}
Example #12
0
int
main( int argc, char **argv )
{
  double c, a = 0.999, b = 1.001;
	int n = 1000;
	int EventSet = PAPI_NULL;
	int retval;
	int i, j = 0;
	long long g1[2];

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	if ( ( retval =
		   PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );


	if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	if ( PAPI_query_event( PAPI_L2_TCM ) == PAPI_OK )
		j++;

	if ( j == 1 &&
		 ( retval = PAPI_add_event( EventSet, PAPI_L2_TCM ) ) != PAPI_OK ) {
		if ( retval != PAPI_ECNFLCT )
			test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
		j--;				 /* The event was not added */
	}

	i = j;
	if ( PAPI_query_event( PAPI_L2_DCM ) == PAPI_OK )
		j++;

	if ( j == ( i + 1 ) &&
		 ( retval = PAPI_add_event( EventSet, PAPI_L2_DCM ) ) != PAPI_OK ) {
		if ( retval != PAPI_ECNFLCT )
			test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
		j--;				 /* The event was not added */
	}

	if ( j ) {
		if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_start", retval );
		for ( i = 0; i < n; i++ ) {
			c = a * b;
		}
		if (!TESTS_QUIET) fprintf(stdout,"c=%lf\n",c);

		if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	}
	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
int main(int argc, char **argv)
{
   pthread_t slaves[MAX_THREADS];
   int rc, i, nthr;
   int retval;
  const PAPI_hw_info_t *hwinfo = NULL;

#if defined(__ALPHA) && defined(__osf__)
   test_skip(__FILE__, __LINE__, "thread support not available on this platform!", PAPI_ESBSTR);
#endif

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   if ((hwinfo = PAPI_get_hardware_info()) == NULL)
    test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);
   
   retval = PAPI_thread_init((unsigned long (*)(void)) (pthread_self));
   if (retval != PAPI_OK) {
      if (retval == PAPI_ESBSTR)
         test_skip(__FILE__, __LINE__, "PAPI_thread_init", retval);
      else
         test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval);
   }

   if (hwinfo->ncpu > MAX_THREADS) 
     nthr = MAX_THREADS;
   else
     nthr = hwinfo->ncpu;

   printf("Creating %d threads\n", nthr);

   for (i=0;i<nthr;i++)
     {
       rc = pthread_create(&slaves[i], NULL, Slave, NULL);
       if (rc) {
	 retval = PAPI_ESYS;
	 test_fail(__FILE__, __LINE__, "pthread_create", retval);
       }
     }

   for (i=0;i<nthr;i++)
     {
       pthread_join(slaves[i], NULL);
     }

   printf("Expected: %lld Received: %lld\n", (long long)nthr*num_iters, count);
   if (nthr*num_iters != count)
      test_fail(__FILE__, __LINE__, "Thread Locks", 1);

   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Example #14
0
int
main( int argc, char **argv )
{
	pthread_t *td = NULL;
	long n;

	tests_quiet( argc, argv );	/*Set TESTS_QUIET variable */

	if ( argc < 2 || sscanf( argv[1], "%d", &program_time ) < 1 )
		program_time = 6;
	if ( argc < 3 || sscanf( argv[2], "%d", &threshold ) < 1 )
		threshold = 20000000;
	if ( argc < 4 || sscanf( argv[3], "%d", &num_threads ) < 1 )
		num_threads = 3;

	td = malloc((num_threads+1) * sizeof(pthread_t));
	if (!td)
		test_fail( __FILE__, __LINE__, "td malloc failed", 1 );

	printf( "program_time = %d, threshold = %d, num_threads = %d\n\n",
			program_time, threshold, num_threads );

	if ( PAPI_library_init( PAPI_VER_CURRENT ) != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init failed", 1 );

	if ( PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) ) !=
		 PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_thread_init failed", 1 );

	if ( pthread_key_create( &key, NULL ) != 0 )
		test_fail( __FILE__, __LINE__, "pthread key create failed", 1 );

	gettimeofday( &start, NULL );

	for ( n = 1; n <= num_threads; n++ ) {
		if ( pthread_create( &(td[n]), NULL, my_thread, ( void * ) n ) != 0 )
			test_fail( __FILE__, __LINE__, "pthread create failed", 1 );
	}

	my_thread( ( void * ) 0 );

	/* wait for all the threads */
	for ( n = 1; n <= num_threads; n++ ) {
	  	if ( pthread_join( td[n], NULL))
			test_fail( __FILE__, __LINE__, "pthread join failed", 1 );
	}

	free(td);

	printf( "done\n" );

	test_pass( __FILE__, NULL, 0 );
	return ( 0 );
}
int
main( int argc, char **argv )
{
	int i, rc, retval;
	pthread_t id[NUM_THREADS];
	pthread_attr_t attr;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	printf( "%s: Using %d threads\n\n", argv[0], NUM_THREADS );
	printf
		( "Does non-threaded multiplexing work with extraneous threads present?\n" );

	/* Create a bunch of unused pthreads, to simulate threads created
	 * by the system that the user doesn't know about.
	 */
	pthread_attr_init( &attr );
#ifdef PTHREAD_CREATE_UNDETACHED
	pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
#endif
#ifdef PTHREAD_SCOPE_SYSTEM
	retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
	if ( retval != 0 )
		test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
#endif

#ifdef PPC64
	sigset_t sigprof;
	sigemptyset( &sigprof );
	sigaddset( &sigprof, SIGPROF );
	retval = sigprocmask( SIG_BLOCK, &sigprof, NULL );
	if ( retval != 0 )
		test_fail( __FILE__, __LINE__, "sigprocmask SIG_BLOCK", retval );
#endif

	for ( i = 0; i < NUM_THREADS; i++ ) {
		rc = pthread_create( &id[i], &attr, thread_fn, NULL );
		if ( rc )
			test_fail( __FILE__, __LINE__, "pthread_create", rc );
	}
	pthread_attr_destroy( &attr );

#ifdef PPC64
	retval = sigprocmask( SIG_UNBLOCK, &sigprof, NULL );
	if ( retval != 0 )
		test_fail( __FILE__, __LINE__, "sigprocmask SIG_UNBLOCK", retval );
#endif

	mainloop( NUM_ITERS );

	test_pass( __FILE__, NULL, 0 );
	exit( 0 );
}
int main(int argc, char **argv)
{

	tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

	printf("%s: Does PAPI_multiplex_init() handle lots of events?\n",argv[0]);
	printf("Using %d iterations\n", NUM_ITERS);

	case1();
	test_pass(__FILE__, NULL, 0);
	exit(1);
}
int main(int argc, char** argv) {
  pthread_t *callThd;
  int i, numthrds;
  int retval;
  pthread_attr_t attr;

  /* Set TESTS_QUIET variable */
  tests_quiet( argc, argv );

  int version = PAPI_library_init (PAPI_VER_CURRENT);
  if (version != PAPI_VER_CURRENT) {
    fprintf(stderr, "PAPI_library_init version mismatch\n");
    exit(1);
  }


  pthread_attr_init(&attr);
  if (PAPI_thread_init(pthread_self) != PAPI_OK) {
    fprintf(stderr, "PAPI_thread_init returned an error\n");
    exit(1);
  }
#ifdef PTHREAD_CREATE_UNDETACHED
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
#endif
#ifdef PTHREAD_SCOPE_SYSTEM
  retval = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
  if (retval != 0) {
    fprintf(stderr,"This system does not support kernel scheduled pthreads.\n");
    exit(1);
  }
#endif

  numthrds = NUM_INFILES;
  if (!TESTS_QUIET) printf("%d threads\n",numthrds);
  callThd = (pthread_t *)malloc(numthrds*sizeof(pthread_t));

  int rc ;
  for (i=0;i<(numthrds-1);i++) {
    rc = pthread_create(callThd+i, &attr, ThreadIO, (void *) files[i]);
    if (rc != 0) perror("Error creating thread using pthread_create()");
  }
  ThreadIO((void *)files[numthrds-1]);
  pthread_attr_destroy(&attr);

  for (i=0;i<(numthrds-1);i++)
    pthread_join(callThd[i], NULL);

  test_pass( __FILE__, NULL, 0 );
  return 0;
}
int main(int argc, char **argv)
{
   int i,j;
   int retval;
   int print_avail_only = 0;
   PAPI_event_info_t info;
   const PAPI_hw_info_t *hwinfo = NULL;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */
   for (i = 0; i < argc; i++)
      if (argv[i]) {
         if (strstr(argv[i], "-a"))
            print_avail_only = PAPI_PRESET_ENUM_AVAIL;
         if (strstr(argv[i], "-h")) {
            print_help();
            exit(1);
         }
      }

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   if (!TESTS_QUIET) {
      retval = PAPI_set_debug(PAPI_VERB_ECONT);
      if (retval != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_set_debug", retval);
   }

   if ((hwinfo = PAPI_get_hardware_info()) == NULL)
      test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

   i = PAPI_PRESET_MASK;
   printf("name,derived,postfix,short_descr,long_descr,note,[native,...]\n\n");

   do {
      if (PAPI_get_event_info(i, &info) == PAPI_OK) {
	      printf("%s,%s,%s,", info.symbol, info.derived, info.postfix);
         if (info.short_descr[0]) { printf("\"%s\",", info.short_descr); }
         else { printf(","); }
         if (info.long_descr[0]) { printf("\"%s\",", info.long_descr); }
         else { printf(","); }
	      if (info.note[0]) printf("\"%s\"", info.note);

         for (j=0;j<(int)info.count;j++) printf(",%s",info.name[j]);
         printf("\n");
	   }
   } while (PAPI_enum_event(&i, print_avail_only) == PAPI_OK);
   exit(1);
}
int main(int argc, char **argv)
{
   pthread_t t1, t2, t3, t4;
   pthread_attr_t attr;
   int retval;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   retval = PAPI_thread_init((unsigned long (*)(void)) (pthread_self));
   if (retval != PAPI_OK) {
      if (retval == PAPI_ESBSTR)
         test_skip(__FILE__, __LINE__, "PAPI_thread_init", retval);
      else
         test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval);
   }

   if (!TESTS_QUIET) {
      printf("Test case: Clock latency and resolution.\n");
      printf("Note: Virtual timers are proportional to # CPU's.\n");
      printf("-------------------------------------------------\n");
   }

   pthread_attr_init(&attr);
#ifdef PTHREAD_CREATE_UNDETACHED
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
#endif
#ifdef PTHREAD_SCOPE_SYSTEM
   retval = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
   if (retval != 0)
      test_skip(__FILE__, __LINE__, "pthread_attr_setscope", retval);
#endif

   pthread_create(&t1, &attr, pthread_main, NULL);
   pthread_create(&t2, &attr, pthread_main, NULL);
   pthread_create(&t3, &attr, pthread_main, NULL);
   pthread_create(&t4, &attr, pthread_main, NULL);
   pthread_main(NULL);

   pthread_join(t1, NULL);
   pthread_join(t2, NULL);
   pthread_join(t3, NULL);
   pthread_join(t4, NULL);

   test_pass(__FILE__, NULL, 0);
   exit(0);
}
Example #20
0
int main(int argc, char **argv)
{
   extern void dummy(void *);
   float matrixa[INDEX][INDEX], matrixb[INDEX][INDEX], mresult[INDEX][INDEX];
   float real_time, proc_time, ipc;
   long long ins;
   int retval;
   int i, j, k;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */


   /* Initialize the Matrix arrays */
   for (i = 0; i < INDEX * INDEX; i++) {
      mresult[0][i] = 0.0;
      matrixa[0][i] = matrixb[0][i] = rand() * (float) 1.1;
   }

   /* Setup PAPI library and begin collecting data from the counters */
   if ((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_ipc", retval);

   /* Matrix-Matrix multiply */
   for (i = 0; i < INDEX; i++)
      for (j = 0; j < INDEX; j++)
         for (k = 0; k < INDEX; k++)
            mresult[i][j] = mresult[i][j] + matrixa[i][k] * matrixb[k][j];

   /* Collect the data into the variables passed in */
   if ((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_ipc", retval);
   dummy((void *) mresult);

   if (!TESTS_QUIET) {
      printf("Real_time: %f Proc_time: %f Total ins: ", real_time, proc_time);
      printf(LLDFMT, ins);
      printf(" IPC: %f\n", ipc);
   }
   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Example #21
0
int main(int argc, char **argv) {

    int retval,max_multiplex,i,EventSet=PAPI_NULL;
    PAPI_event_info_t info;
    int added=0;
    int events_tried=0;

    /* Set TESTS_QUIET variable */
    tests_quiet( argc, argv );

    /* Initialize the library */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
        test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
    }

    retval = PAPI_multiplex_init(  );
    if ( retval != PAPI_OK) {
        test_fail(__FILE__, __LINE__, "Multiplex not supported", 1);
    }

    max_multiplex=PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL );

    if (!TESTS_QUIET) {
        printf("Maximum multiplexed counters=%d\n",max_multiplex);
    }

    if (!TESTS_QUIET) {
        printf("Trying to multiplex as many as possible:\n");
    }

    retval = PAPI_create_eventset( &EventSet );
    if ( retval != PAPI_OK ) {
        test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval );
    }

    retval = PAPI_assign_eventset_component( EventSet, 0 );
    if ( retval != PAPI_OK ) {
        test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component",
                  retval );
    }

    retval = PAPI_set_multiplex( EventSet );
    if ( retval != PAPI_OK ) {
        test_fail(__FILE__, __LINE__, "PAPI_create_multiplex", retval );
    }


    i = 0 | PAPI_PRESET_MASK;
    PAPI_enum_event( &i, PAPI_ENUM_FIRST );
    do {
        retval = PAPI_get_event_info( i, &info );
        if (retval==PAPI_OK) {
            if (!TESTS_QUIET) printf("Adding %s: ",info.symbol);
        }

        retval = PAPI_add_event( EventSet, info.event_code );
        if (retval!=PAPI_OK) {
            if (!TESTS_QUIET) printf("Fail!\n");
        }
        else {
            if (!TESTS_QUIET) printf("Success!\n");
            added++;
        }
        events_tried++;

    } while (PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK );

    PAPI_shutdown(  );

    if (!TESTS_QUIET) {
        printf("Added %d of theoretical max %d\n",added,max_multiplex);
    }

    if (events_tried<max_multiplex) {
        if (!TESTS_QUIET) {
            printf("Ran out of events before we ran out of room\n");
        }
    }
    else if (added!=max_multiplex) {
        test_fail(__FILE__, __LINE__,
                  "Couldn't max out multiplexed events", 1);
    }

    test_pass( __FILE__, NULL, 0 );
    exit( 0 );
}
Example #22
0
int main (int argc, char **argv)
{

    int retval,cid,rapl_cid=-1,numcmp;
    int EventSet = PAPI_NULL;
    long long *values;
    int num_events=0;
    int code;
    char event_names[MAX_RAPL_EVENTS][PAPI_MAX_STR_LEN];
    char units[MAX_RAPL_EVENTS][PAPI_MIN_STR_LEN];
    int r,i;
    const PAPI_component_info_t *cmpinfo = NULL;
    PAPI_event_info_t evinfo;
    long long before_time,after_time;
    double elapsed_time;

        /* Set TESTS_QUIET variable */
     tests_quiet( argc, argv );      

	/* PAPI Initialization */
     retval = PAPI_library_init( PAPI_VER_CURRENT );
     if ( retval != PAPI_VER_CURRENT ) {
	test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
     }

     if (!TESTS_QUIET) {
	printf("Trying all RAPL events\n");
     }

     numcmp = PAPI_num_components();

     for(cid=0; cid<numcmp; cid++) {

	if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	   test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
	}

	if (strstr(cmpinfo->name,"rapl")) {

	   rapl_cid=cid;

	   if (!TESTS_QUIET) {
	      printf("Found rapl component at cid %d\n",rapl_cid);
	   }

           if (cmpinfo->disabled) {
	      if (!TESTS_QUIET) {
		 printf("RAPL component disabled: %s\n",
                        cmpinfo->disabled_reason);
	      } 
              test_skip(__FILE__,__LINE__,"RAPL component disabled",0);
           }
	   break;
	}
     }

     /* Component not found */
     if (cid==numcmp) {
       test_skip(__FILE__,__LINE__,"No rapl component found\n",0);
     }

     /* Create EventSet */
     retval = PAPI_create_eventset( &EventSet );
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, 
                              "PAPI_create_eventset()",retval);
     }

     /* Add all events */

     code = PAPI_NATIVE_MASK;

     r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, rapl_cid );

     while ( r == PAPI_OK ) {

        retval = PAPI_event_code_to_name( code, event_names[num_events] );
	if ( retval != PAPI_OK ) {
	   printf("Error translating %#x\n",code);
	   test_fail( __FILE__, __LINE__, 
                            "PAPI_event_code_to_name", retval );
	}

	retval = PAPI_get_event_info(code,&evinfo);
	if (retval != PAPI_OK) {
	  test_fail( __FILE__, __LINE__,
             "Error getting event info\n",retval);
	}
	
	strncpy(units[num_events],evinfo.units,PAPI_MIN_STR_LEN);

        retval = PAPI_add_event( EventSet, code );
        if (retval != PAPI_OK) {
	  break; /* We've hit an event limit */
	}
	num_events++;
  	      
        r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid );
     }

     values=calloc(num_events,sizeof(long long));
     if (values==NULL) {
	test_fail(__FILE__, __LINE__, 
                              "No memory",retval);
     }

     if (!TESTS_QUIET) {
	printf("\nStarting measurements...\n\n");
     }

     /* Start Counting */
     before_time=PAPI_get_real_nsec();
     retval = PAPI_start( EventSet);
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
     }

     /* Run test */
     run_test(TESTS_QUIET);

     /* Stop Counting */
     after_time=PAPI_get_real_nsec();
     retval = PAPI_stop( EventSet, values);
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
     }

     elapsed_time=((double)(after_time-before_time))/1.0e9;

     if (!TESTS_QUIET) {
        printf("\nStopping measurements, took %.3fs, gathering results...\n\n",
	       elapsed_time);

	printf("Energy measurements:\n");

	for(i=0;i<num_events;i++) {
	   if (strstr(units[i],"nJ")) {

	      printf("%s\t%.6fJ\t(Average Power %.1fW)\n",
		    event_names[i],
		    (double)values[i]/1.0e9,
		    ((double)values[i]/1.0e9)/elapsed_time);
	   }
	}

	printf("\n");
	printf("Fixed values:\n");

	for(i=0;i<num_events;i++) {
	   if (!strstr(units[i],"nJ")) {

	     union {
	       long long ll;
	       double fp;
	     } result;

	     result.ll=values[i];

	      printf("%s\t%0.3f%s\n",
		    event_names[i],
		    result.fp,
		    units[i]);
	   }
	}

     }

     /* Done, clean up */
     retval = PAPI_cleanup_eventset( EventSet );
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, 
                              "PAPI_cleanup_eventset()",retval);
     }

     retval = PAPI_destroy_eventset( &EventSet );
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, 
                              "PAPI_destroy_eventset()",retval);
     }
        
     test_pass( __FILE__, NULL, 0 );
		
     return 0;
}
Example #23
0
int
main( int argc, char **argv )
{
	int retval;
	int num_events;
	long long *values;
	char *success;
	PAPI_event_info_t info;
	int EventSet = PAPI_NULL;
	int i, j, data_type, event;
	int u_format = 0;
	int hex_format = 0;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	if ( ( retval =
		   PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	/* Automatically pass if no events, for run_tests.sh */
	if ((( TESTS_QUIET ) && ( argc == 2)) || ( argc == 1 )) {
		test_pass( __FILE__, NULL, 0 );
	}

	values =
		( long long * ) malloc( sizeof ( long long ) * ( size_t ) argc );
	success = ( char * ) malloc( ( size_t ) argc );

	if ( success == NULL || values == NULL )
		test_fail_exit( __FILE__, __LINE__, "malloc", PAPI_ESYS );

	for ( num_events = 0, i = 1; i < argc; i++ ) {
		if ( !strcmp( argv[i], "-h" ) ) {
			print_help( argv );
			exit( 1 );
		} else if ( !strcmp( argv[i], "-u" ) ) {
			u_format = 1;
		} else if ( !strcmp( argv[i], "-x" ) ) {
			hex_format = 1;
		} else {
			if ( ( retval = PAPI_add_named_event( EventSet, argv[i] ) ) != PAPI_OK ) {
				printf( "Failed adding: %s\nbecause: %s\n", argv[i], 
					PAPI_strerror(retval));
			} else {
				success[num_events++] = i;
				printf( "Successfully added: %s\n", argv[i] );
			}
		}
	}

	/* Automatically pass if no events, for run_tests.sh */
	if ( num_events == 0 ) {
		test_pass( __FILE__, NULL, 0 );
	}


	printf( "\n" );

	do_flops( 1 );
	do_flush(  );

	if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) {
	   test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );
	}

	do_flops( NUM_FLOPS );
	do_misses( 1, L1_MISS_BUFFER_SIZE_INTS );

	if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
		test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );

	for ( j = 0; j < num_events; j++ ) {
		i = success[j];
		if (! (u_format || hex_format) ) {
			retval = PAPI_event_name_to_code( argv[i], &event );
			if (retval == PAPI_OK) {
				retval = PAPI_get_event_info(event, &info);
				if (retval == PAPI_OK) data_type = info.data_type;
				else data_type = PAPI_DATATYPE_INT64;
			}
			switch (data_type) {
			  case PAPI_DATATYPE_UINT64:
				printf( "%s : \t%llu(u)", argv[i], (unsigned long long)values[j] );
				break;
			  case PAPI_DATATYPE_FP64:
				printf( "%s : \t%0.3f", argv[i], *((double *)(&values[j])) );
				j++;
				break;
			  case PAPI_DATATYPE_BIT64:
				printf( "%s : \t0x%llX", argv[i], values[j] );
				break;
			  case PAPI_DATATYPE_INT64:
			  default:
				printf( "%s : \t%lld", argv[i], values[j] );
				break;
			}
			if (retval == PAPI_OK)  printf( " %s", info.units );
			printf( "\n" );
		}
		if (u_format) printf( "%s : \t%llu(u)\n", argv[i], (unsigned long long)values[j] );
		if (hex_format) printf( "%s : \t0x%llX\n", argv[i], values[j] );
	}

	printf( "\n----------------------------------\n" );
	printf
		( "Verification: Checks for valid event name.\n This utility lets you add events from the command line interface to see if they work.\n" );
	test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
int main (int argc, char **argv)
{
    int retval,cid,numcmp;
    int EventSet = PAPI_NULL;
    long long value;
    int code;
    char event_name[PAPI_MAX_STR_LEN];
    int total_events=0;
    int r;
    const PAPI_component_info_t *cmpinfo = NULL;

    /* Set TESTS_QUIET variable */
    tests_quiet( argc, argv );

    /* PAPI Initialization */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
        test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
    }

    if (!TESTS_QUIET) {
        printf("Trying all net events\n");
    }

    numcmp = PAPI_num_components();

    for(cid=0; cid<numcmp; cid++) {

        if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
            test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
        }

        if (!TESTS_QUIET) {
            printf("Component %d - %d events - %s\n", cid,
                cmpinfo->num_native_events, cmpinfo->name);
        }

        if ( strstr(cmpinfo->name, "infiniband") == NULL) {
            continue;
        }

        code = PAPI_NATIVE_MASK;

        r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
        while ( r == PAPI_OK ) {

            retval = PAPI_event_code_to_name( code, event_name );
            if ( retval != PAPI_OK ) {
                test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
            }

            if (!TESTS_QUIET) {
                printf("%#x %-24s = ", code, event_name);
            }

            EventSet = PAPI_NULL;

            retval = PAPI_create_eventset( &EventSet );
            if (retval != PAPI_OK) {
                test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
            }

            retval = PAPI_add_event( EventSet, code );
            if (retval != PAPI_OK) {
                test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval);
            }

            retval = PAPI_start( EventSet );
            if (retval != PAPI_OK) {
                test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
            }

            if (strcmp(event_name, "_recv") == 0) {
                /* XXX figure out a general method to  generate some traffic 
                 * for infiniband
                 * the operation should take more than one second in order
                 * to guarantee that the network counters are updated */
                retval = system("ping -c 4 " PINGADDR " > /dev/null");
                if (retval < 0) {
					test_fail(__FILE__, __LINE__, "Unable to start ping", retval);
				}
            }

            retval = PAPI_stop( EventSet, &value );
            if (retval != PAPI_OK) {
                test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
            }

            if (!TESTS_QUIET) printf("%lld\n", value);

            retval = PAPI_cleanup_eventset( EventSet );
            if (retval != PAPI_OK) {
                test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
            }

            retval = PAPI_destroy_eventset( &EventSet );
            if (retval != PAPI_OK) {
                test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
            }

            total_events++;

            r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
        }

    }

    if (total_events==0) {
        test_skip(__FILE__,__LINE__,"No net events found", 0);
    }

    test_pass( __FILE__, NULL, 0 );

    return 0;
}
Example #25
0
int
main( int argc, char **argv )
{
	int EventSet = PAPI_NULL;
	long long values0[2],values1[2],values2[2];
	int num_flops = 3000000, retval;
	int mythreshold = 1000000;
	char event_name1[PAPI_MAX_STR_LEN];
        int PAPI_event;
	int cid,numcmp,rapl_cid;
	const PAPI_component_info_t *cmpinfo = NULL;

	/* Set TESTS_QUIET variable */
	tests_quiet( argc, argv );      

	quiet=TESTS_QUIET;

	/* Init PAPI */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
	  test_fail(__FILE__, __LINE__,"PAPI_library_init",retval);
	}

	numcmp = PAPI_num_components();

	for(cid=0; cid<numcmp; cid++) {

	  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	    test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
	  }

	  if (strstr(cmpinfo->name,"linux-rapl")) {
	    rapl_cid=cid;
	    if (!TESTS_QUIET) printf("Found rapl component at cid %d\n",
				     rapl_cid);
	    if (cmpinfo->num_native_events==0) {
              test_skip(__FILE__,__LINE__,"No rapl events found",0);
	    }
	    break;
	  }
	}

	/* Component not found */
	if (cid==numcmp) {
	  test_skip(__FILE__,__LINE__,"No rapl component found\n",0);
	}


	/* add PAPI_TOT_CYC and PAPI_TOT_INS */
	retval=PAPI_create_eventset(&EventSet);
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval);
	}

	retval=PAPI_add_event(EventSet,PAPI_TOT_CYC);
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_add_event",retval);
	}

	retval=PAPI_add_event(EventSet,PAPI_TOT_INS);
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_add_event",retval);
	}

	/* Add some RAPL events */
	retval=PAPI_create_eventset(&EventSet2);
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval);
	}

        retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE0");
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_add_event",retval);
	}

        retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE1");
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_add_event",retval);
	}
	
	PAPI_event=PAPI_TOT_CYC;

	/* arbitrary */
	mythreshold = 2000000;
	if (!TESTS_QUIET) {
	   printf("Using %x for the overflow event, threshold %d\n",
		  PAPI_event,mythreshold);
	}

	/* Start the run calibration run */
	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_start",retval);
	}

	do_ints(num_flops,TESTS_QUIET);
	do_flops( 3000000 );

	/* stop the calibration run */
	retval = PAPI_stop( EventSet, values0 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_stop",retval);
	}


	/* set up overflow handler */
	retval = PAPI_overflow( EventSet,PAPI_event,mythreshold, 0, handler );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_overflow",retval);
	}

	/* Start overflow run */
	retval = PAPI_start( EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_start",retval);
	}
	retval = PAPI_start( EventSet2 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_start",retval);
	}

	do_ints(num_flops,TESTS_QUIET);
	do_flops( num_flops );

	/* stop overflow run */
	retval = PAPI_stop( EventSet, values1 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_stop",retval);
	}

	retval = PAPI_stop( EventSet2, values2 );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_stop",retval);
	}

	retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_overflow",retval);
	}

	retval = PAPI_event_code_to_name( PAPI_event, event_name1 );
	if (retval != PAPI_OK) {
	   test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n", retval);
	}

	if (!TESTS_QUIET) {
	   printf("%s: %lld %lld\n",event_name1,values0[0],values1[0]);
	}

	retval = PAPI_event_code_to_name( PAPI_TOT_INS, event_name1 );
	if (retval != PAPI_OK) {
	  test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n",retval);
	}

	if (!TESTS_QUIET) {
	   printf("%s: %lld %lld\n",event_name1,values0[1],values1[1]);
	}

	retval = PAPI_cleanup_eventset( EventSet );
	if ( retval != PAPI_OK ) {
	  test_fail(__FILE__, __LINE__,"PAPI_cleanup_eventset",retval);
	}

	retval = PAPI_destroy_eventset( &EventSet );
	if ( retval != PAPI_OK ) {
	   test_fail(__FILE__, __LINE__,"PAPI_destroy_eventset",retval);
	}

	if (rapl_backward) {
	   test_fail(__FILE__, __LINE__,"RAPL counts went backward!",0);
	}

	test_pass( __FILE__, NULL, 0 );


	return 0;
}
int main(int argc, char **argv)
{
   int retval, i,j;
   int EventSet=PAPI_NULL;
   long long values[2];
   const PAPI_hw_info_t *hwinfo = NULL;
   char descr[PAPI_MAX_STR_LEN];
   PAPI_event_info_t evinfo;
   PAPI_mh_level_t *L;


   const unsigned int eventlist[] = {
      PAPI_L1_DCA,
      PAPI_L1_DCM,
      PAPI_L1_DCH,
      PAPI_L2_DCA,
      PAPI_L2_DCM,
      PAPI_L2_DCH,
#if 0
      PAPI_L1_LDM,
      PAPI_L1_STM,
      PAPI_L1_DCR,
      PAPI_L1_DCW,
      PAPI_L1_ICM,
      PAPI_L1_TCM,
      PAPI_LD_INS,
      PAPI_SR_INS,
      PAPI_LST_INS,
      PAPI_L2_DCR,
      PAPI_L2_DCW,
      PAPI_CSR_TOT,
      PAPI_MEM_SCY,
      PAPI_MEM_RCY,
      PAPI_MEM_WCY,
      PAPI_L1_ICH,
      PAPI_L1_ICA,
      PAPI_L1_ICR,
      PAPI_L1_ICW,
      PAPI_L1_TCH,
      PAPI_L1_TCA,
      PAPI_L1_TCR,
      PAPI_L1_TCW,
      PAPI_L2_DCM,
      PAPI_L2_ICM,
      PAPI_L2_TCM,
      PAPI_L2_LDM,
      PAPI_L2_STM,
      PAPI_L2_DCH,
      PAPI_L2_DCA,
      PAPI_L2_DCR,
      PAPI_L2_DCW,
      PAPI_L2_ICH,
      PAPI_L2_ICA,
      PAPI_L2_ICR,
      PAPI_L2_ICW,
      PAPI_L2_TCH,
      PAPI_L2_TCA,
      PAPI_L2_TCR,
      PAPI_L2_TCW,
#endif
      0
   };

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   if ((hwinfo = PAPI_get_hardware_info()) == NULL) {
      test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);
   }

   if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);

   /* Extract and report the cache information */
   L = (PAPI_mh_level_t *) (hwinfo->mem_hierarchy.level);
   for (i=0; i<hwinfo->mem_hierarchy.levels; i++) {
      for (j=0; j<2; j++) {
	  int tmp;

	  tmp = PAPI_MH_CACHE_TYPE(L[i].cache[j].type);
	  if (tmp == PAPI_MH_TYPE_UNIFIED)
	  { printf("L%d Unified ",i+1);} 
	  else if (tmp == PAPI_MH_TYPE_DATA)
	  { 	      printf("L%d Data ",i+1);}
	  else if (tmp == PAPI_MH_TYPE_INST)
	  { printf("L%d Instruction ",i+1); } 
	  else if (tmp == PAPI_MH_TYPE_VECTOR)
	  { printf("L%d Vector ",i+1); } 
	  else if (tmp == PAPI_MH_TYPE_TRACE)
	  { printf("L%d Trace ",i+1); } 
	  else if (tmp == PAPI_MH_TYPE_EMPTY)
	  { break; }
	  else
	  { test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EBUG); }

	  tmp = PAPI_MH_CACHE_WRITE_POLICY(L[i].cache[j].type);
	  if (tmp == PAPI_MH_TYPE_WB)
	  { printf("Write back ");} 
	  else if (tmp == PAPI_MH_TYPE_WT)
	  { printf("Write through ");} 
	  else 
	  { test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EBUG); } 

	  tmp = PAPI_MH_CACHE_REPLACEMENT_POLICY(L[i].cache[j].type);
	  if (tmp == PAPI_MH_TYPE_PSEUDO_LRU)
	  { printf("Pseudo LRU policy "); } 
	  else if (tmp == PAPI_MH_TYPE_LRU)
	  { printf("LRU policy ");} 
	  else if (tmp == PAPI_MH_TYPE_UNKNOWN)
	  { printf("Unknown policy "); }
	  else
	  { test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EBUG); }

	  printf("Cache:\n");
         if (L[i].cache[j].type) {
            printf("  Total size: %dKB\n  Line size: %dB\n  Number of Lines: %d\n  Associativity: %d\n\n",
               (L[i].cache[j].size)>>10, L[i].cache[j].line_size, L[i].cache[j].num_lines, L[i].cache[j].associativity);
         }
      }
   }
int main(int argc, char **argv)
{
   int EventSet=PAPI_NULL;
   long long values[2] = { 0, 0 };
   long long min, max;
   int num_flops=NUM_FLOPS, retval;
   int PAPI_event=0, mythreshold;
   char event_name[PAPI_MAX_STR_LEN];
   const PAPI_hw_info_t *hw_info = NULL;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   hw_info = PAPI_get_hardware_info();
   if (hw_info == NULL)
     test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

   if((!strncmp(hw_info->model_string, "UltraSPARC", 10) &&
       !(strncmp(hw_info->vendor_string, "SUN", 3))) ||
      (!strncmp(hw_info->model_string, "AMD K7", 6)) ||
      (!strncmp(hw_info->vendor_string, "Cray", 4)) ||
      (strstr(hw_info->model_string, "POWER3"))) {
   /* query and set up the right instruction to monitor */
      if (PAPI_query_event(PAPI_TOT_INS) == PAPI_OK) {
         PAPI_event = PAPI_TOT_INS;
      } else {
         test_fail(__FILE__, __LINE__, "PAPI_TOT_INS not available on this Sun platform!", 0);
      }
   } else {
   /* query and set up the right instruction to monitor */
      if (PAPI_query_event(PAPI_FP_INS) == PAPI_OK) {
         PAPI_event = PAPI_FP_INS;
      } else {
         if (PAPI_query_event(PAPI_FP_OPS) == PAPI_OK) 
            PAPI_event = PAPI_FP_OPS;
         else 
            PAPI_event = PAPI_TOT_INS;
      }
   }

   if ( PAPI_event == PAPI_FP_INS )
      mythreshold = THRESHOLD ;
   else 
#if defined(linux)
      mythreshold = hw_info->mhz*10000*2;
#else
      mythreshold = THRESHOLD*2;
#endif

   retval = PAPI_create_eventset(&EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);

   retval = PAPI_add_event(EventSet, PAPI_event);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_add_event", retval);

   retval = PAPI_start(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_stop(EventSet, &values[0]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

   retval = PAPI_overflow(EventSet, PAPI_event, mythreshold, 0, handler);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_overflow", retval);

   retval = PAPI_start(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_stop(EventSet, &values[1]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

#if defined(linux) || defined(__ia64__) || defined(_WIN32) || defined(_POWER4)
   num_flops *= 2;
#endif

   if (!TESTS_QUIET) {
      if ((retval = PAPI_event_code_to_name(PAPI_event, event_name)) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval);

      printf("Test case: Overflow dispatch of 1st event in set with 1 event.\n");
      printf("--------------------------------------------------------------\n");
      printf("Threshold for overflow is: %d\n", mythreshold);
      printf("Using %d iterations of c += a*b\n", NUM_FLOPS);
      printf("-----------------------------------------------\n");

      printf("Test type    : %16d%16d\n", 1, 2);
      printf(OUT_FMT, event_name, values[0], values[1]);
      printf("Overflows    : %16s%16d\n", "", total);
      printf("-----------------------------------------------\n");

      printf("Verification:\n");
/*
	if (PAPI_event == PAPI_FP_INS)
		printf("Row 1 approximately equals %d %d\n", num_flops, num_flops);
	printf("Column 1 approximately equals column 2\n");
*/
      printf("Row 3 approximately equals %u +- %u %%\n",
             (unsigned) ((values[0]) / (long long) mythreshold),
             (unsigned) (OVR_TOLERANCE * 100.0));

   }

/*
  min = (long long)(values[0]*(1.0-TOLERANCE));
  max = (long long)(values[0]*(1.0+TOLERANCE));
  if ( values[1] > max || values[1] < min )
  	test_fail(__FILE__, __LINE__, event_name, 1);
*/

   min = (long long) ((values[0] * (1.0 - OVR_TOLERANCE)) / (long long) mythreshold);
   max = (long long) ((values[0] * (1.0 + OVR_TOLERANCE)) / (long long) mythreshold);
   if (total > max || total < min)
      test_fail(__FILE__, __LINE__, "Overflows", 1);

   test_pass(__FILE__, NULL, 0);
   exit(1);
}
Example #28
0
int
main( int argc, char **argv )
{
	int retval, i;
	int EventSet = PAPI_NULL, count = 0, err_count = 0;
	long long values;
	PAPI_event_info_t info;
	char errstring[PAPI_MAX_STR_LEN];


	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	retval = PAPI_create_eventset( &EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
		if ( PAPI_get_event_info( PAPI_PRESET_MASK | i, &info ) != PAPI_OK )
			continue;
		if ( !( info.count ) )
			continue;
		printf( "Adding %-14s", info.symbol );
		retval = PAPI_add_event( EventSet, ( int ) info.event_code );
		if ( retval != PAPI_OK ) {
			PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN );
			fprintf( stdout, "Error: %s\n", errstring );
			err_count++;
		} else {
			retval = PAPI_start( EventSet );
			if ( retval != PAPI_OK ) {
				PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN );
				fprintf( stdout, "Error Starting: %s\n", errstring );
				err_count++;
			} else {
				retval = PAPI_stop( EventSet, &values );
				if ( retval != PAPI_OK ) {
					PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN );
					fprintf( stdout, "Error Stopping: %s\n", errstring );
					err_count++;
				} else {
					printf( "successful\n" );
					count++;
				}
			}
			retval = PAPI_remove_event( EventSet, ( int ) info.event_code );
			if ( retval != PAPI_OK )
				test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval );
		}
	}
	retval = PAPI_destroy_eventset( &EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );

	printf( "Successfully added, started and stopped %d events.\n", count );
	if ( err_count )
		printf( "Failed to add, start or stop %d events.\n", err_count );
	if ( count > 0 )
		test_pass( __FILE__, NULL, 0 );
	else
		test_fail( __FILE__, __LINE__, "No events added", 1 );
	exit( 1 );
}
Example #29
0
int
main( int argc, char **argv )
{
	int nthreads = 8, ret, i;
	PAPI_event_info_t info;
	pthread_t *threads;
	const PAPI_hw_info_t *hw_info;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	if ( !TESTS_QUIET ) {
		if ( argc > 1 ) {
			int tmp = atoi( argv[1] );
			if ( tmp >= 1 )
				nthreads = tmp;
		}
	}

	ret = PAPI_library_init( PAPI_VER_CURRENT );
	if ( ret != PAPI_VER_CURRENT ) {
		test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
	}

	hw_info = PAPI_get_hardware_info(  );
	if ( hw_info == NULL )
		test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );

	if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
		ret = PAPI_set_domain( PAPI_DOM_ALL );
		if ( ret != PAPI_OK ) {
			test_fail( __FILE__, __LINE__, "PAPI_set_domain", ret );
		}
	}

	ret = PAPI_thread_init( ( unsigned long ( * )( void ) ) pthread_self );
	if ( ret != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
	}

	ret = PAPI_multiplex_init(  );
	if ( ret != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", ret );
	}

	/* Fill up the event set with as many non-derived events as we can */

	i = PAPI_PRESET_MASK;
	do {
		if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
			if ( info.count == 1 ) {
				events[numevents++] = ( int ) info.event_code;
				printf( "Added %s\n", info.symbol );
			} else {
				printf( "Skipping derived event %s\n", info.symbol );
			}
		}
	} while ( ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK )
			  && ( numevents < PAPI_MPX_DEF_DEG ) );

	printf( "Found %d events\n", numevents );

	do_stuff(  );

	printf( "Creating %d threads:\n", nthreads );

	threads =
		( pthread_t * ) malloc( ( size_t ) nthreads * sizeof ( pthread_t ) );
	if ( threads == NULL ) {
		test_fail( __FILE__, __LINE__, "malloc", PAPI_ENOMEM );
	}

	/* Create the threads */
	for ( i = 0; i < nthreads; i++ ) {
		ret = pthread_create( &threads[i], NULL, thread, NULL );
		if ( ret != 0 ) {
			test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
		}
	}

	/* Wait for thread completion */
	for ( i = 0; i < nthreads; i++ ) {
		ret = pthread_join( threads[i], NULL );
		if ( ret != 0 ) {
			test_fail( __FILE__, __LINE__, "pthread_join", PAPI_ESYS );
		}
	}

	printf( "Done." );
	test_pass( __FILE__, NULL, 0 );
	pthread_exit( NULL );
	exit( 0 );
}
Example #30
0
int
main( int argc, char *argv[] )
{
	extern void dummy( void * );

	float aa, *a, *b, *c, *x, *y;
	double aad, *ad, *bd, *cd, *xd, *yd;
	int i, j, n;
	int inner = 0;
	int vector = 0;
	int matrix = 0;
	int double_precision = 0;
	int retval = PAPI_OK;
	char papi_event_str[PAPI_MIN_STR_LEN] = "PAPI_FP_OPS";
	int papi_event;
	int EventSet = PAPI_NULL;

/* Parse the input arguments */
	for ( i = 0; i < argc; i++ ) {
		if ( strstr( argv[i], "-i" ) )
			inner = 1;
		else if ( strstr( argv[i], "-v" ) )
			vector = 1;
		else if ( strstr( argv[i], "-m" ) )
			matrix = 1;
		else if ( strstr( argv[i], "-e" ) ) {
			if ( ( argv[i + 1] == NULL ) || ( strlen( argv[i + 1] ) == 0 ) ) {
				print_help( argv );
				exit( 1 );
			}
			strncpy( papi_event_str, argv[i + 1], sizeof ( papi_event_str ) );
			i++;
		} else if ( strstr( argv[i], "-d" ) )
			double_precision = 1;
		else if ( strstr( argv[i], "-h" ) ) {
			print_help( argv );
			exit( 1 );
		}
	}

	/* if no options specified, set all tests to TRUE */
	if ( inner + vector + matrix == 0 )
		inner = vector = matrix = 1;


	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	if ( !TESTS_QUIET )
		printf( "Initializing..." );

	/* Initialize PAPI */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	/* Translate name */
	retval = PAPI_event_name_to_code( papi_event_str, &papi_event );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );

	if ( PAPI_query_event( papi_event ) != PAPI_OK )
		test_skip( __FILE__, __LINE__, "PAPI_query_event", PAPI_ENOEVNT );

	if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	if ( ( retval = PAPI_add_event( EventSet, papi_event ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );

	printf( "\n" );

	retval = PAPI_OK;

	/* Inner Product test */
	if ( inner ) {
		/* Allocate the linear arrays */
	   if (double_precision) {
	        xd = malloc( INDEX5 * sizeof(double) );
	        yd = malloc( INDEX5 * sizeof(double) );
		if ( !( xd && yd ) )
			retval = PAPI_ENOMEM;
	   }
	   else {
	        x = malloc( INDEX5 * sizeof(float) );
		y = malloc( INDEX5 * sizeof(float) );
		if ( !( x && y ) )
			retval = PAPI_ENOMEM;
	   }

		if ( retval == PAPI_OK ) {
			headerlines( "Inner Product Test", TESTS_QUIET );

			/* step through the different array sizes */
			for ( n = 0; n < INDEX5; n++ ) {
				if ( n < INDEX1 || ( ( n + 1 ) % 50 ) == 0 ) {

					/* Initialize the needed arrays at this size */
					if ( double_precision ) {
						for ( i = 0; i <= n; i++ ) {
							xd[i] = ( double ) rand(  ) * ( double ) 1.1;
							yd[i] = ( double ) rand(  ) * ( double ) 1.1;
						}
					} else {
						for ( i = 0; i <= n; i++ ) {
							x[i] = ( float ) rand(  ) * ( float ) 1.1;
							y[i] = ( float ) rand(  ) * ( float ) 1.1;
						}
					}

					/* reset PAPI flops count */
					reset_flops( "Inner Product Test", EventSet );

					/* do the multiplication */
					if ( double_precision ) {
						aad = inner_double( n, xd, yd );
						dummy( ( void * ) &aad );
					} else {
						aa = inner_single( n, x, y );
						dummy( ( void * ) &aa );
					}
					resultline( n, 1, EventSet );
				}
			}
		}
		if (double_precision) {
			free( xd );
			free( yd );
		} else {
			free( x );
			free( y );
		}
	}

	/* Matrix Vector test */
	if ( vector && retval != PAPI_ENOMEM ) {
		/* Allocate the needed arrays */
	  if (double_precision) {
	        ad = malloc( INDEX5 * INDEX5 * sizeof(double) );
	        xd = malloc( INDEX5 * sizeof(double) );
	        yd = malloc( INDEX5 * sizeof(double) );
		if ( !( ad && xd && yd ) )
			retval = PAPI_ENOMEM;
	  } else {
	        a = malloc( INDEX5 * INDEX5 * sizeof(float) );
	        x = malloc( INDEX5 * sizeof(float) );
	        y = malloc( INDEX5 * sizeof(float) );
		if ( !( a && x && y ) )
			retval = PAPI_ENOMEM;
	  }

		if ( retval == PAPI_OK ) {
			headerlines( "Matrix Vector Test", TESTS_QUIET );

			/* step through the different array sizes */
			for ( n = 0; n < INDEX5; n++ ) {
				if ( n < INDEX1 || ( ( n + 1 ) % 50 ) == 0 ) {

					/* Initialize the needed arrays at this size */
					if ( double_precision ) {
						for ( i = 0; i <= n; i++ ) {
							yd[i] = 0.0;
							xd[i] = ( double ) rand(  ) * ( double ) 1.1;
							for ( j = 0; j <= n; j++ )
								ad[i * n + j] =
									( double ) rand(  ) * ( double ) 1.1;
						}
					} else {
						for ( i = 0; i <= n; i++ ) {
							y[i] = 0.0;
							x[i] = ( float ) rand(  ) * ( float ) 1.1;
							for ( j = 0; j <= n; j++ )
								a[i * n + j] =
									( float ) rand(  ) * ( float ) 1.1;
						}
					}

					/* reset PAPI flops count */
					reset_flops( "Matrix Vector Test", EventSet );

					/* compute the resultant vector */
					if ( double_precision ) {
						vector_double( n, ad, xd, yd );
						dummy( ( void * ) yd );
					} else {
						vector_single( n, a, x, y );
						dummy( ( void * ) y );
					}
					resultline( n, 2, EventSet );
				}
			}
		}
		if (double_precision) {
			free( ad );
			free( xd );
			free( yd );
		} else {
			free( a );
			free( x );
			free( y );
		}
	}

	/* Matrix Multiply test */
	if ( matrix && retval != PAPI_ENOMEM ) {
		/* Allocate the needed arrays */
	  if (double_precision) {
	        ad = malloc( INDEX5 * INDEX5 * sizeof(double) );
	        bd = malloc( INDEX5 * INDEX5 * sizeof(double) );
	        cd = malloc( INDEX5 * INDEX5 * sizeof(double) );
		if ( !( ad && bd && cd ) )
			retval = PAPI_ENOMEM;
	  } else {
	        a = malloc( INDEX5 * INDEX5 * sizeof(float) );
	        b = malloc( INDEX5 * INDEX5 * sizeof(float) );
	        c = malloc( INDEX5 * INDEX5 * sizeof(float) );
		if ( !( a && b && c ) )
			retval = PAPI_ENOMEM;
	  }


		if ( retval == PAPI_OK ) {
			headerlines( "Matrix Multiply Test", TESTS_QUIET );

			/* step through the different array sizes */
			for ( n = 0; n < INDEX5; n++ ) {
				if ( n < INDEX1 || ( ( n + 1 ) % 50 ) == 0 ) {

					/* Initialize the needed arrays at this size */
					if ( double_precision ) {
						for ( i = 0; i <= n * n + n; i++ ) {
							cd[i] = 0.0;
							ad[i] = ( double ) rand(  ) * ( double ) 1.1;
							bd[i] = ( double ) rand(  ) * ( double ) 1.1;
						}
					} else {
						for ( i = 0; i <= n * n + n; i++ ) {
							c[i] = 0.0;
							a[i] = ( float ) rand(  ) * ( float ) 1.1;
							b[i] = ( float ) rand(  ) * ( float ) 1.1;
						}
					}

					/* reset PAPI flops count */
					reset_flops( "Matrix Multiply Test", EventSet );

					/* compute the resultant matrix */
					if ( double_precision ) {
						matrix_double( n, cd, ad, bd );
						dummy( ( void * ) c );
					} else {
						matrix_single( n, c, a, b );
						dummy( ( void * ) c );
					}
					resultline( n, 3, EventSet );
				}
			}
		}
		if (double_precision) {
			free( ad );
			free( bd );
			free( cd );
		} else {
			free( a );
			free( b );
			free( c );
		}
	}

	/* exit with status code */
	if ( retval == PAPI_ENOMEM )
		test_fail( __FILE__, __LINE__, "malloc", retval );
	else
		test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}