Ejemplo n.º 1
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 );
}
Ejemplo n.º 2
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 );
}
Ejemplo n.º 3
0
//
// This method should be placed at the start of instrumented code
//
void startPapiCounters(){
    initializeCounters(0);
#ifdef DBG
    printGEvents();
    printf("********* STARTING COUNTERS *************\n");
    //assert(NUM_EVENTS == _G_EVENT_COUNT);
#endif
    // initialize papi library and assert that it's successful
    _CALL_PAPI(PAPI_library_init( PAPI_VER_CURRENT ));    
    
    // check that all the events can be counted at once.
    int numCounters = PAPI_num_counters() ;
    assert( NUM_EVENTS <= numCounters );

    
#ifdef DBG
    printf("Number of hardware counters available on this machine: %d", numCounters);
#endif

    for ( int i = 0; i < NUM_EVENTS; i++ ) {
        char name[PAPI_MAX_STR_LEN];
        (void) _CALL_PAPI(PAPI_event_code_to_name( _G_EVENTS[i], name ));
        if(PAPI_query_event( _G_EVENTS[i] ) < PAPI_OK) {
            fprintf(stderr, "Event %s could not be counted on this machine.\n", name);
            abort();
        }
    }

    //*******  Start Counters ******
    (void) _CALL_PAPI(PAPI_start_counters(_G_EVENTS, NUM_EVENTS));
}
Ejemplo n.º 4
0
void my_papi_start( int myrank )
{
#ifdef PAPI_MONITOR
  int retval, index ;
  char EventCodeStr[PAPI_MAX_STR_LEN];
  
  if(myrank == 0)
    DO_TEST = 1;
  
  retval = PAPI_library_init(PAPI_VER_CURRENT);
  if (retval != PAPI_VER_CURRENT)
    {
      fprintf(stderr, "PAPI library init error! %d\n", retval);
      exit(1);
    }
  fprintf(stderr,"PAPI Library start ...\n");

  if (PAPI_create_eventset(&PAPI_EventSet) != PAPI_OK)
    exit(1);

  for (index = 0 ; index < NEVENTS ; index ++)
    {
      PAPI_event_code_to_name(PAPI_events[index], EventCodeStr);
      /*fprintf(stderr,"Adding event %s ... ",EventCodeStr); */
      if (PAPI_add_event(PAPI_EventSet,PAPI_events[index]) != PAPI_OK)
	exit(1);
      /*fprintf(stderr," DONE !\n"); */
    }
  /*fprintf(stderr,"\n"); */

  if (PAPI_start(PAPI_EventSet) != PAPI_OK)
    exit(1);
#endif /*PAPI_MONITOR */
}
Ejemplo n.º 5
0
void initTimers() {
#if USING_PERFCTR == 0
	int retval;
	fprintf(stderr, "1\n");

	if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) {
		printf("PAPI Library initialization error! \n");
		exit(1);
	}

	fprintf(stderr, "2\n");
	if ((retval = PAPI_set_debug(PAPI_VERB_ESTOP)) != PAPI_OK) {
		printf("PAPI set debug error! \n");
		exit(1);
	}
	fprintf(stderr, "3\n");
	if (PAPI_thread_init(pthread_self) != PAPI_OK) {
		printf("PAPI thread Library initialisation error! \n");
		exit(1);
	}
	fprintf(stderr, "4\n");
	PAPI_thread_init(gettid);
	PAPI_register_thread();
#else
	PERFCTR_initialize();
	PERFCTR_register_thread();
