JNIEXPORT jint JNICALL Java_papi_Wrapper_eventSetAddEvents (JNIEnv *env, jclass UNUSED_ARG(self), jlong eventsetid, jintArray eventsarr) { DEBUG_PRINT("enter"); if (eventsarr == NULL) { DEBUG_PRINT("events array is NULL!"); return PAPI_EINVAL; } int events_count = (*env)->GetArrayLength(env, eventsarr); if (events_count == 0) { return PAPI_OK; } int eventset = (int) eventsetid; DEBUG_PRINT("eventset is %d", eventset); jint *eventsj = (*env)->GetIntArrayElements(env, eventsarr, NULL); int *events = (int *) eventsj; int rc = PAPI_add_events(eventset, events, events_count); (*env)->ReleaseIntArrayElements(env, eventsarr, eventsj, JNI_ABORT); DEBUG_PRINT("returning %d (%s)", rc, PAPI_strerror(rc)); return rc; }
void papi_init_eventset(pid_t pid, int *EventSet) { int retval; if ( (retval = PAPI_create_eventset(EventSet) ) != PAPI_OK) { fprintf(stderr, "PAPI EventSet init error!\n%s\n", PAPI_strerror(retval)); } if ( (retval = PAPI_add_events(*EventSet, global_config.native_events, global_config.nb_papi_events) ) != PAPI_OK) { fprintf(stderr, "PAPI add events error!\n%s\n", PAPI_strerror(retval)); } if ( (retval = PAPI_attach(*EventSet, pid) ) != PAPI_OK) { fprintf(stderr, "PAPI attach error!\n%s\n", PAPI_strerror(retval)); } }
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 }
static void papiBegin() { int rv; // Init library if (!isInit) { rv = PAPI_library_init(PAPI_VER_CURRENT); if (rv != PAPI_VER_CURRENT && rv < 0) { std::cout << "PAPI library version mismatch!\n"; abort(); } if (rv < 0) handle_error(rv); isInit = true; } //setup counters /* Create the Event Set */ if ((rv = PAPI_create_eventset(&papiEventSet)) != PAPI_OK) handle_error(rv); if ((rv = PAPI_add_events(papiEventSet, papiEvents, 2)) != PAPI_OK) handle_error(rv); /* Start counting events in the Event Set */ if ((rv = PAPI_start(papiEventSet)) != PAPI_OK) handle_error(rv); }
void test_papi_initialize(struct test_statistics_t *test_stat) { int test_counter_types[] = { PAPI_FP_OPS, PAPI_L1_DCM }; test_stat->num_counters = sizeof(test_counter_types) / sizeof(int); test_stat->counters = (long long *) malloc(sizeof(long long) * test_stat->num_counters); test_stat->event_set = PAPI_NULL; int retval; if ((retval = PAPI_create_eventset((&test_stat->event_set))) != PAPI_OK ) test_fail(__FILE__, __LINE__, "PAPI_creat_eventset", retval); if ((retval = PAPI_add_events(test_stat->event_set, test_counter_types, test_stat->num_counters)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_events", retval); if ((retval = PAPI_start(test_stat->event_set)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); }
void * thread( void *arg ) { ( void ) arg; /*unused */ int eventset = PAPI_NULL; long long values[PAPI_MPX_DEF_DEG]; int ret = PAPI_register_thread( ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", ret ); ret = PAPI_create_eventset( &eventset ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret ); printf( "Event set %d created\n", eventset ); /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ ret = PAPI_assign_eventset_component( eventset, 0 ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", ret ); } ret = PAPI_set_multiplex( eventset ); if ( ret == PAPI_ENOSUPP) { test_skip( __FILE__, __LINE__, "Multiplexing not supported", 1 ); } else if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", ret ); } ret = PAPI_add_events( eventset, events, numevents ); if ( ret < PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events", ret ); } ret = PAPI_start( eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", ret ); } do_stuff( ); ret = PAPI_stop( eventset, values ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", ret ); } ret = PAPI_cleanup_eventset( eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", ret ); } ret = PAPI_destroy_eventset( &eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret ); } ret = PAPI_unregister_thread( ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret ); return ( NULL ); }
int _hl_rate_calls( float *real_time, float *proc_time, int *events, long long *values, long long *ins, float *rate, int mode ) { long long rt, pt; // current elapsed real and process times in usec int num_events = 2; int retval = 0; HighLevelInfo *state = NULL; if ( ( retval = _internal_check_state( &state ) ) != PAPI_OK ) { return ( retval ); } if ( state->running != HL_STOP && state->running != mode ) { return PAPI_EINVAL; } if ( state->running == HL_STOP ) { switch (mode) { case HL_FLOP: case HL_FLIP: num_events = 1; break; case HL_IPC: break; case HL_EPC: if ( events[2] != 0 ) num_events = 3; break; default: return PAPI_EINVAL; } if (( retval = PAPI_add_events( state->EventSet, events, num_events )) != PAPI_OK ) { _internal_cleanup_hl_info( state ); PAPI_cleanup_eventset( state->EventSet ); return retval; } state->total_ins = 0; state->initial_real_time = state->last_real_time = PAPI_get_real_usec( ); state->initial_proc_time = state->last_proc_time = PAPI_get_virt_usec( ); if ( ( retval = PAPI_start( state->EventSet ) ) != PAPI_OK ) { return retval; } /* Initialize the interface */ state->running = mode; *real_time = 0.0; *proc_time = 0.0; *rate = 0.0; } else { if ( ( retval = PAPI_stop( state->EventSet, values ) ) != PAPI_OK ) { state->running = HL_STOP; return retval; } /* Read elapsed real and process times */ rt = PAPI_get_real_usec(); pt = PAPI_get_virt_usec(); /* Convert to seconds with multiplication because it is much faster */ *real_time = ((float)( rt - state->initial_real_time )) * .000001; *proc_time = ((float)( pt - state->initial_proc_time )) * .000001; state->total_ins += values[0]; switch (mode) { case HL_FLOP: case HL_FLIP: /* Calculate MFLOP and MFLIP rates */ if ( pt > 0 ) { *rate = (float)values[0] / (pt - state->last_proc_time); } else *rate = 0; break; case HL_IPC: case HL_EPC: /* Calculate IPC */ if (values[1]!=0) { *rate = (float) ((float)values[0] / (float) ( values[1])); } break; default: return PAPI_EINVAL; } state->last_real_time = rt; state->last_proc_time = pt; if ( ( retval = PAPI_start( state->EventSet ) ) != PAPI_OK ) { state->running = HL_STOP; return retval; } } *ins = state->total_ins; return PAPI_OK; }
int main (int argc, char **argv) { int i, retval; int EventSet = PAPI_NULL; char *event_name[NUM_EVENTS] = { IFNAME ":rx:bytes", IFNAME ":rx:packets", IFNAME ":tx:bytes", IFNAME ":tx:packets", }; int event_code[NUM_EVENTS] = { 0, 0, 0, 0}; long long event_value[NUM_EVENTS]; int total_events=0; /* 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("Net events by name\n"); } /* Map names to codes */ for ( i=0; i<NUM_EVENTS; i++ ) { retval = PAPI_event_name_to_code( event_name[i], &event_code[i]); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval ); } total_events++; } /* Create and populate the EventSet */ EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval); } retval = PAPI_add_events( EventSet, event_code, NUM_EVENTS); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval); } retval = PAPI_start( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()", retval); } /* generate some traffic * 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, event_value ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()", retval); } if (!TESTS_QUIET) { for ( i=0; i<NUM_EVENTS; i++ ) { printf("%#x %-24s = %lld\n", event_code[i], event_name[i], event_value[i]); } } 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; }
int PAPI_get_info (char *event_name, int finish, int type) { int retval,i; PAPI_Event Event_papi; Event_papi.event_name = event_name; Event_papi.finish = finish; Event_papi.time = gettime(); long long values [PAPI_MAX_EVENT_NUM]; if (type == PAPI_PROCESS) { if ( (retval=PAPI_start(EventSet)) != PAPI_OK) ERROR_RETURN(retval); if ((retval=PAPI_stop(EventSet,values)) != PAPI_OK) ERROR_RETURN(retval); // printf_d ("%s\n", Event_papi.event_name); for (i = 0; i < NUM_EVENT; i++) { Event_papi.papi_event = PAPI_EVENT[i]; Event_papi.data = values[i]; if ((PAPI_info_record (Event_papi)) == -1) printf_d ("[PAPI]GET stream error!!\n"); } return 0; } else if (type == PAPI_THREAD) { int EventSet1 = PAPI_NULL; int *event_codes; event_codes = (int *)calloc (sizeof (int *), NUM_EVENT); for (i = 0; i < NUM_EVENT; ++i) { retval = PAPI_event_name_to_code (PAPI_EVENT[i], &event_codes[i]); if( retval != PAPI_OK ) printf_d("[PAPI]PAPI_event_name_to_code failed, retval = %d\n", retval ); } if ((retval = PAPI_register_thread ()) != PAPI_OK) ERROR_RETURN (retval); if ((retval=PAPI_create_eventset(&EventSet1)) != PAPI_OK) ERROR_RETURN(retval); if ((retval=PAPI_add_events(EventSet1, event_codes, NUM_EVENT)) != PAPI_OK) ERROR_RETURN(retval); if ((retval=PAPI_start(EventSet1)) != PAPI_OK) ERROR_RETURN(retval); if ((retval=PAPI_stop(EventSet1,values)) != PAPI_OK) ERROR_RETURN(retval); for (i = 0; i < NUM_EVENT; i++) { Event_papi.papi_event = PAPI_EVENT[i]; Event_papi.data = values[i]; PAPI_info_record (Event_papi); } if ((PAPI_unregister_thread()) != PAPI_OK) ERROR_RETURN(retval); return 0; } return 1; }
int main(int argc, char **argv) { PAPI_event_info_t info; int i, j, retval; int iters = NUM_FLOPS; double x = 1.1, y; long long t1, t2; long long values[MAXEVENTS], refvalues[MAXEVENTS]; int sleep_time = SLEEPTIME; double valsqsum[MAXEVENTS]; double valsum[MAXEVENTS]; int nevents = MAXEVENTS; int eventset = PAPI_NULL; int events[MAXEVENTS]; events[0] = PAPI_FP_INS; events[1] = PAPI_TOT_INS; events[2] = PAPI_INT_INS; events[3] = PAPI_TOT_CYC; events[4] = PAPI_STL_CCY; events[5] = PAPI_BR_INS; events[6] = PAPI_SR_INS; events[7] = PAPI_LD_INS; events[8] = PAPI_TOT_IIS; events[9] = PAPI_FAD_INS; events[10] = PAPI_BR_TKN; events[11] = PAPI_BR_MSP; events[12] = PAPI_L1_ICA; events[13] = PAPI_L1_DCA; for (i = 0; i < MAXEVENTS; i++) { values[i] = 0; valsqsum[i] = 0; valsum[i] = 0; } if (argc > 1) { if (!strcmp(argv[1], "TESTS_QUIET")) tests_quiet(argc, argv); else { sleep_time = atoi(argv[1]); if (sleep_time <= 0) sleep_time = SLEEPTIME; } } if (!TESTS_QUIET) { printf("\nAccuracy check of multiplexing routines.\n"); printf("Comparing a multiplex measurement with separate measurements.\n\n"); } if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); decide_which_events(events, &nevents); init_multiplex(); /* Find a reasonable number of iterations (each * event active 20 times) during the measurement */ t2 = 10000 * 20 * nevents; /* Target: 10000 usec/multiplex, 20 repeats */ if (t2 > 30e6) test_skip(__FILE__, __LINE__, "This test takes too much time", retval); y = dummy3(x, iters); /* Measure one run */ t1 = PAPI_get_real_usec(); y = dummy3(x, iters); t1 = PAPI_get_real_usec() - t1; if (t1 < 1000000) /* Scale up execution time to match t2 */ { iters = iters * (1000000/t1); printf("Modified iteration count to %d\n\n",iters); } /* Now loop through the items one at a time */ ref_measurements(iters, &eventset, events, nevents, refvalues); /* Now check multiplexed */ if ((retval = PAPI_create_eventset(&eventset))) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ retval = PAPI_assign_eventset_component(eventset, 0); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ((retval = PAPI_set_multiplex(eventset))) test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval); if ((retval = PAPI_add_events(eventset, events, nevents))) test_fail(__FILE__, __LINE__, "PAPI_add_events", retval); printf("\nPAPI multiplexed measurements:\n"); x = 1.0; t1 = PAPI_get_real_usec(); if ((retval = PAPI_start(eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); y = dummy3(x, iters); if ((retval = PAPI_stop(eventset, values))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); t2 = PAPI_get_real_usec(); for (j = 0; j < nevents; j++) { PAPI_get_event_info(events[j], &info); if (!TESTS_QUIET) { printf("%20s = ", info.short_descr); printf(LLDFMT, values[j]); printf("\n"); } } check_values(eventset, events, nevents, values, refvalues); if ((retval = PAPI_remove_events(eventset, events, nevents))) test_fail(__FILE__, __LINE__, "PAPI_remove_events", retval); if ((retval = PAPI_cleanup_eventset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset", retval); if ((retval = PAPI_destroy_eventset(&eventset))) test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval); eventset = PAPI_NULL; /* Now loop through the items one at a time */ ref_measurements(iters, &eventset, events, nevents, refvalues); check_values(eventset, events, nevents, values, refvalues); test_pass(__FILE__, NULL, 0); return 0; }
int main(int nargs, char** args) { real T=5.0, h=0.005, h_alpha; int j, k, N,i; real *a, *b, *y, c_j; real sum_a, sum_b, yp_jp1; clock_t start, finish; if (nargs>1) h = atof(args[1]); if (nargs>1) T = atof(args[2]); N = (int)(T/h+0.5); printf("Serial LoopFusion version---------------\n"); printf("T=%g, h=%g, N=%d\n", T,h,N); a = (real*)malloc((N+1)*sizeof(real)); b = (real*)malloc((N+1)*sizeof(real)); y = (real*)malloc((N+1)*sizeof(real)); h_alpha = pow(h,alpha); start = clock(); for (j=N; j>=0; j--) { b[j] = (pow(j+1,alpha)-pow(j,alpha))/gamma1; a[j] = (pow(j+2,alpha+1)-2.*pow(j+1,alpha+1)+pow(j,alpha+1))/gamma2; } y[0] = y0; int Events[] = {PAPI_L1_TCA,PAPI_L2_TCA,}; int NUM_EVENTS = sizeof(Events)/sizeof(Events[0]); long long res_papi[NUM_EVENTS]; char EventName[128]; int num_hwcntrs = 0; int EventSet = PAPI_NULL; int retval; retval = PAPI_library_init( PAPI_VER_CURRENT ); retval = PAPI_create_eventset( &EventSet ); if (PAPI_add_events( EventSet, Events, NUM_EVENTS) != PAPI_OK){ printf("PAPI_add_events failed\n"); } for (i=0; i<NUM_EVENTS; i++){ res_papi[i] = 0; } if ( PAPI_start( EventSet ) != PAPI_OK){ printf("PAPI_read_counters failed\n"); } for (j=0; j<N; j++) { sum_b = b[j]*f(y[0]); c_j = (pow(j,alpha+1)-(j-alpha)*pow(j+1,alpha))/gamma2; sum_a = c_j*f(y[0]); for (k=1; k<=j; k++) { sum_b += b[j-k]*f(y[k]); sum_a += a[j-k]*f(y[k]); } yp_jp1 = prefix + h_alpha*sum_b; y[j+1] = prefix + h_alpha*(sum_a + f(yp_jp1)/gamma2); } if ( PAPI_stop( EventSet, res_papi ) != PAPI_OK){ printf("PAPI_accum_counters failed\n"); } for (i = 0; i<NUM_EVENTS; i++){ PAPI_event_code_to_name(Events[i], EventName); printf("PAPI Event name: %s, value: %lld\n", EventName, res_papi[i]); } finish=clock(); printf("y[%d]=%e",N,y[N]); printf(" timeusage=%g",(finish-start)/1e6); printf(" GFLOPs=%g\n",2.0*N*(N+1)/(finish-start)/1000.0); free(a); free(b); free(y); PAPI_shutdown (); return 0; }
int main (int argc, char **argv) { int retval,cid,numcmp; int EventSet = PAPI_NULL; long long value; int code; char event_names[MAX_EVENTS][PAPI_MAX_STR_LEN]; int event_codes[MAX_EVENTS]; long long event_values[MAX_EVENTS]; int total_events=0; /* events added so far */ 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 appio 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, "appio") == NULL) { continue; } code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); /* Create and populate the EventSet */ EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval); } while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_names[total_events] ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } if (!TESTS_QUIET) { printf("Added event %s (code=%#x)\n", event_names[total_events], code); } event_codes[total_events++] = code; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } } int fdin,fdout; const char* infile = "/etc/group"; printf("This program will read %s and write it to /dev/null\n", infile); int bytes = 0; char buf[1024]; retval = PAPI_add_events( EventSet, event_codes, total_events); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval); } retval = PAPI_start( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()", retval); } fdin=open(infile, O_RDONLY); if (fdin < 0) perror("Could not open file for reading: \n"); fdout = open("/dev/null", O_WRONLY); if (fdout < 0) perror("Could not open /dev/null for writing: \n"); while ((bytes = read(fdin, buf, 1024)) > 0) { write(fdout, buf, bytes); } retval = PAPI_stop( EventSet, event_values ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_stop()", retval); } close(fdin); close(fdout); int i; if (!TESTS_QUIET) { for ( i=0; i<total_events; i++ ) { printf("%#x %-24s = %lld\n", event_codes[i], event_names[i], event_values[i]); } } 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 (total_events==0) { test_skip(__FILE__,__LINE__,"No appio events found", 0); } test_pass( __FILE__, NULL, 0 ); 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); } return 0; }
void *watch_process(void* _pid) { pid_t pid = *((pid_t*)_pid); printf("%d\n", pid); int retval, EventSet = PAPI_NULL; //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "MEM_LOAD_RETIRED:L1D_HIT", "MEM_LOAD_RETIRED:L2_HIT", "LLC_REFERENCES"}; //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "MEM_LOAD_RETIRED:L2_HIT", "L2_RQSTS:LOADS", "L2_DATA_RQSTS:ANY"}; //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "L1I:READS", "L1D_CACHE_LD:MESI", "L1D_CACHE_ST:MESI"}; //char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "L1D_CACHE_LD:MESI", "L1D_CACHE_ST:MESI", "L2_DATA_RQSTS:ANY" }; char events_name[NB_EVENTS][PAPI_MAX_STR_LEN] = {"UNHALTED_CORE_CYCLES", "INSTRUCTION_RETIRED", "L1I:READS", "L1D_CACHE_LD:MESI", "L1D_CACHE_ST:MESI", "MEM_LOAD_RETIRED:L2_HIT", "L2_RQSTS:LOADS", "L2_DATA_RQSTS:ANY", "BR_INST_RETIRED:ALL_BRANCHES", "BR_INST_EXEC:ANY", "BR_MISP_EXEC:ANY" }; unsigned int native_events[NB_EVENTS]; long long values[NB_EVENTS]; int err; /* Initialize the library */ if ( (err = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) { fprintf(stderr, "PAPI library init error! %d\n", err); exit(1); } if ( (err = PAPI_multiplex_init()) != PAPI_OK) { fprintf(stderr, "PAPI multiplex init error! %d\n", err); exit(1); } if (PAPI_thread_init(pthread_self) != PAPI_OK) { fprintf(stderr, "PAPI thread init error! %d\n", err); exit(1); } //sched_setaffinity(0, 0); //if ((retval = PAPI_set_granularity(PAPI_GRN_MAX)) != PAPI_OK) { // fprintf(stderr, "PAPI set granurality error! %d, %d, %d, %d, %d\n", retval, PAPI_EINVAL, PAPI_ENOEVST, PAPI_ENOCMP, PAPI_EISRUN); // exit(1); //} // Traduction des string en code name_to_code(events_name, NB_EVENTS, native_events); // Vérification des évènements check_events(native_events, NB_EVENTS); if (PAPI_create_eventset(&EventSet) != PAPI_OK) { fprintf(stderr, "PAPI EventSet init error!\n"); exit(1); } if ( (err = PAPI_assign_eventset_component( EventSet, 0 ) ) != PAPI_OK ) { fprintf(stderr, "PAPI assign component error!\n%s\n", PAPI_strerror(err)); exit(1); } if ( ( err = PAPI_set_multiplex(EventSet) ) != PAPI_OK) { fprintf(stderr, "PAPI set multiplex error!\n%s\n", PAPI_strerror(err)); exit(1); } if ( (retval = PAPI_add_events(EventSet, native_events, NB_EVENTS) ) != PAPI_OK) { fprintf(stderr, "PAPI add events error!\n%s\n", PAPI_strerror(retval) ); exit(1); } if (PAPI_attach(EventSet, pid) != PAPI_OK) exit(1); while(while_watch) { /* Start counting */ if (PAPI_start(EventSet) != PAPI_OK) { fprintf(stderr, "PAPI start error!\n"); exit(1); } usleep(1000000); if (PAPI_stop(EventSet, values) != PAPI_OK) { fprintf(stderr, "PAPI stop error!\n"); exit(1); } print_values(events_name, values, NB_EVENTS); } return 0; }
int main(int argc, char **argv) { #if defined(PARALLEL) || defined(PARTIALPAR) omp_set_num_threads(initParams::nprocs); size_t threadID; std::vector<size_t> neighbourThreadId; std::vector<size_t> workingThreadId; std::vector<cv::KeyPoint> globalKeypoints; cv::Mat globalDescriptors; std::vector<size_t> globalIdx(initParams::nprocs/2, 0); std::vector<size_t> levelThreadIdx; #endif cv::Mat frame; cv::VideoCapture cap; class initParams params; // Set motion field norm threshold. If intra-frame motion greater than this threshold carry out outlier classification, rotation compensation, FOE and TTC computations #if !defined(PARALLEL) const float OFThresh = 10.0f; #endif #ifdef USE_PAPI int events[NUM_EVENTS] = { PAPI_L1_DCM, PAPI_L2_DCA, PAPI_L2_DCM }; long long values[NUM_EVENTS+1]; long long start_time = PAPI_get_real_usec(); double total_time = 0.0f; #endif // Initialization of parameters params.set(); if (argc < 3) { std::cerr << "Run Configuration :\n\t./[program name] [input video file] [Total # of frames in video file, 798 for data set-1 and 977 for data set-2]\n"; exit(EXIT_FAILURE); } cap.open(argv[1]); if(!cap.isOpened()){ std::cerr << "Could not access video file: " << argv[1] << std::endl; exit(EXIT_FAILURE); } size_t frameTotal = (size_t) std::atoi(argv[2]); class agast objExtractor; class FindRobustFeatures rFeatures(&objExtractor, ¶ms); cv::Mat tmpDescriptors; std::vector<cv::KeyPoint> tmpKeypoints; #ifdef WRITEDATA analysis::TTCvector.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0.0f); analysis::kpVector.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0); analysis::outliersVector.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0); analysis::matchOutliersVector.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0); analysis::OFNorm.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0); analysis::keypointsVector.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), 0); #endif #if defined(PROF) || defined(WRITEDATA) time_t rawtime; char buffer[80]; time(&rawtime); struct tm * timeinfo = localtime(&rawtime); strftime(buffer,80, "%d-%m-%y_%H-%M-%S", timeinfo); analysis::timeStamp = std::string(buffer); #endif #ifdef PROF analysis::perfTime.resize((size_t)cap.get(CV_CAP_PROP_FRAME_COUNT), std::vector<float>(3, 0.0f)); #endif #ifdef USE_PAPI //********** PAPI Module initialization for performance analysis***********// // Setup PAPI library int ret = PAPI_library_init(PAPI_VER_CURRENT); if (ret != PAPI_VER_CURRENT) { printf("Problem while initializing PAPI library: %s\n", PAPI_strerror(ret)); exit(EXIT_FAILURE); } // Init multiplexer ret = PAPI_multiplex_init(); if (ret != PAPI_OK) { printf("Problem while initializing PAPI multiplexer: %s\n", PAPI_strerror(ret)); exit(1); } // Create event set for the events that we want to measure int eventset = PAPI_NULL; ret = PAPI_create_eventset(&eventset); if (ret != PAPI_OK) { printf("Problem while creating PAPI event set: %s\n", PAPI_strerror(ret)); exit(1); } ret = PAPI_add_event(eventset, PAPI_L1_DCA); if (ret != PAPI_OK) { printf("Problem while adding first PAPI event: %s\n", PAPI_strerror(ret)); exit(1); } // set multiplexer for event set ret = PAPI_set_multiplex(eventset); if (ret != PAPI_OK) { printf("Problem while setting PAPI multiplex: %s\n", PAPI_strerror(ret)); exit(1); } // Add events to event set ret = PAPI_add_events(eventset, events, NUM_EVENTS); if (ret != PAPI_OK) { printf("Problem while adding PAPI events: %s\n", PAPI_strerror(ret)); exit(1); } //********** END INITIALIZATION **********// // Start measuring computation runtime start_time = PAPI_get_real_usec(); // Start measuring events in event set ret = PAPI_start(eventset); if (ret != PAPI_OK) { printf("Problem while starting PAPI eventset: %s\n", PAPI_strerror(ret)); exit(1); } #endif try { while(( (size_t)cap.get(CV_CAP_PROP_POS_FRAMES) + initParams::frameDelay ) < frameTotal) { /****************************PARALLEL-REGION************************************/ #if defined(PARALLEL) || defined(PARTIALPAR) globalIdx.resize(initParams::nprocs/2, 0); analysis::refFrameCount = cap.get(CV_CAP_PROP_POS_FRAMES); analysis::frameCount = cap.get(CV_CAP_PROP_POS_FRAMES); for (size_t i = 0; i < initParams::nprocs; ++i) { if (i % 2 == 0) { workingThreadId.push_back(i); } else { neighbourThreadId.push_back(i); } } #pragma omp parallel num_threads(initParams::nprocs) private(threadID, frame) shared(globalIdx, params, neighbourThreadId, workingThreadId, objExtractor) { threadID = omp_get_thread_num(); // get index of the frame to be handled by a particular thread executed only once: size_t myFrameID = 0; #pragma omp for ordered schedule(static,1) for (size_t i = 0; i < initParams::nprocs; ++i) { #pragma omp ordered myFrameID = threadID + analysis::frameCount; analysis::frameCount++; } class agast objExtractorLoc; while(cap.get(CV_CAP_PROP_POS_FRAMES) != myFrameID) { std::this_thread::sleep_for(std::chrono::milliseconds(5)); } // get first frame and extract new features: cap >> objExtractorLoc.frame; objExtractorLoc.extractFeatures(); if (threadID == initParams::nprocs-1) { objExtractorLoc.frame.copyTo(objExtractor.frame); } #pragma omp master { // keep ref. of the first keypoints and their descriptors: objExtractor.descriptorsOld = objExtractorLoc.descriptors.clone(); objExtractor.keypointsOld = objExtractorLoc.keypoints; #ifdef VISUALIZE objExtractorLoc.frame.copyTo(objExtractor.frameOld); #endif } // follow keypoints over the next framedelay # of frames: objExtractorLoc.swap(); cap >> objExtractorLoc.frame; objExtractorLoc.extractFeatures(); objExtractorLoc.featureMatching(); #if ! defined(WRITEDATA) objExtractorLoc.homographyRANSAC(3.0f); #else objExtractorLoc.homographyRANSAC(3.0f, analysis::outliers, analysis::frameCount, analysis::outliersVector); #endif if((size_t)objExtractorLoc.goodMatches.size() > 5) objExtractorLoc.swapGM(); if (!globalIdx.empty()) { helperFunc::storeGlobal(globalKeypoints, globalDescriptors, objExtractorLoc, threadID, globalIdx, neighbourThreadId); #pragma omp barrier helperFunc::recomputeInterThreadGoodMatches(globalKeypoints, globalDescriptors, objExtractorLoc, workingThreadId, globalIdx, threadID, neighbourThreadId); } #pragma omp master { // re-swaping into global extractors' new points, due to swaping carried out at the end of inter thread matching: objExtractor.keypoints = objExtractorLoc.keypointsOld; objExtractor.descriptors = objExtractorLoc.descriptorsOld.clone(); objExtractor.featureMatching(); rFeatures.homographyRANSAC(3.0f, true); #ifdef VISUALIZE analysis::frameCount = cap.get(CV_CAP_PROP_POS_FRAMES) - 1; #endif } } //Compute velocity projection vectors: rFeatures.compute(); objExtractor.goodMatches.clear(); #ifdef VISUALIZE //Analyze and verify data if necessary: if((char)cv::waitKey(cap.get(CV_CAP_PROP_FPS))==27) break; cv::waitKey(10); #endif /****************************SERIAL-REGION**************************************/ #else //Get first frame and extract new features: analysis::refFrameCount = cap.get(CV_CAP_PROP_POS_FRAMES); #if defined(VISUALIZE) || defined(WRITEIMAGE) cv::Mat refFrame; #endif cap >> objExtractor.frame; #if defined(VISUALIZE) || defined(WRITEIMAGE) objExtractor.frame.copyTo(refFrame); #endif objExtractor.extractFeatures(); #ifdef PROF analysis::perfTime[analysis::frameCount][2] = objExtractor.elapsedTime.count(); #endif // Keep ref. of the first keypoints and their descriptors: objExtractor.descriptors.copyTo(tmpDescriptors); tmpKeypoints = objExtractor.keypoints; // Specify initial features as old features: objExtractor.swap(); // Follow keypoints over the next frames: while((size_t)cap.get(CV_CAP_PROP_POS_FRAMES) < frameTotal ) { analysis::frameCount = cap.get(CV_CAP_PROP_POS_FRAMES); analysis::outliers = 0; cap >> objExtractor.frame; objExtractor.extractFeatures(); #ifdef PROF analysis::perfTime[analysis::frameCount][2] = objExtractor.elapsedTime.count(); analysis::start = std::chrono::high_resolution_clock::now(); #endif // FLANN based matching of keypoints: objExtractor.featureMatching(); #ifdef PROF analysis::stop = std::chrono::high_resolution_clock::now(); analysis::elapsedTime = analysis::stop - analysis::start; analysis::perfTime[analysis::frameCount][0] = analysis::elapsedTime.count(); #endif #ifdef VISUALIZE analysis::visMatchingPts(objExtractor); cv::waitKey(5); #endif #ifdef WRITEDATA analysis::keypointsVector[analysis::frameCount] = std::min((size_t)objExtractor.keypoints.size(), (size_t)objExtractor.keypointsOld.size()); analysis::matchOutliersVector[analysis::frameCount] = analysis::keypointsVector[analysis::frameCount] - (size_t)objExtractor.goodMatches.size(); #endif #ifdef PROF analysis::start = std::chrono::high_resolution_clock::now(); #endif // RANSAC based outlier classification: rFeatures.homographyRANSAC(1.2f, true); #ifdef PROF analysis::stop = std::chrono::high_resolution_clock::now(); analysis::elapsedTime = analysis::stop - analysis::start; analysis::perfTime[analysis::frameCount][1] = analysis::elapsedTime.count(); #endif #ifdef VISUALIZE analysis::visMatchingPts(objExtractor); cv::waitKey(5); #endif float OF = 0.0f; // Calculation of motion field norm makes sense only if matching points are greater than 3 if ((size_t)objExtractor.goodMatches.size() > 3) { // Calculate intra-frame motion flow norm OF = helperFunc::calcMeanOFNorm(objExtractor.keypoints, objExtractor.keypointsOld, objExtractor.goodMatches); } #ifdef WRITEDATA analysis::OFNorm[analysis::frameCount] = helperFunc::calcMeanOFNorm(objExtractor.keypoints, objExtractor.keypointsOld, objExtractor.goodMatches); #endif // Different cases of computation: if ((size_t)objExtractor.goodMatches.size() < 5 || OF >= OFThresh) { // Case 1: Matching(refFrame(n) , refFrame(n+1)) lead to no good matches if (analysis::refFrameCount == (analysis::frameCount - 1) ) { // If large motion field norm was the case then compute ttc: if (OF >= OFThresh) { //Compute velocity projection vectors and ttc: rFeatures.compute(); } // Define latest frame as refFrame analysis::refFrameCount = analysis::frameCount; objExtractor.descriptors.copyTo(tmpDescriptors); tmpKeypoints = objExtractor.keypoints; #if defined(VISUALIZE) || defined(WRITEIMAGE) refFrame = objExtractor.frame.clone(); #endif // Move latest frame data to old objExtractor.swap(); } // Case 2: Matching(refFrame(n+i) , refFrame(n+i+1)) lead to no good matches else { // In case of motion flow greater than threshold compute ttc for the given intra-frame motion otherwise move consistent features and compute motion flow if (OF >= OFThresh) { // Compute velocity projection vectors: rFeatures.compute(); // Define latest frame as refFrame analysis::refFrameCount = analysis::frameCount; objExtractor.descriptors.copyTo(tmpDescriptors); tmpKeypoints = objExtractor.keypoints; #if defined(VISUALIZE) || defined(WRITEIMAGE) refFrame = objExtractor.frame.clone(); #endif // Move latest frame data to old objExtractor.swap(); } else { // Move consistent good matching features to new objExtractor.keypoints.swap(objExtractor.keypointsOld); objExtractor.keypointsOld.swap(tmpKeypoints); cv::Mat placeHolder(objExtractor.descriptors.size(), objExtractor.descriptors.type()); #ifdef OPTIMIZED objExtractor.descriptors.copyTo(placeHolder); #else placeHolder = objExtractor.descriptors.clone(); #endif objExtractor.descriptors.resize(0); objExtractor.descriptorsOld.copyTo(objExtractor.descriptors); tmpDescriptors.copyTo(objExtractor.descriptorsOld ); tmpDescriptors.resize(0); #ifdef OPTIMIZED placeHolder.copyTo(tmpDescriptors); #else tmpDescriptors = placeHolder.clone(); #endif placeHolder.release(); #if defined(VISUALIZE) || defined(WRITEIMAGE) cv::Mat tmpFrame; tmpFrame = objExtractor.frame.clone(); objExtractor.frame = objExtractor.frameOld.clone(); objExtractor.frameOld = refFrame.clone(); refFrame = tmpFrame.clone(); tmpFrame.release(); #endif // Match refFrame features with consistent good matching features uptil refFrame(n+i) objExtractor.featureMatching(); #ifdef VISUALIZE analysis::visMatchingPts(objExtractor, "Using Consistent Features"); cv::waitKey(10); #endif // Calculate Motion Flow norm OF = helperFunc::calcMeanOFNorm(objExtractor.keypoints, objExtractor.keypointsOld, objExtractor.goodMatches); if( OF > OFThresh ) { // Compute motion flow and ttc: rFeatures.compute(); } objExtractor.goodMatches.clear(); objExtractor.keypointsOld = tmpKeypoints; tmpDescriptors.copyTo(objExtractor.descriptorsOld); // Define latest frame as refFrame analysis::refFrameCount = analysis::frameCount; } } } else { objExtractor.swapGM(); } #ifdef VISUALIZE if((char)cv::waitKey(cap.get(CV_CAP_PROP_FPS))==27) break; cv::waitKey(10); #endif } #endif } } catch(cv::Exception) { std::cerr << "Exception @ frame : " << cap.get(CV_CAP_PROP_POS_FRAMES) << "\n"; } #ifdef USE_PAPI // Collect data from the event set if ( PAPI_stop(eventset, values) != PAPI_OK ) { printf("Problem while reading PAPI event set!\n"); exit(EXIT_FAILURE); } // Print results total_time = ((double)(PAPI_get_real_usec() - start_time))/1000000; printf("Computation execution time: %lf seconds\n", total_time); printf("L1 Cache miss rate = %lf \n",((double)values[1])/(values[0])); printf("L2 Cache miss rate = %lf \n",((double)values[3])/(values[2])); #endif /*************************WRITE DATA TO FILE BLOCK********************************/ /*<---------------------------- REGQUIRES SETTING OF PERSONAL PATH TO SAVING GENERATED DATA -------------------------->*/ #ifdef WRITEDATA std::ofstream file; std::string fileName; fileName = "/home/ragesam/gitThesis/testCase/poseFeatures/build/ttc_" + analysis::timeStamp + ".dat"; std::cout << "\nWRITING TTC DATA TO FILE \n"; file.open(fileName); if(!file.is_open()) { std::cout << "\nCan not write TTC to file\n"; std::exit(EXIT_FAILURE); } else { for (size_t i = 0; i < (size_t)analysis::TTCvector.size(); ++i) { file << i << "\t" << analysis::TTCvector[i] << "\t" << analysis::kpVector[i] <<"\n"; } } file.close(); fileName = "/home/ragesam/gitThesis/testCase/poseFeatures/build/outliers_" + analysis::timeStamp + ".dat"; std::cout << "\nWRITING OUTLIER DATA TO FILE \n"; file.open(fileName); if(!file.is_open()) { std::cout << "\nCan not write outliers to file\n"; std::exit(EXIT_FAILURE); } else { file << "Frame #\t# of Keypoints\tFLANN based outliers\tRANSAC based outliers\tIntra-fram projection vector norm\n"; for (size_t i = 0; i < (size_t)analysis::outliersVector.size(); ++i) { file << i << "\t" << analysis::keypointsVector[i] << "\t" << analysis::matchOutliersVector[i] << "\t" << analysis::outliersVector[i] << "\t" << analysis::OFNorm[i] <<"\n"; } } file.close(); #endif #ifdef PROF std::ofstream fileProf; std::string fileNameProf; fileNameProf = "/home/ragesam/gitThesis/testCase/poseFeatures/build/profile_" + analysis::timeStamp + ".dat"; std::cout << "\nWRITING PROFILING DATA TO FILE \n"; fileProf.open(fileNameProf); if(!fileProf.is_open()) { std::cout << "\nCan not write profiling data to file\n"; std::exit(EXIT_FAILURE); } else { fileProf << "Frame #\telapsedTime Matching\telapsedTime RANSAC\telapsedTimeDetection\n"; for (size_t i = 0; i < (size_t)analysis::perfTime.size(); ++i) { fileProf << i << "\t" << analysis::perfTime[i][0] << "\t" << analysis::perfTime[i][1] << "\t" << analysis::perfTime[i][2] << "\n"; } } fileProf.close(); #endif cap.release(); return 0; }
int main( int argc, char *argv[] ) { if ( argc < 4 ) { printf( "Usage: %s format_file input_file output_file\n", argv[0] ); return EXIT_FAILURE; } // For checking the library initialisation int retval; // EventSet for L2 & L3 cache misses and accesses int EventSet = PAPI_NULL; int EventSet1 = PAPI_NULL; // Data pointer for getting the cpu info const PAPI_hw_info_t * hwinfo = NULL; PAPI_mh_info_t mem_hrch; // Initialising the library retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { printf( "Initialisation of Papi failed \n" ); exit( 1 ); } if ( ( hwinfo = PAPI_get_hardware_info() ) == NULL ) { printf( "Unable to access hw info \n" ); return 1; } /* Accessing the cpus per node, threads per core, memory, frequency */ printf( "No. of cpus in one node : %d \n", hwinfo->ncpu ); printf( "Threads per core : %d \n", hwinfo->threads ); printf( "No. of cores per socket : %d \n", hwinfo->cores ); printf( "No. of sockets : %d \n", hwinfo->sockets ); printf( "Total CPUS in the entire system : %d \n", hwinfo->totalcpus ); /* Variables for reading counters of EventSet*/ long long eventValues[NUMEVENTS] = { 0 }; // long long eventFpValue[ NUM_FPEVENTS ] = {0}; char *format = argv[1]; char *file_in = argv[2]; char *file_out = argv[3]; char delim[] = "."; char *cp = (char *) malloc( sizeof(char) * 10 ); cp = strcpy( cp, file_in ); char *token = malloc( sizeof(char) * 10 ); token = strtok( cp, delim ); char * res_file = malloc( sizeof(char) * 30 ); res_file = strcpy( res_file, file_out ); res_file = strcat( res_file, token ); free( cp ); // free( token ); char *csv_file = malloc( sizeof(char) * 30 ); csv_file = strcpy( csv_file, res_file ); FILE *csv_fp = fopen( strcat( csv_file, OPTI ), "w" ); FILE *res_fp = fopen( strcat( res_file, "_psdats.dat" ), "w" ); int status = 0; free( res_file ); free( csv_file ); /** internal cells start and end index*/ int nintci, nintcf; /** external cells start and end index. The external cells are only ghost cells. * They are accessed only through internal cells*/ int nextci, nextcf; /** link cell-to-cell array. Stores topology information*/ int **lcc; /** red-black colouring of the cells*/ int *nboard; /** boundary coefficients for each volume cell */ double *bs, *be, *bn, *bw, *bl, *bh, *bp, *su; // Parameters for measuring the time long long startusec, endusec; /*the total number of points (after conversion to unstructured mesh topology)*/ int nodeCnt; /* the array containing the coordinate of the points * (after conversion to unstructured mesh topology) */ int **points; /* the array containing the mesh elements (after conversion to unstructured mesh topology) */ int **elems; // Creating the eventSets if ( PAPI_create_eventset( &EventSet ) != PAPI_OK ) { printf( "Problem in create eventset \n" ); exit( 1 ); } // Create the Flops eventSet /*if ( PAPI_create_eventset( &EventSet1 ) != PAPI_OK ) { printf( "Problem in creating the flops eventset \n" ); exit(1); }*/ int EventCode[NUMEVENTS] = { PAPI_L2_TCM, PAPI_L2_TCA, PAPI_L3_TCM, PAPI_L3_TCA }; // int EventFpCode[ NUM_FPEVENTS ] = { PAPI_FP_OPS }; // Adding events to the eventset if ( PAPI_add_events( EventSet, EventCode, NUMEVENTS ) != PAPI_OK ) { printf( "Problem in adding events \n" ); exit( 1 ); } /*if( PAPI_add_events( EventSet1, EventFpCode, 1 ) != PAPI_OK ){ printf( "Problem in adding the flops event \n" ); exit( 1 ); }*/ printf( "Success in adding events \n" ); // Start the eventset counters PAPI_start( EventSet ); // PAPI_start( EventSet1 ); startusec = PAPI_get_real_usec(); /* initialization */ // read-in the input file int f_status; if ( !strcmp( format, "bin" ) ) { f_status = read_bin_formatted( file_in, &nintci, &nintcf, &nextci, &nextcf, &lcc, &bs, &be, &bn, &bw, &bl, &bh, &bp, &su, &nboard ); } else if ( !strcmp( format, "txt" ) ) { f_status = read_formatted( file_in, &nintci, &nintcf, &nextci, &nextcf, &lcc, &bs, &be, &bn, &bw, &bl, &bh, &bp, &su, &nboard ); } if ( f_status != 0 ) { printf( "failed to initialize data! \n" ); return EXIT_FAILURE; } // allocate arrays used in gccg int nomax = 3; /** the reference residual*/ double resref = 0.0; /** the ratio between the reference and the current residual*/ double ratio; /** array storing residuals */ double* resvec = (double *) calloc( sizeof(double), ( nintcf + 1 ) ); /** the variation vector -> keeps the result in the end */ double* var = (double *) calloc( sizeof(double), ( nextcf + 1 ) ); /** the computation vectors */ double* direc1 = (double *) calloc( sizeof(double), ( nextcf + 1 ) ); double* direc2 = (double *) calloc( sizeof(double), ( nextcf + 1 ) ); /** additional vectors */ double* cgup = (double *) calloc( sizeof(double), ( nextcf + 1 ) ); double* oc = (double *) calloc( sizeof(double), ( nintcf + 1 ) ); double* cnorm = (double *) calloc( sizeof(double), ( nintcf + 1 ) ); double* adxor1 = (double *) calloc( sizeof(double), ( nintcf + 1 ) ); double* adxor2 = (double *) calloc( sizeof(double), ( nintcf + 1 ) ); double* dxor1 = (double *) calloc( sizeof(double), ( nintcf + 1 ) ); double* dxor2 = (double *) calloc( sizeof(double), ( nintcf + 1 ) ); // initialize the reference residual for ( int nc = nintci; nc <= nintcf; nc++ ) { resvec[nc] = su[nc]; resref = resref + resvec[nc] * resvec[nc]; } resref = sqrt( resref ); if ( resref < 1.0e-15 ) { printf( "i/o - error: residue sum less than 1.e-15 - %lf\n", resref ); return EXIT_FAILURE; } // initialize the arrays for ( int nc = 0; nc <= 10; nc++ ) { oc[nc] = 0.0; cnorm[nc] = 1.0; } for ( int nc = nintci; nc <= nintcf; nc++ ) { cgup[nc] = 0.0; var[nc] = 0.0; } for ( int nc = nextci; nc <= nextcf; nc++ ) { var[nc] = 0.0; cgup[nc] = 0.0; direc1[nc] = 0.0; bs[nc] = 0.0; be[nc] = 0.0; bn[nc] = 0.0; bw[nc] = 0.0; bl[nc] = 0.0; bh[nc] = 0.0; } for ( int nc = nintci; nc <= nintcf; nc++ ) cgup[nc] = 1.0 / bp[nc]; int if1 = 0; int if2 = 0; int iter = 1; int nor = 1; int nor1 = nor - 1; /* finished initalization */ endusec = PAPI_get_real_usec(); // Read the eventSet counters PAPI_read( EventSet, eventValues ); // PAPI_read( EventSet1, eventFpValue ); fprintf( res_fp, "Execution time in microseconds for the initialisation: %lld \n", endusec - startusec ); fprintf( res_fp, "Initialisation.... \n" ); fprintf( res_fp, "INPUT \t PAPI_L2_TCM \t %lld \n", eventValues[0] ); fprintf( res_fp, "INPUT \t PAPI_L2_TCA \t %lld \n", eventValues[1] ); fprintf( res_fp, "INPUT \t PAPI_L3_TCM \t %lld \n", eventValues[2] ); fprintf( res_fp, "INPUT \t PAPI_L3_TCA \t %lld \n", eventValues[3] ); // fprintf( res_fp, "INPUT \t PAPI_FP_OPS \t %lld \n", eventFpValue[0] ); // Cache miss rate calculations float L2_cache_miss_rate, L3_cache_miss_rate; L2_cache_miss_rate = ( (float) eventValues[0] / eventValues[1] ) * 100; L3_cache_miss_rate = ( (float) eventValues[2] / eventValues[3] ) * 100; fprintf( res_fp, "INPUT \t L2MissRate \t %f% \n", L2_cache_miss_rate ); fprintf( res_fp, "INPUT \t L3MissRate \t %f% \n", L3_cache_miss_rate ); fprintf( csv_fp, "Results for the INPUT phase \n" ); fprintf( csv_fp, "%s, %lld, %lld, %lld, %lld, %f, %f \n", OPTI, eventValues[0], eventValues[1], eventValues[2], eventValues[3], L2_cache_miss_rate, L3_cache_miss_rate ); // Resetting the event counters PAPI_reset( EventSet ); // PAPI_reset( EventSet1 ); fprintf( res_fp, "Starting with the computation part \n" ); startusec = PAPI_get_real_usec(); /* start computation loop */ while ( iter < 10000 ) { /* start phase 1 */ // update the old values of direc for ( int nc = nintci; nc <= nintcf; nc++ ) { direc1[nc] = direc1[nc] + resvec[nc] * cgup[nc]; } // compute new guess (approximation) for direc for ( int nc = nintci; nc <= nintcf; nc++ ) { direc2[nc] = bp[nc] * direc1[nc] - bs[nc] * direc1[lcc[0][nc]] - bw[nc] * direc1[lcc[3][nc]] - bl[nc] * direc1[lcc[4][nc]] - bn[nc] * direc1[lcc[2][nc]] - be[nc] * direc1[lcc[1][nc]] - bh[nc] * direc1[lcc[5][nc]]; } /* end phase 1 */ /* start phase 2 */ // execute normalization steps double oc1, oc2, occ; if ( nor1 == 1 ) { oc1 = 0; occ = 0; for ( int nc = nintci; nc <= nintcf; nc++ ) { occ = occ + adxor1[nc] * direc2[nc]; } oc1 = occ / cnorm[1]; for ( int nc = nintci; nc <= nintcf; nc++ ) { direc2[nc] = direc2[nc] - oc1 * adxor1[nc]; direc1[nc] = direc1[nc] - oc1 * dxor1[nc]; } if1++; } else if ( nor1 == 2 ) { oc1 = 0; occ = 0; for ( int nc = nintci; nc <= nintcf; nc++ ) occ = occ + adxor1[nc] * direc2[nc]; oc1 = occ / cnorm[1]; oc2 = 0; occ = 0; for ( int nc = nintci; nc <= nintcf; nc++ ) occ = occ + adxor2[nc] * direc2[nc]; oc2 = occ / cnorm[2]; for ( int nc = nintci; nc <= nintcf; nc++ ) { direc2[nc] = direc2[nc] - oc1 * adxor1[nc] - oc2 * adxor2[nc]; direc1[nc] = direc1[nc] - oc1 * dxor1[nc] - oc2 * dxor2[nc]; } if2++; } cnorm[nor] = 0; double omega = 0; // compute the new residual for ( int nc = nintci; nc <= nintcf; nc++ ) { cnorm[nor] = cnorm[nor] + direc2[nc] * direc2[nc]; omega = omega + resvec[nc] * direc2[nc]; } omega = omega / cnorm[nor]; double resnew = 0.0; for ( int nc = nintci; nc <= nintcf; nc++ ) { var[nc] = var[nc] + omega * direc1[nc]; resvec[nc] = resvec[nc] - omega * direc2[nc]; resnew = resnew + resvec[nc] * resvec[nc]; } resnew = sqrt( resnew ); ratio = resnew / resref; // exit on no improvements of residual if ( ratio <= 1.0e-10 ) break; iter++; // prepare additional arrays for the next iteration step if ( nor == nomax ) nor = 1; else { if ( nor == 1 ) { for ( int nc = nintci; nc <= nintcf; nc++ ) { dxor1[nc] = direc1[nc]; adxor1[nc] = direc2[nc]; } } else if ( nor == 2 ) { for ( int nc = nintci; nc <= nintcf; nc++ ) { dxor2[nc] = direc1[nc]; adxor2[nc] = direc2[nc]; } } nor++; } nor1 = nor - 1; }/* end phase 2 */ /* finished computation loop */ endusec = PAPI_get_real_usec(); // Read the eventSet counters PAPI_read( EventSet, eventValues ); // PAPI_read( EventSet1, eventFpValue ); fprintf( res_fp, "Execution time in microseconds for the computation : %lld \n", endusec - startusec ); fprintf( res_fp, "CALC \t PAPI_L2_TCM \t %lld \n", eventValues[0] ); fprintf( res_fp, "CALC \t PAPI_L2_TCA \t %lld \n", eventValues[1] ); fprintf( res_fp, "CALC \t PAPI_L3_TCM \t %lld \n", eventValues[2] ); fprintf( res_fp, "CALC \t PAPI_L3_TCA \t %lld \n", eventValues[3] ); // fprintf( res_fp, "CALC \t PAPI_FP_OPS \t %lld \n", eventFpValue[0] ); L2_cache_miss_rate = ( (float) eventValues[0] / eventValues[1] ) * 100; L3_cache_miss_rate = ( (float) eventValues[2] / eventValues[3] ) * 100; fprintf( res_fp, "CALC \t L2MissRate \t %f%\n", L2_cache_miss_rate ); fprintf( res_fp, "CALC \t L3MissRate \t %f%\n", L3_cache_miss_rate ); fprintf( csv_fp, "Results for the CALC phase \n" ); fprintf( csv_fp, "%s, %lld, %lld, %lld, %lld, %f, %f \n", OPTI, eventValues[0], eventValues[1], eventValues[2], eventValues[3], L2_cache_miss_rate, L3_cache_miss_rate ); // Resetting the event counters PAPI_reset( EventSet ); // PAPI_reset( EventSet1 ); char *vtk_file = malloc( sizeof(char) * 30 ); fprintf( res_fp, "Starting with the output vtk part \n" ); startusec = PAPI_get_real_usec(); /* write output file */ vol2mesh( nintci, nintcf, lcc, &nodeCnt, &points, &elems ); if( write_result( file_in, file_out, nintci, nintcf, var, iter, ratio ) != 0 ) { printf( "error when trying to write to file %s\n", file_out ); } if( write_result_vtk( strcat( strcpy( vtk_file, file_out ), "SU.vtk" ), nintci, nintcf, nodeCnt, points, elems, su ) != 0 ) { printf( "error when trying to write to vtk file %s\n", "SU.vtk" ); } if( write_result_vtk( strcat( strcpy( vtk_file, file_out ), "CGUP.vtk" ), nintci, nintcf, nodeCnt, points, elems, cgup ) != 0 ) { printf( "error when trying to write to vtk file %s\n", "CGUP.vtk" ); } if( write_result_vtk( strcat( strcpy( vtk_file, file_out ), "VAR.vtk" ), nintci, nintcf, nodeCnt, points, elems, var ) != 0 ) { printf( "error when trying to write to vtk file %s\n", "VAR.vtk" ); } free( vtk_file ); /* finished computation loop */ endusec = PAPI_get_real_usec(); // Read the eventSet counters PAPI_stop( EventSet, eventValues ); // PAPI_stop( EventSet1, eventFpValue ); fprintf( res_fp, "Execution time in microseconds for the output vtk part : %lld \n", endusec - startusec ); fprintf( res_fp, "OUTPUT \t PAPI_L2_TCM \t %lld \n", eventValues[0] ); fprintf( res_fp, "OUTPUT \t PAPI_L2_TCA \t %lld \n", eventValues[1] ); fprintf( res_fp, "OUTPUT \t PAPI_L3_TCM \t %lld \n", eventValues[2] ); fprintf( res_fp, "OUTPUT \t PAPI_L3_TCA \t %lld \n", eventValues[3] ); // fprintf( res_fp, "CALC \t PAPI_FP_OPS \t %lld \n", eventFpValue[0] ); L2_cache_miss_rate = ( (float) eventValues[0] / eventValues[1] ) * 100; L3_cache_miss_rate = ( (float) eventValues[2] / eventValues[3] ) * 100; fprintf( res_fp, "OUTPUT \t L2MissRate \t %f%\n", L2_cache_miss_rate ); fprintf( res_fp, "OUTPUT \t L3MissRate \t %f%\n", L3_cache_miss_rate ); fprintf( csv_fp, "Results for the OUTPUT phase \n" ); fprintf( csv_fp, "%s, %lld, %lld, %lld, %lld, %f, %f \n", OPTI, eventValues[0], eventValues[1], eventValues[2], eventValues[3], L2_cache_miss_rate, L3_cache_miss_rate ); /* Free all the dynamically allocated memory */ free( direc2 ); free( direc1 ); free( dxor2 ); free( dxor1 ); free( adxor2 ); free( adxor1 ); free( cnorm ); free( oc ); free( var ); free( cgup ); free( resvec ); free( su ); free( bp ); free( bh ); free( bl ); free( bw ); free( bn ); free( be ); free( bs ); printf( "Simulation completed successfully!\n" ); fclose( res_fp ); fclose( csv_fp ); return EXIT_SUCCESS; }
int main (int argc, char **argv) { int i, retval; int EventSet = PAPI_NULL; char *event_name[NUM_EVENTS] = { "READ_BYTES", "READ_CALLS", "READ_USEC", "READ_EOF", "READ_SHORT", "READ_ERR", "WRITE_BYTES", "WRITE_CALLS", "WRITE_USEC", "WRITE_ERR", "WRITE_SHORT" }; int event_code[NUM_EVENTS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0}; long long event_value[NUM_EVENTS]; int total_events=0; /* 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("Appio events by name\n"); } /* Map names to codes */ for ( i=0; i<NUM_EVENTS; i++ ) { retval = PAPI_event_name_to_code( event_name[i], &event_code[i]); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval ); } total_events++; } int fdin,fdout; const char* infile = "/etc/group"; if (!TESTS_QUIET) fprintf(stderr, "This program will read %s and write it to /dev/null\n", infile); fdin=open(infile, O_RDONLY); if (fdin < 0) perror("Could not open file for reading: \n"); fdout=open("/dev/null", O_WRONLY); if (fdout < 0) perror("Could not open /dev/null for writing: \n"); int bytes = 0; char buf[1024]; /* Create and populate the EventSet */ EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval); } retval = PAPI_add_events( EventSet, event_code, NUM_EVENTS); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval); } retval = PAPI_start( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()", retval); } while ((bytes = read(fdin, buf, 1024)) > 0) { write(fdout, buf, bytes); } close(fdin); close(fdout); retval = PAPI_stop( EventSet, event_value ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()", retval); } if (!TESTS_QUIET) { for ( i=0; i<NUM_EVENTS; i++ ) { printf("0x%x %-24s = %lld\n", event_code[i], event_name[i], event_value[i]); } } 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 (total_events==0) { test_skip(__FILE__,__LINE__,"No appio events found", 0); } test_pass( __FILE__, NULL, 0 ); return 0; }