本文整理汇总了C++中PAPI_create_eventset函数的典型用法代码示例。如果您正苦于以下问题:C++ PAPI_create_eventset函数的具体用法?C++ PAPI_create_eventset怎么用?C++ PAPI_create_eventset使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PAPI_create_eventset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vt_metric_create
struct vt_metv* vt_metric_create()
{
struct vt_metv* metv;
int retval, i;
if ( nmetrics == 0 )
return NULL;
metv = (struct vt_metv*)malloc(sizeof(struct vt_metv));
if ( metv == NULL )
vt_error();
/* create event set */
metv->EventSet = PAPI_NULL;
retval = PAPI_create_eventset(&metv->EventSet);
if ( retval != PAPI_OK)
vt_metric_error(retval, "PAPI_create_eventset");
for ( i = 0; i < nmetrics; i++ )
{
/* add event to event set */
retval = PAPI_add_event(metv->EventSet, metricv[i]->papi_code);
if ( retval != PAPI_OK )
vt_metric_error(retval, "PAPI_add_event");
}
retval = PAPI_start(metv->EventSet);
if ( retval != PAPI_OK )
vt_metric_error(retval, "PAPI_start");
/*vt_cntl_msg("Counters started");*/
return metv;
}
示例2: 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);
}
}
示例3: check_papi_counter
int
check_papi_counter(char * counter_name)
{
PAPI_event_info_t * info;
int EventSet = PAPI_NULL;
unsigned int event_code = 0x0;
int err;
if ((err=PAPI_create_eventset (&EventSet)) != PAPI_OK){
fprintf(stderr,"Failed to create a PAPI eventset\n");
exit(1);
}
if((err = PAPI_event_name_to_code(counter_name,&event_code)) != PAPI_OK){
return err;
}
if((err = PAPI_add_event (EventSet, event_code)) != PAPI_OK) {
return err;
}
PAPI_remove_named_event (EventSet, counter_name);
if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK ){
printf("********** Call to destroy eventset failed when trying to validate event '%s' **********\n", counter_name);
}
return err;
}
示例4: UNUSED_ARG
JNIEXPORT jint JNICALL Java_papi_Wrapper_eventSetCreate
(JNIEnv *env, jclass UNUSED_ARG(self), jlongArray eventsetidoutarr) {
if (eventsetidoutarr == NULL) {
return PAPI_EINVAL;
}
if ((*env)->GetArrayLength(env, eventsetidoutarr) != 1) {
return PAPI_EINVAL;
}
int eventset = PAPI_NULL;
int rc = PAPI_create_eventset(&eventset);
if (rc != PAPI_OK) {
return rc;
}
jlong *eventsetidoutj = (*env)->GetLongArrayElements(env, eventsetidoutarr, NULL);
long long *eventsetidout = (long long *) eventsetidoutj;
eventsetidout[0] = eventset;
(*env)->ReleaseLongArrayElements(env, eventsetidoutarr, eventsetidoutj, JNI_COMMIT);
DEBUG_PRINT("new eventset is %d", eventset);
return PAPI_OK;
}
示例5: counter_init
void counter_init( int *eventset, int *num_papi_events )
{
char error_str[PAPI_MAX_STR_LEN];
// int events[] = {PAPI_TOT_INS,PAPI_BR_INS,PAPI_SR_INS};
int events[] = {PAPI_TOT_CYC,PAPI_L3_TCM};
int stat;
int thread = omp_get_thread_num();
if( thread == 0 )
printf("Initializing PAPI counters...\n");
*num_papi_events = sizeof(events) / sizeof(int);
if ((stat = PAPI_thread_init((long unsigned int (*)(void)) omp_get_thread_num)) != PAPI_OK) {
PAPI_perror("PAPI_thread_init");
exit(1);
}
if ( (stat= PAPI_create_eventset(eventset)) != PAPI_OK) {
PAPI_perror("PAPI_create_eventset");
exit(1);
}
for( int i = 0; i < *num_papi_events; i++ ) {
if ((stat=PAPI_add_event(*eventset,events[i])) != PAPI_OK) {
PAPI_perror("PAPI_add_event");
exit(1);
}
}
if ((stat=PAPI_start(*eventset)) != PAPI_OK) {
PAPI_perror("PAPI_start");
exit(1);
}
}
示例6: 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));
}
}
示例7: 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 */
}
示例8: vt_metric_test
static void vt_metric_test(void)
{
int i;
int retval;
int EventSet = PAPI_NULL;
/* create event set */
retval = PAPI_create_eventset(&EventSet);
if ( retval != PAPI_OK)
vt_metric_error(retval, "PAPI_create_eventset");
for ( i = 0; i < nmetrics; i++ )
{
/* add event to event set */
retval = PAPI_add_event(EventSet, metricv[i]->papi_code);
if ( retval != PAPI_OK ) {
char errstring[PAPI_MAX_STR_LEN];
sprintf(errstring, "PAPI_add_event(%d:\"%s\")", i, metricv[i]->name);
vt_metric_error(retval, errstring);
}
vt_cntl_msg("Event %s added to event set", metricv[i]->name);
}
retval = PAPI_cleanup_eventset(EventSet);
if ( retval != PAPI_OK )
vt_metric_error(retval, "PAPI_cleanup_eventset");
retval = PAPI_destroy_eventset(&EventSet);
if ( retval != PAPI_OK )
vt_metric_error(retval, "PAPI_destroy_eventset");
vt_cntl_msg("Event set tested OK");
}
示例9: 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));
}
}
}
示例10: int
MeasureTimePAPI::MeasureTimePAPI(unsigned long int (*threadHandle)()) : MeasureTime(), threadHandle(threadHandle)
{
_events = new int[NUM_PAPI_EVENTS];
#ifdef USE_PAPI
_events[0] = PAPI_TOT_CYC;
_events[1] = PAPI_L2_TCM;
_events[2] = PAPI_TOT_INS;
_eventSet = PAPI_NULL;
int initRetVal = PAPI_library_init(PAPI_VER_CURRENT);
if (initRetVal != PAPI_VER_CURRENT && initRetVal > 0)
{
std::cerr << "PAPI library init failed!" << std::endl;
exit(1);
}
if (PAPI_thread_init(threadHandle) != PAPI_OK)
{
std::cerr << "PAPI thread init failed!" << std::endl;
exit(1);
}
if (PAPI_create_eventset(&_eventSet) != PAPI_OK)
{
std::cerr << "PAPI create eventset failed!" << " Error: " << PAPI_create_eventset(&_eventSet) << std::endl;
exit(1);
}
if (PAPI_add_events(_eventSet, _events, NUM_PAPI_EVENTS) != PAPI_OK)
{
std::cerr << "PAPI add events failed!" << std::endl;
exit(1);
}
if (PAPI_start(_eventSet) != PAPI_OK)
{
std::cerr << "PAPI_start_counters - FAILED" << std::endl;
throw ModelicaSimulationError(UTILITY,"PAPI_start_counters - FAILED");
}
#else
_eventSet = 0;
throw ModelicaSimulationError(UTILITY,"Papi not supported!");
#endif
}
示例11: compute
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
}
示例12: main
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 );
}
示例13: check_event
static int
check_event( int event_code, char *name )
{
int retval;
char errstring[PAPI_MAX_STR_LEN];
long long values;
int EventSet = PAPI_NULL;
/* Is there an issue with older machines? */
/* Disable for now, add back once we can reproduce */
// if ( PENTIUM4 ) {
// if ( strcmp( name, "REPLAY_EVENT:BR_MSP" ) == 0 ) {
// return 1;
// }
// }
retval = PAPI_create_eventset( &EventSet );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
retval = PAPI_add_event( EventSet, event_code );
if ( retval != PAPI_OK ) {
printf( "Error adding %s\n", name );
return 0;
} else {
// printf( "Added %s successfully ", name );
}
retval = PAPI_start( EventSet );
if ( retval != PAPI_OK ) {
PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN );
fprintf( stdout, "Error starting %s : %s\n", name, errstring );
} else {
retval = PAPI_stop( EventSet, &values );
if ( retval != PAPI_OK ) {
PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN );
fprintf( stdout, "Error stopping %s: %s\n", name, errstring );
return 0;
} else {
printf( "Added and Stopped %s successfully.\n", name );
}
}
retval=PAPI_cleanup_eventset( EventSet );
if (retval != PAPI_OK ) {
test_warn( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval);
}
retval=PAPI_destroy_eventset( &EventSet );
if (retval != PAPI_OK ) {
test_warn( __FILE__, __LINE__, "PAPI_destroy_eventset", retval);
}
return ( 1 );
}
示例14: metric_test
/* Test whether requested event combination valid */
static void metric_test(void)
{
int i, j;
int retval;
int component;
struct eventmap_t * EventSet[VT_METRIC_MAXNUM];
for (i=0; i<VT_METRIC_MAXNUM; i++)
EventSet[i] = NULL;
for (i=0; i < nmetrics; i++) {
#ifdef PAPIC
/* Preset-counter belong to Component 0! */
component = PAPI_COMPONENT_INDEX(metricv[i]->papi_code);
#else
component = 0;
#endif
/* search for the eventset that matches the counter */
j=0;
while (EventSet[j]!=NULL && j < VT_METRIC_MAXNUM && EventSet[j]->ComponentId!=component){
j++;
}
if (EventSet[j]==NULL) /* create eventset, if no matching found */
{
EventSet[j] = malloc(sizeof(eventmap_t));
EventSet[j]->EventId=PAPI_NULL;
retval = PAPI_create_eventset(&(EventSet[j]->EventId));
if ( retval != PAPI_OK)
metric_error(retval, "PAPI_create_eventset");
EventSet[j]->ComponentId=component;
}
/* add event to event set */
retval = PAPI_add_event(EventSet[j]->EventId, metricv[i]->papi_code);
if ( retval != PAPI_OK ) {
char errstring[PAPI_MAX_STR_LEN];
sprintf(errstring, "PAPI_add_event(%d:\"%s\")", i, metricv[i]->name);
metric_error(retval, errstring);
}
vt_cntl_msg(2, "Event %s added to event set", metricv[i]->name);
}
/* foreach used eventset */
for (i=0; i < VT_METRIC_MAXNUM && EventSet[i]!=NULL; i++)
{
retval = PAPI_cleanup_eventset(EventSet[i]->EventId);
if ( retval != PAPI_OK )
metric_error(retval, "PAPI_cleanup_eventset");
retval = PAPI_destroy_eventset(&(EventSet[i]->EventId));
if ( retval != PAPI_OK )
metric_error(retval, "PAPI_destroy_eventset");
free(EventSet[i]);
}
vt_cntl_msg(2, "Event set tested OK");
}
示例15: my_thread
void *
my_thread( void *v )
{
long num = ( long ) v;
int n;
int EventSet = PAPI_NULL;
long long value;
int retval = PAPI_register_thread( );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
pthread_setspecific( key, v );
count[num] = 0;
iter[num] = 0;
last[num] = start;
if ( PAPI_create_eventset( &EventSet ) != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", 1 );
if ( PAPI_add_event( EventSet, EVENT ) != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_add_event failed", 1 );
if ( PAPI_overflow( EventSet, EVENT, threshold, 0, my_handler ) != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 );
if ( PAPI_start( EventSet ) != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 );
printf( "launched timer in thread %ld\n", num );
for ( n = 1; n <= program_time; n++ ) {
do_cycles( num, 1 );
print_rate( num );
}
PAPI_stop( EventSet, &value );
retval = PAPI_overflow( EventSet, EVENT, 0, 0, my_handler);
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_overflow failed to reset the overflow handler", retval );
if ( PAPI_remove_event( EventSet, EVENT ) != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_remove_event", 1 );
if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", 1 );
if ( PAPI_unregister_thread( ) != PAPI_OK != retval )
test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", 1 );
return ( NULL );
}