#endif

	gettimeofday(&program_start, NULL);
}
Ejemplo n.º 6
0
 main(){

	long_long start_cycles, end_cycles, start_usec, end_usec;
	int EventSet = PAPI_NULL;

	int tabla[100];

	        
	if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
	  exit(1);

	/* Gets the starting time in clock cycles */
	start_cycles = PAPI_get_real_cyc();

	/* Gets the starting time in microseconds */
	start_usec = PAPI_get_real_usec();

	/*Create an EventSet */
	//if (PAPI_create_eventset(&EventSet) != PAPI_OK)
	//  exit(1);
	tabla[0]=1;
	tabla[100]=1;
	/* Gets the ending time in clock cycles */
	end_cycles = PAPI_get_real_cyc();

	/* Gets the ending time in microseconds */
	end_usec = PAPI_get_real_usec();

	printf("Wall clock cycles: %lld\n", end_cycles - start_cycles);
	printf("Wall clock time in microseconds: %lld\n", end_usec - start_usec); 
}
Ejemplo n.º 7
0
Archivo: floops1.c Proyecto: di/school
int main(int argc, char *argv[]) {

     double a[MAXVSIZE], b[MAXVSIZE], c[MAXVSIZE];
     int i,n;
     long long before, after;
     float rtime, ptime, mflops;
     long long flpops; 

     if (PAPI_VER_CURRENT != 
		PAPI_library_init(PAPI_VER_CURRENT))
	ehandler("PAPI_library_init error.");


     printf("Enter vector size:  ");
     scanf("%d",&n);

     for (i=0;i<n;i++) {
       a[i] = i;
       b[i] = n-i;
     }

     PAPI_flops(&rtime, &ptime, &flpops, &mflops);
     loop(c,a,b,n);
     PAPI_flops(&rtime, &ptime, &flpops, &mflops);


     printf("Number of floatinig point operations = %lld\n",flpops);
     printf("mflops = %f\n",mflops);
     return 0;

}
Ejemplo n.º 8
0
void PAPI_HW_COUNTER_init(int _numcpus, int _numiters){
  int retval;
  int i,j;

  numcpus = _numcpus;
  numiters= _numiters;

  retval = PAPI_library_init(PAPI_VER_CURRENT);
  if (retval <0){
    printf("ERROR: PAPI failed to initialize.(%d)\n",retval);
    exit(1);
  }else if (retval != PAPI_VER_CURRENT) {
    printf("ERROR: PAPI library version mismatch.(%d!=%d)\n", PAPI_VER_CURRENT,retval);
    exit(1);
  }
  printf("PAPI is initialized.\n");

  // malloc thr_vars
  if (posix_memalign((void**)&thr_vars, CACHELINE_SIZE, sizeof(struct PAPI_VARS)*numcpus)){
    printf("ERROR: failed to allocate memory to thr_vars\n");
    exit(1);
  }

  // Open file to overall result
  summary_f=fopen("summary.txt", "w");
  if (summary_f == NULL){
    printf("ERROR: failed to open file summary.txt.\n");
    exit(1);
  }
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
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);
}
Ejemplo n.º 11
0
void papi_global_init() {
  int retval;
  if ( (retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) {
    fprintf(stderr, "PAPI library init error!\n%s\n", PAPI_strerror(retval));
  }
  //papi_init_counters_name_non_thread_safe();
}
Ejemplo n.º 12
0
void initialize_papi (int eventCode) {
  /* Initialize the PAPI library */
  retval = PAPI_library_init(PAPI_VER_CURRENT);
  if (retval != PAPI_VER_CURRENT) {
    fprintf(stderr, "PAPI library init error! %d\n",PAPI_EINVAL);
    handle_error(1);
  }
  
  if (EventSet==PAPI_NULL) {
  	if (PAPI_create_eventset(&EventSet) != PAPI_OK) {
	  	printf("PAPI create eventset error\n");
  	  handle_error(1);
  	}
  } else {
  	if (PAPI_cleanup_eventset(EventSet) != PAPI_OK) {
  		printf("PAPI cleanup error\n");
			handle_error(1);
		}
	}
	
  if (PAPI_add_event(EventSet, eventCode) != PAPI_OK) {
		printf("PAPI add event error: %x\n", eventCode);
    handle_error(1);
  }  
}
Ejemplo n.º 13
0
/* Initialize htable with the metrics known by the system */
int init_known_metrics()
{
  /* Initialize PAPI library */
  int retval;

  retval = PAPI_library_init(PAPI_VER_CURRENT);
  if (retval != PAPI_VER_CURRENT) {
    fprintf(stderr, "Error! PAPI_library_init %d\n",retval);

    PAPI_shutdown();
  }

  /* Initialize custom metrics storage */
  HASH_CLEAR(hh, callbacks_storage);

  for(int i = 0; i < available_metrics_no; ++i) {
    htable *new_pair = NULL;
    new_pair = malloc(sizeof(htable));

    if (!new_pair) {
        fprintf(stderr, "can't alloc memory for the new pair\n");
        exit(-1);
    }

    strcpy(new_pair->key, callbacks[i].alias);
    new_pair->value = callbacks[i].func;

    /* insert the new pair in callbacks_storage */
    HASH_ADD_STR(callbacks_storage, key, new_pair);
  }

  return 0;
}
Ejemplo n.º 14
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 );
	}
}
Ejemplo n.º 15
0
void papi_init(int eventNumber){
	if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) {
		fprintf(stderr, "PAPI is unsupported.\n");
		papi_supported = false;
	}

	if (PAPI_num_counters() < 5) {
		fprintf(stderr, "PAPI is unsupported.\n");
		papi_supported = false;
	}

	if ((papi_err = PAPI_create_eventset(&eventSet)) != PAPI_OK) {
		fprintf(stderr, "Could not create event set: %s\n", PAPI_strerror(papi_err));
	}

    /* force program to run on a single CPU */
    cpu_set_t my_set;        /* Define your cpu_set bit mask. */
    CPU_ZERO(&my_set);       /* Initialize it all to 0, i.e. no CPUs selected. */
	CPU_SET(0, &my_set);
	if (sched_setaffinity(0, sizeof(cpu_set_t), &my_set) != 0) {
		perror("sched_setaffinity error");
	}

	if ((papi_err = PAPI_add_event(eventSet, events[eventNumber])) != PAPI_OK ) {
		fprintf(stderr, "Could not add event: %s\n", PAPI_strerror(papi_err));
	}
}
Ejemplo n.º 16
0
void start_papi() {
    values = calloc(en, sizeof(long long));

    if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) {
        fprintf(stderr, "PAPI is unsupported.\n");
        papi_supported = 0;
    }

    if (PAPI_num_counters() < en) {
        fprintf(stderr, "PAPI is unsupported.\n");
        papi_supported = 0;
    }
    
    if ((papi_err = PAPI_create_eventset(&eventSet)) != PAPI_OK) {
        fprintf(stderr, "Could not create event set: %s\n", PAPI_strerror(papi_err));
    }

    for (int i=0; i<en; ++i) {
        if ((papi_err = PAPI_add_event(eventSet, events[i])) != PAPI_OK ) {
            fprintf(stderr, "Could not add event: %s %s\n", event_names[i], PAPI_strerror(papi_err));
        }
    }

    /* start counters */

    if (papi_supported) {
        if ((papi_err = PAPI_start(eventSet)) != PAPI_OK) {
            fprintf(stderr, "Could not start counters: %s\n", PAPI_strerror(papi_err));
        }
    }
}
Ejemplo n.º 17
0
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);
}
Ejemplo n.º 18
0
static void namdInitPapiCounters(){
	if(CkMyRank()==0){
		//only initialize per OS process (i.e. a charm node)
		int retval = PAPI_library_init(PAPI_VER_CURRENT);
		if(retval != PAPI_VER_CURRENT) {
			if(CkMyPe()==0){
				CkPrintf("ERROR: PAPI library is not compatitible!");
				CkExit();
			}
		}
	#if CMK_SMP
		//now only consider systems that are compatible with POSIX
		if(PAPI_thread_init(pthread_self)!=PAPI_OK) {
			if(CkMyPe()==0){
				CkPrintf("ERROR: multi-thread mode in PAPI could not be initialized!");
				CkExit();
			}
		}
	#endif
	}
	CkpvInitialize(int *, papiEvents);
	CkpvAccess(papiEvents) = new int[NUM_PAPI_EVENTS];

#if MEASURE_PAPI_CACHE
	if(PAPI_query_event(PAPI_L1_DCM)==PAPI_OK) {
		CkpvAccess(papiEvents)[0] = PAPI_L1_DCM;
	}else{
		if(CkMyPe()==0){
			CkPrintf("WARNING: PAPI_L1_DCM doesn't exsit on this platform!\n");			
		}
		//if not default to PAPI_TOT_INS
		CkpvAccess(papiEvents)[0] = PAPI_TOT_INS;
	}

	if(PAPI_query_event(PAPI_L2_DCM)==PAPI_OK) {
		CkpvAccess(papiEvents)[1] = PAPI_L2_DCM;
	}else{
		//if not default to PAPI_TOT_CYC
		CkpvAccess(papiEvents)[1] = PAPI_TOT_CYC;
	}	
#elif MEASURE_PAPI_FLOPS
	if(PAPI_query_event(PAPI_FP_INS)==PAPI_OK) {
		CkpvAccess(papiEvents)[0] = PAPI_FP_INS;
	}else{
		if(CkMyPe()==0){
			CkPrintf("WARNING: PAPI_FP_INS doesn't exsit on this platform!\n");
		}
		//if not default to PAPI_TOT_INS
		CkpvAccess(papiEvents)[0] = PAPI_TOT_INS;
	}

	if(PAPI_query_event(PAPI_FMA_INS)==PAPI_OK) {
		CkpvAccess(papiEvents)[1] = PAPI_FMA_INS;
	}else{
		//if not default to PAPI_TOT_CYC
		CkpvAccess(papiEvents)[1] = PAPI_TOT_CYC;
	}
#endif
}
Ejemplo n.º 19
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);
}
Ejemplo n.º 20
0
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;
}
Ejemplo n.º 21
0
void compute() {
#if PAPI
    int EventCode, retval;
    int EventSet = PAPI_NULL;
    long long PAPI_Counters[MAX_COUNTERS];

    /* Initialize the library */
    retval = PAPI_library_init(PAPI_VER_CURRENT);

    if  (retval != PAPI_VER_CURRENT) {
        fprintf(stderr, "PAPI library init error!\n");
        exit(1); 
    }

    /* PAPI create event */
    if (PAPI_create_eventset(&EventSet) != PAPI_OK) {
        fprintf(stderr, "create event set: %s", PAPI_strerror(retval));
    }

    for (int i = 0; i < NUMCOUNTERS; i++) {
        if ( (retval = PAPI_add_named_event(EventSet, events[i])) != PAPI_OK) {
            fprintf(stderr, "add named event: %s", PAPI_strerror(retval));
        }
    }

    retval = PAPI_start(EventSet);
#endif
    
    float matice1[rozmer][rozmer];
    float matice2[rozmer][rozmer];
    float matice3[rozmer][rozmer];
    //Main multiply code
    int j,k,m;
    for(j = 0; j < rozmer; j++)
    {
        for (k = 0; k < rozmer; k++)
        {
            float temp = 0;
            for (m = 0; m < rozmer; m++)
            {
                temp = temp + matice1[j][m] * matice2[m][k];
            }
            matice3[j][k] = temp;
        }
    }

#if PAPI
    retval = PAPI_stop(EventSet, PAPI_Counters);
    if (retval != PAPI_OK) exit(1);

    for (int j = 0; j < NUMCOUNTERS; j++) {
        printf("%20lld %s\n", PAPI_Counters[j], events[j]);
    //    fprintf(stderr, "%lld\n ", PAPI_Counters[j]);
    }
#endif
}
Ejemplo n.º 22
0
void
perf_lib_init(const char *perfcfg, const char *perfout)
{
  int retval;

  retval = PAPI_library_init(PAPI_VER_CURRENT);
  assert(retval == PAPI_VER_CURRENT);

  retval = PAPI_thread_init(pthread_self);
  assert(retval == PAPI_OK);

  if (perfcfg)
    PERF_CONFIG = mystrdup(perfcfg);

  if (perfout)
    PERF_OUT = mystrdup(perfout);

  int max_counters = PAPI_num_counters();
  if (max_counters > MAX_PERF_EVENTS)
    max_counters = MAX_PERF_EVENTS;

  PERF_EVENT_NAMES = (char**)malloc(sizeof(char*) * max_counters);  
  assert(PERF_EVENT_NAMES != NULL);
  memset(PERF_EVENT_NAMES, 0x0, sizeof(char*) * max_counters);

  if (PERF_CONFIG) {
    char line[80];
    FILE *config = fopen(PERF_CONFIG, "r");
    assert(config != NULL);

    while (fgets(line, 80, config) != NULL && NUM_EVENTS < max_counters) {
      if (line[0]=='#')
        continue;
      PERF_EVENT_NAMES[NUM_EVENTS] = mystrdup(line);
      NUM_EVENTS++;
    }
    if (!feof(config))
      fprintf(stderr, "Too many counters added. Only take the first %d.\n", max_counters);

    fclose(config);
  }
  else { /* if no config file is specified, add default events only */
    NUM_EVENTS = sizeof(DEFAULT_EVENTS) / sizeof(char*);
    if (NUM_EVENTS > max_counters) {
      NUM_EVENTS = max_counters;
      fprintf(stderr, "Too many counters added. Only take the first %d.\n", max_counters);
    }
    
    for (int i = 0; i < NUM_EVENTS; i++)
      PERF_EVENT_NAMES[i] = mystrdup(DEFAULT_EVENTS[i]);
  }

  for (int i = 0; i != NUM_EVENTS; ++i)
    PERF_COUNTER_INITIALIZER.value[i] = 0;
}
int main(int argc, char **argv)
{
   pthread_t master;
   pthread_t slave1;
   int result_m, result_s, rc, i;
   int retval;

   /* Setup a random number so compilers can't optimize it out */
   count = rand();
   result_m = count;
   rank = 0;

   for (i = 0; i < LOOPS; i++) {
      result_m = 2 * result_m - i;
   }
   result_s = result_m;

   for (i = 0; i < LOOPS; i++) {
      result_s += i;
   }

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
   {
      printf("Library initialization error! \n");
      exit(-1);
   }

   if ((retval = PAPI_set_debug(PAPI_VERB_ECONT)) != PAPI_OK)
      ERROR_RETURN(retval);

   PAPI_lock(PAPI_USR2_LOCK);
   rc = pthread_create(&master, NULL, Master, NULL);
   if (rc) {
      retval = PAPI_ESYS;
      ERROR_RETURN(retval);
   }
   rc = pthread_create(&slave1, NULL, Slave, NULL);
   if (rc) {
      retval = PAPI_ESYS;
      ERROR_RETURN(retval);
   }
   pthread_join(master, NULL);
   printf("Master: Expected: %d  Recieved: %d\n", result_m, count);
   if (result_m != count)
      ERROR_RETURN(1);
   PAPI_unlock(PAPI_USR2_LOCK);

   pthread_join(slave1, NULL);
   printf("Slave: Expected: %d  Recieved: %d\n", result_s, count);

   if (result_s != count)
      ERROR_RETURN(1);

   exit(0);
}
Ejemplo n.º 24
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);
}
Ejemplo n.º 26
0
void init_papi(void)
{
	int retval;

	/* Initialize the library */

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

}
Ejemplo n.º 27
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 );
}
Ejemplo n.º 28
0
int main(int argc, char **argv) {

	int retval;

	retval = PAPI_library_init(PAPI_VER_CURRENT);
	if (retval != PAPI_VER_CURRENT) {
		fprintf(stderr,"Error! PAPI_library_init %d\n", retval);
	}

	retval = PAPI_query_event(PAPI_TOT_INS);
	if (retval != PAPI_OK) {
		fprintf(stderr,"PAPI_TOT_INS not supported\n");
		exit(1);
	}

	int i;
	int events[1],result;
	long long counts[1];

	long long total=0,average,max=0,min=0x7ffffffffffffffULL;

	events[0]=PAPI_TOT_INS;

	PAPI_start_counters(events,1);

	for(i=0;i<NUM_RUNS;i++) {


		result=instructions_million();

		PAPI_read_counters(counts,1);

		results[i]=counts[0];

 	}

	PAPI_stop_counters(counts,1);


	PAPI_shutdown();

	for(i=0;i<NUM_RUNS;i++) {
		total+=results[i];
		if (results[i]>max) max=results[i];
		if (results[i]<min) min=results[i];
	}

	average=total/NUM_RUNS;
	printf("Average=%lld max=%lld min=%lld\n",average,max,min);

	(void) result;

	return 0;
}
Ejemplo n.º 29
0
void
papi_init() 
{
  int max;

  /* Check PAPI sanity */
  if (PAPI_VER_CURRENT != PAPI_library_init(PAPI_VER_CURRENT))
    papi_eprintf("PAPI_library_init error.\n");

  max = PAPI_num_counters();
  PAPI_reset(max);
}
Ejemplo n.º 30
0
// initialize papi with one thread first
void papi_serial_init(void)
{
	if ( PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT){
		fprintf(stderr, "PAPI library init error!\n");
		exit(1);
	}
	if (( PAPI_thread_init((long unsigned int (*)(void))
					pthread_self )) != PAPI_OK){
		PAPI_perror("PAPI_thread_init");
		exit(1);
	}
}