本文整理汇总了C++中PAPI_library_init函数的典型用法代码示例。如果您正苦于以下问题:C++ PAPI_library_init函数的具体用法?C++ PAPI_library_init怎么用?C++ PAPI_library_init使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PAPI_library_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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 );
}
示例2: main
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 );
}
示例3: startPapiCounters
//
// 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));
}
示例4: my_papi_start
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 */
}
示例5: initTimers
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);
}
示例6: main
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);
}
示例7: main
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;
}
示例8: PAPI_HW_COUNTER_init
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);
}
}
示例9: main
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);
}
示例10: main
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 ([email protected]) 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);
}
示例11: papi_global_init
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();
}
示例12: initialize_papi
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);
}
}
示例13: init_known_metrics
/* 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;
}
示例14: papi_init
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));
}
}
示例15: start_papi
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));
}
}
}