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 ); } }
/* Extract and display hardware information for this processor. (Re)Initialize PAPI_flops() and begin counting floating ops. */ static void headerlines( char *title, int TESTS_QUIET ) { const PAPI_hw_info_t *hwinfo = NULL; if ( !TESTS_QUIET ) { if ( papi_print_header( "", 0, &hwinfo ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); printf( "\n%s:\n%8s %12s %12s %8s %8s\n", title, "i", "papi", "theory", "diff", "%error" ); printf ( "-------------------------------------------------------------------------\n" ); } }
int main( int argc, char **argv ) { int i, j = 0, k; int retval; PAPI_event_info_t info; const PAPI_hw_info_t *hwinfo = NULL; command_flags_t flags; int enum_modifier; int numcmp, cid; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Initialize before parsing the input arguments */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } /* Parse the command-line arguments */ parse_args( argc, argv, &flags ); /* Set enum modifier mask */ if ( flags.dear ) enum_modifier = PAPI_NTV_ENUM_DEAR; else if ( flags.darr ) enum_modifier = PAPI_NTV_ENUM_DARR; else if ( flags.iear ) enum_modifier = PAPI_NTV_ENUM_IEAR; else if ( flags.iarr ) enum_modifier = PAPI_NTV_ENUM_IARR; else if ( flags.opcm ) enum_modifier = PAPI_NTV_ENUM_OPCM; else enum_modifier = PAPI_ENUM_EVENTS; if ( !TESTS_QUIET ) { retval = PAPI_set_debug( PAPI_VERB_ECONT ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval ); } } retval = papi_print_header( "Available native events and hardware information.\n", &hwinfo ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); } /* Do this code if an event name was specified on the commandline */ if ( flags.named ) { if ( PAPI_event_name_to_code( flags.name, &i ) == PAPI_OK ) { if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) { printf( "%-30s%s\n%-30s%d\n", "Event name:", info.symbol, "Number of Register Values:", info.count ); printf( "%-29s|%s|\n", "Description:", info.long_descr ); for ( k = 0; k < ( int ) info.count; k++ ) printf( " Register[%2d]: |%s|\n", k, info.name[k] ); /* if unit masks exist but none specified, process all */ if ( !strchr( flags.name, ':' ) ) { if ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { printf( "\nUnit Masks:\n" ); do { retval = PAPI_get_event_info( i, &info ); if ( retval == PAPI_OK ) { if ( parse_unit_masks( &info ) ) { printf( "%-29s|%s|%s|\n", " Mask Info:", info.symbol, info.long_descr ); for ( k = 0; k < ( int ) info.count; k++ ) printf( " Register[%2d]: 0x%08x |%s|\n", k, info.code[k], info.name[k] ); } } } while ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); } } } } else { printf("Sorry, an event by the name '%s' could not be found.\n", flags.name); printf("Is it typed correctly?\n\n"); exit( 1 ); } } else { /* Print *ALL* available events */ numcmp = PAPI_num_components( ); j = 0; for ( cid = 0; cid < numcmp; cid++ ) { const PAPI_component_info_t *component; component=PAPI_get_component_info(cid); /* Skip if requested enumeration not available */ if (( flags.dear ) && !( component->cntr_DEAR_events )) { continue; } if (( flags.darr ) && !( component->data_address_range)) { continue; } if (( flags.iear ) && !( component->cntr_IEAR_events )) { continue; } if (( flags.iarr ) && !( component->instr_address_range )) { continue; } if (( flags.opcm ) && !( component->cntr_OPCM_events )) { continue; } printf( "===============================================================================\n" ); printf( " Events in Component: %s\n",component->name); printf( "===============================================================================\n" ); /* Always ASK FOR the first event */ /* Don't just assume it'll be the first numeric value */ i = 0 | PAPI_NATIVE_MASK | PAPI_COMPONENT_MASK( cid ); /* UGH PAPI_enum_event() really needs a component field */ PAPI_enum_event( &i, PAPI_ENUM_FIRST ); do { memset( &info, 0, sizeof ( info ) ); retval = PAPI_get_event_info( i, &info ); /* This event may not exist */ if ( retval != PAPI_OK ) continue; /* count only events that as supported by host cpu */ j++; print_event( &info, 0 ); /* Does this matter on anything but perfctr? */ if ( flags.details ) { for ( k = 0; k < ( int ) info.count; k++ ) { if ( strlen( info.name[k] ) ) { printf( " Register[%d] Name: %-20s Value: 0x%-28x|\n", k, info.name[k], info.code[k] ); } } } /* modifier = PAPI_NTV_ENUM_GROUPS returns event codes with a groups id for each group in which this native event lives, in bits 16 - 23 of event code terminating with PAPI_ENOEVNT at the end of the list. */ /* This is an IBM Power issue */ if ( flags.groups ) { k = i; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) == PAPI_OK ) { printf( "Groups: " ); do { printf( "%4d", ( ( k & PAPI_NTV_GROUP_AND_MASK ) >> PAPI_NTV_GROUP_SHIFT ) - 1 ); } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) ==PAPI_OK ); printf( "\n" ); } } /* Print umasks */ /* components that don't have them can just ignore */ if ( flags.umask ) { k = i; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { do { retval = PAPI_get_event_info( k, &info ); if ( retval == PAPI_OK ) { if ( parse_unit_masks( &info ) ) print_event( &info, 2 ); } } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); } } printf( "--------------------------------------------------------------------------------\n" ); } while ( PAPI_enum_event( &i, enum_modifier ) == PAPI_OK ); }
int main( int argc, char **argv ) { int i, k, add_count = 0, err_count = 0, unc_count = 0, offcore_count = 0; int retval; PAPI_event_info_t info, info1; const PAPI_hw_info_t *hwinfo = NULL; const PAPI_component_info_t* cmpinfo; char *Intel_i7; int event_code; int numcmp, cid; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Init PAPI library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } retval = papi_print_header( "Test case ALL_NATIVE_EVENTS: Available " "native events and hardware " "information.\n", &hwinfo ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); } numcmp = PAPI_num_components( ); /* we need a little exception processing if it's a Core i7 */ /* Unfortunately, this test never succeeds... */ Intel_i7 = strstr( hwinfo->model_string, "Intel Core i7" ); /* Loop through all components */ for( cid = 0; cid < numcmp; cid++ ) { cmpinfo = PAPI_get_component_info( cid ); if (cmpinfo == NULL) { test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 ); } if (cmpinfo->disabled) { printf( "Name: %-23s %s\n", cmpinfo->name ,cmpinfo->description); printf(" \\-> Disabled: %s\n",cmpinfo->disabled_reason); continue; } /* For platform independence, always ASK FOR the first event */ /* Don't just assume it'll be the first numeric value */ i = 0 | PAPI_NATIVE_MASK; retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid ); do { retval = PAPI_get_event_info( i, &info ); /* Skip OFFCORE and UNCORE events */ /* Adding them will fail currently */ if ( Intel_i7 || ( hwinfo->vendor == PAPI_VENDOR_INTEL ) ) { if ( !strncmp( info.symbol, "UNC_", 4 ) ) { unc_count++; continue; } if ( !strncmp( info.symbol, "OFFCORE_RESPONSE_0", 18 ) ) { offcore_count++; continue; } } /* Enumerate all umasks */ k = i; if ( PAPI_enum_cmp_event(&k, PAPI_NTV_ENUM_UMASKS, cid )==PAPI_OK ) { do { retval = PAPI_get_event_info( k, &info1 ); event_code = ( int ) info1.event_code; if ( check_event( event_code, info1.symbol ) ) { add_count++; } else { err_count++; } } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cid ) == PAPI_OK ); } else { /* Event didn't have any umasks */ event_code = ( int ) info.event_code; if ( check_event( event_code, info.symbol ) ) { add_count++; } else { err_count++; } } } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cid ) == PAPI_OK ); } printf( "\n\nSuccessfully found and added %d events " "(in %d eventsets).\n", add_count , add_count); if ( err_count ) { printf( "Failed to add %d events.\n", err_count ); } if (( unc_count ) || (offcore_count)) { char warning[BUFSIZ]; sprintf(warning,"%d Uncore and %d Offcore events were ignored", unc_count,offcore_count); test_warn( __FILE__, __LINE__, warning, 1 ); } if ( add_count > 0 ) { test_pass( __FILE__, NULL, 0 ); } else { test_fail( __FILE__, __LINE__, "No events added", 1 ); } exit( 1 ); }
int main( int argc, char **argv ) { int retval, i, j; const PAPI_hw_info_t *hwinfo = NULL; const PAPI_mh_info_t *mh; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); retval = papi_print_header ( "Test case hwinfo.c: Check output of PAPI_get_hardware_info.\n", &hwinfo ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); mh = &hwinfo->mem_hierarchy; validate_string( ( char * ) hwinfo->vendor_string, "vendor_string" ); validate_string( ( char * ) hwinfo->model_string, "model_string" ); if ( hwinfo->vendor == PAPI_VENDOR_UNKNOWN ) test_fail( __FILE__, __LINE__, "Vendor unknown", 0 ); if ( hwinfo->cpu_max_mhz == 0.0 ) test_fail( __FILE__, __LINE__, "Mhz unknown", 0 ); if ( hwinfo->ncpu < 1 ) test_fail( __FILE__, __LINE__, "ncpu < 1", 0 ); if ( hwinfo->totalcpus < 1 ) test_fail( __FILE__, __LINE__, "totalcpus < 1", 0 ); /* if ( PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ) < 1 ) test_fail( __FILE__, __LINE__, "get_opt(MAX_HWCTRS) < 1", 0 ); if ( PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ) < 1 ) test_fail( __FILE__, __LINE__, "get_opt(MAX_MPX_CTRS) < 1", 0 );*/ if ( mh->levels < 0 ) test_fail( __FILE__, __LINE__, "max mh level < 0", 0 ); printf( "Max level of TLB or Cache: %d\n", mh->levels ); for ( i = 0; i < mh->levels; i++ ) { for ( j = 0; j < PAPI_MH_MAX_LEVELS; j++ ) { const PAPI_mh_cache_info_t *c = &mh->level[i].cache[j]; const PAPI_mh_tlb_info_t *t = &mh->level[i].tlb[j]; printf( "Level %d, TLB %d: %d, %d, %d\n", i, j, t->type, t->num_entries, t->associativity ); printf( "Level %d, Cache %d: %d, %d, %d, %d, %d\n", i, j, c->type, c->size, c->line_size, c->num_lines, c->associativity ); } } test_pass( __FILE__, 0, 0 ); exit( 1 ); }
int main(int argc, char *argv[]) { float rtime1, rtime2, ptime1, ptime2, mflops; long long flpops; unsigned long int tid; int num_hwcntrs = 0; int fip = 0, retval; float real_time, proc_time; long long flpins; int i; unsigned int EventSet = PAPI_NULL; int count = 0, err_count = 0; PAPI_event_info_t info; long long ( values2[2] )[2]; long long min, max; int PAPI_event, mythreshold = THRESHOLD; char event_name1[PAPI_MAX_STR_LEN]; const PAPI_hw_info_t *hw_info = NULL; int num_events, mask; int num_flops = NUM_FLOPS; 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 ); retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); /* Get hardware info */ hw_info = PAPI_get_hardware_info( ); if ( hw_info == NULL ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); EventSet = add_two_nonderived_events( &num_events, &PAPI_event, &mask ); printf("Using %#x for the overflow event\n",PAPI_event); if ( PAPI_event == PAPI_FP_INS ) { mythreshold = THRESHOLD; } else { #if defined(linux) mythreshold = ( int ) hw_info->cpu_max_mhz * 20000; #else mythreshold = THRESHOLD * 2; #endif } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_flops( NUM_FLOPS ); /* stop the calibration run */ retval = PAPI_stop( EventSet, values2[0] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); /* set up overflow handler */ retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); } /* Start overflow run */ retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( num_flops ); /* stop overflow run */ retval = PAPI_stop( EventSet, values2[1] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); if ( !TESTS_QUIET ) { if ( ( retval = PAPI_event_code_to_name( PAPI_event, event_name1 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); printf( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" ); printf( "---------------------------------------------------------------\n" ); printf( "Threshold for overflow is: %d\n", mythreshold ); printf( "Using %d iterations\n", num_flops ); printf( "-----------------------------------------------\n" ); printf( "Test type : %16d%16d\n", 1, 2 ); printf( OUT_FMT, event_name1, ( values2[0] )[1], ( values2[1] )[1] ); printf( OUT_FMT, "PAPI_TOT_CYC", ( values2[0] )[0], ( values2[1] )[0] ); printf( "Overflows : %16s%16d\n", "", total ); printf( "-----------------------------------------------\n" ); } 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 ( !TESTS_QUIET ) { printf( "Verification:\n" ); #if defined(linux) || defined(__ia64__) || defined(_POWER4) num_flops *= 2; #endif if ( PAPI_event == PAPI_FP_INS || PAPI_event == PAPI_FP_OPS ) { printf( "Row 1 approximately equals %d %d\n", num_flops, num_flops ); } printf( "Column 1 approximately equals column 2\n" ); printf( "Row 3 approximately equals %u +- %u %%\n",( unsigned ) ( ( values2[0] )[1] / ( long long ) mythreshold ),( unsigned ) ( OVR_TOLERANCE * 100.0 ) ); } min = ( long long ) ( ( ( double ) values2[0][1] * ( 1.0 - OVR_TOLERANCE ) ) / ( double ) mythreshold ); max = ( long long ) ( ( ( double ) values2[0][1] * ( 1.0 + OVR_TOLERANCE ) ) / ( double ) mythreshold ); printf( "Overflows: total(%d) > max(%lld) || total(%d) < min(%lld) \n", total, max, total, min ); if ( total > max || total < min ) test_fail( __FILE__, __LINE__, "Overflows", 1 ); printf("Initial thread id is: %lu\n",tid); /* Initialize the PAPI library and get the number of counters available */ if ((num_hwcntrs = PAPI_num_counters()) <= 0) handle_error(1); /* The installation supports PAPI, but has no counters */ if ((num_hwcntrs = PAPI_num_counters()) == 0 ) fprintf(stderr,"Info:: This machine does not provide hardware counters."); printf("This system has %d available counters.\n", num_hwcntrs); if (num_hwcntrs > 2) num_hwcntrs = 2; /* Start counting events */ if (PAPI_start_counters(Events, num_hwcntrs) != PAPI_OK) handle_error(1); if (argc != 8) { printf("\nError :: Ejecutar como : a.out archivo_BD Num_elem archivo_queries Num_queries N_THREADS numero_K Dimension_objetos\n"); return 0; } TOPK = atoi(argv[6]); DIM = atoi(argv[7]); double **DB; double **Consultas; //Cola de consultas int N_QUERIES, N_DB; char str_f[256]; double dato[DIM]; int j; FILE *f_dist, *fquery; Elem *heap, e_temp,*answer; int *acum, N_THREADS; //N_THREADS es el nro. de threads con el que se lanzará la región paralela N_THREADS = atoi(argv[5]); //N_QUERIES es el nro. de consultas N_QUERIES = atoi(argv[4]); N_DB = atoi(argv[2]); printf("\nN_QUERIES = %d\nN_THREADS = %d\n", N_QUERIES, N_THREADS); fflush(stdout); acum = (int *) malloc(sizeof (int)*N_THREADS); for (i = 0; i < N_THREADS; i++) acum[i] = 0; sprintf(str_f, "%s", argv[1]); printf("\nAbriendo %s... ", argv[1]); fflush(stdout); f_dist = fopen(str_f, "r"); printf("OK\n"); fflush(stdout); Consultas = (double **) malloc(sizeof (double *)*N_QUERIES); for (i = 0; i < N_QUERIES; i++) Consultas[i] = (double *) malloc(sizeof (double)*DIM); DB = (double **) malloc(sizeof (double *)*N_DB); for (i = 0; i < N_DB; i++) DB[i] = (double *) malloc(sizeof (double)*DIM); answer = (Elem *)malloc(sizeof(Elem)*N_QUERIES*TOPK); printf("\nCargando DB... "); fflush(stdout); for (i = 0; i < N_DB; i++) { //Usar leedato_cophir() cuando se utilice la BD Cophir para no tener problemas con las "," //if (leedato_cophir(dato, f_dist) == ERROR || feof(f_dist)) if (leedato(dato, f_dist) == ERROR || feof(f_dist)) { printf("\n\nERROR :: N_DB mal establecido\n\n"); fflush(stdout); fclose(f_dist); break; } copiavalor(DB[i], dato); } fclose(f_dist); printf("OK\n"); fflush(stdout); if ((fquery = fopen(argv[3], "r")) == NULL) printf("Error al abrir para lectura el archivo de qeuries: %s\n", argv[3]); else printf("Abriendo para lectura %s\n", argv[3]); printf("\nCargando Consultas... "); fflush(stdout); for (i = 0; i < N_QUERIES; i++) { //Usar leedato_cophir() cuando se utilice la BD Cophir para no tener problemas con las "," //if (leedato_cophir(dato, fquery) == ERROR || feof(fquery)) if (leedato(dato, fquery) == ERROR || feof(fquery)) { printf("\n\nERROR :: N_QUERIES mal establecido, Menos queries que las indicadas\n\n"); fflush(stdout); fclose(fquery); break; } copiavalor(Consultas[i], dato); } fclose(fquery); printf("OK\n"); fflush(stdout); PAPI_start_counters((int*) Events, NUM_EVENTS); omp_set_num_threads(N_THREADS); elapsed_us = PAPI_get_real_usec( ); elapsed_cyc = PAPI_get_real_cyc( ); retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( omp_get_thread_num ) ); if ( retval != PAPI_OK ) { if ( retval == PAPI_ECMP ) test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval ); else test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval ); } #pragma omp parallel shared(Consultas, DB, N_QUERIES, N_DB, N_THREADS, acum, DIM) { float real_time; struct timeval t1, t2; int i, j; Elem *heap, e_temp; double d; int n_elem = 0; int trid = omp_get_thread_num(); //ID del thread int procs = omp_get_num_threads(); //Nro. total de threads double suma = 0; suma = 0; heap = (Elem *) malloc(sizeof (Elem) * TOPK); #pragma omp barrier #pragma omp master { gettimeofday(&t1, 0); } //Cada hilo accede a un subconjunto de las consultas. Cada hio accede de manera circular al arreglo de consultas. for (i = trid; i < N_QUERIES; i += procs) { n_elem = 0; for (j = 0; j < N_DB; j++) { d = distancia(Consultas[i], DB[j]); //Si la distancia del objeto a la consulta es menor que la raíz del heap, entonces se inserta en el heap. La raíz siempre mantiene la mayor de las distancias if(n_elem<TOPK){ e_temp.dist = d; e_temp.ind = j; inserta2(heap, &e_temp, &n_elem); } if (n_elem==TOPK){ if (d < topH(heap, &n_elem)) { e_temp.dist = d; e_temp.ind = j; //Si el heap no está lleno, se inserta el elemento if (n_elem < TOPK) inserta2(heap, &e_temp, &n_elem); //Si el heap está lleno, se inserta el elemento nuevo y se saca el que era antes de mayor de distancia. popush2() hace las operaciones de sacar el elemento mayor e insertar el nuevo. else popush2(heap, &n_elem, &e_temp); }} } //En este punto del código se tienen los K elemntos más cercanos a la consulta en 'heap'. Se pueden extraer con extraer2() for (j = 0; j < TOPK ; j++) { extrae2(heap, &n_elem, &e_temp); answer[i*TOPK+j].ind = e_temp.ind; answer[i*TOPK+j].dist = e_temp.dist; } //Realizamos una operación con los resultados para que el compilador no evite hacer instrucciones que considere que el usuario no utiliza. Simplemente cada hilo suma las distancias de los elementos mas cercanos a la consulta } Thread( 1000000 * ( tid + 1 ) ); fflush(stdout); #pragma omp barrier #pragma omp master { if ( fip > 0 ) { /* Setup PAPI library and begin collecting data from the counters */ if ( fip == 1 ) { if ( ( retval = PAPI_flips( &real_time, &proc_time, &flpins, &mflops ) ) < PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_flips", retval ); } else { if ( ( retval = PAPI_flops( &real_time, &proc_time, &flpins, &mflops ) ) < PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_flops", retval ); } gettimeofday(&t2, 0); real_time = (t2.tv_sec - t1.tv_sec) + (float) (t2.tv_usec - t1.tv_usec) / 1000000; Salida_Multihilo = fopen("Salida_Multihilo.txt", "w"); for (i = 0; i < N_QUERIES; ++i){ fprintf(Salida_Multihilo, "Consulta id:: %d\n",i); for (j = 0; j < TOPK; ++j){ fprintf(Salida_Multihilo,"ind = %d :: dist = %f\n",answer[(i*TOPK)+j].ind,answer[(i*TOPK)+j].dist); } fprintf(Salida_Multihilo, "---------------------------------\n"); } fclose(Salida_Multihilo); printf("\n\nK = %d", TOPK); printf("\nReal Time = %f segundos.\n", real_time); fflush(stdout); if ( fip == 1 ) { if ( ( retval = PAPI_flips( &real_time, &proc_time, &flpins, &mflops ) ) < PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_flips", retval ); } else { if ( ( retval = PAPI_flops( &real_time, &proc_time, &flpins, &mflops ) ) < PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_flops", retval ); } if ( !TESTS_QUIET ) { if ( fip == 1 ) { printf( "Real_time: %f Proc_time: %f Total flpins: ", real_time, proc_time ); } else { printf( "Real_time: %f Proc_time: %f Total flpops: ", real_time, proc_time ); } printf( LLDFMT, flpins ); printf( " MFLOPS: %f\n", mflops ); } } } free(heap); }//end pragma omp parallel 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 ); } const PAPI_hw_info_t *hwinfo = NULL; const PAPI_mh_tlb_info_t *mhinfo = NULL; const PAPI_mh_cache_info_t *mhcacheinfo = NULL; const PAPI_mh_level_t *mhlevel = NULL; if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) exit(1); if ((hwinfo = PAPI_get_hardware_info()) == NULL) exit(1); if ((mhinfo = PAPI_get_hardware_info()) == NULL) exit(1); if ((mhcacheinfo = PAPI_get_hardware_info()) == NULL) exit(1); if ((mhlevel = PAPI_get_hardware_info()) == NULL) exit(1); printf("\n\nA continuación información actual del equipo\n\n"); printf("MH Type %d - Num entries %d - Associativity %d \n",mhinfo->type, mhinfo->num_entries, mhinfo->associativity); printf("Cache MH type %d size %d line size %d num_lines %d Associativity %d\n\n",mhcacheinfo->type, mhcacheinfo->size,mhcacheinfo->line_size, mhcacheinfo->num_lines, mhcacheinfo->associativity); retval=papi_print_header("Available PAPI preset and user defined events plus hardware information.\n",&hwinfo ); printf("Total hardware flops = %lld\n",(float)values[1]); printf("L2 data cache misses is %lld\n", values[0]); retval = PAPI_stop_counters(values, NUM_EVENTS); return 0; }
int main( int argc, char **argv ) { int retval; int code = PAPI_TOT_CYC, last; char event_name[PAPI_MAX_STR_LEN]; const PAPI_hw_info_t *hwinfo = NULL; const PAPI_component_info_t *cmp_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 ); retval = papi_print_header ( "Test case code2name.c: Check limits and indexing of event tables.\n", &hwinfo ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); printf( "Looking for PAPI_TOT_CYC...\n" ); retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); printf( "Found |%s|\n", event_name ); code = PAPI_FP_OPS; printf( "Looking for highest defined preset event (PAPI_FP_OPS): 0x%x...\n", code ); retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); printf( "Found |%s|\n", event_name ); code = PAPI_PRESET_MASK | ( PAPI_MAX_PRESET_EVENTS - 1 ); printf( "Looking for highest allocated preset event: 0x%x...\n", code ); retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) test_continue( "PAPI_event_code_to_name", retval ); else printf( "Found |%s|\n", event_name ); code = PAPI_PRESET_MASK | ( int ) PAPI_NATIVE_AND_MASK; printf( "Looking for highest possible preset event: 0x%x...\n", code ); retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) test_continue( "PAPI_event_code_to_name", retval ); else printf( "Found |%s|\n", event_name ); /* Find the first defined native event */ /* For platform independence, always ASK FOR the first event */ /* Don't just assume it'll be the first numeric value */ code = PAPI_NATIVE_MASK; PAPI_enum_event( &code, PAPI_ENUM_FIRST ); printf( "Looking for first native event: 0x%x...\n", code ); retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } else { printf( "Found |%s|\n", event_name ); } /* Find the last defined native event */ cmp_info = PAPI_get_component_info( 0 ); if ( cmp_info == NULL ) test_fail( __FILE__, __LINE__, "PAPI_get_component_info", PAPI_ESBSTR ); code = PAPI_NATIVE_MASK; PAPI_enum_event( &code, PAPI_ENUM_FIRST ); while ( PAPI_enum_event( &code, PAPI_ENUM_EVENTS ) == PAPI_OK ) { last=code; } code = last; printf( "Looking for last native event: 0x%x...\n", code ); retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } else { printf( "Found |%s|\n", event_name ); } /* Highly doubtful we have this many natives */ /* Turn on all bits *except* PRESET bit and COMPONENT bits */ code = PAPI_PRESET_AND_MASK & PAPI_COMPONENT_AND_MASK; printf( "Looking for highest definable native event: 0x%x...\n", code ); retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) test_continue( "PAPI_event_code_to_name", retval ); else printf( "Found |%s|\n", event_name ); if ( ( retval == PAPI_ENOEVNT ) || ( retval == PAPI_OK ) ) test_pass( __FILE__, 0, 0 ); test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", PAPI_EBUG ); exit( 1 ); }
int main( int argc, char **argv ) { int i, k, add_count = 0, err_count = 0, unc_count = 0, offcore_count = 0; int retval; PAPI_event_info_t info, info1; const PAPI_hw_info_t *hwinfo = NULL; char *Intel_i7; int event_code; const PAPI_component_info_t *s = NULL; int numcmp, cid; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } retval = papi_print_header( "Test case ALL_NATIVE_EVENTS: Available " "native events and hardware " "information.\n", 0, &hwinfo ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); } numcmp = PAPI_num_components( ); /* we need a little exception processing if it's a Core i7 */ /* Unfortunately, this test never succeeds... */ Intel_i7 = strstr( hwinfo->model_string, "Intel Core i7" ); for ( cid = 0; cid < numcmp; cid++ ) { if ( ( s = PAPI_get_component_info( cid ) ) == NULL ) test_fail( __FILE__, __LINE__, "PAPI_get_substrate_info", 2 ); /* For platform independence, always ASK FOR the first event */ /* Don't just assume it'll be the first numeric value */ i = 0 | PAPI_NATIVE_MASK | PAPI_COMPONENT_MASK( cid ); PAPI_enum_event( &i, PAPI_ENUM_FIRST ); do { retval = PAPI_get_event_info( i, &info ); if ( Intel_i7 || ( hwinfo->vendor == PAPI_VENDOR_INTEL ) ) { if ( !strncmp( info.symbol, "UNC_", 4 ) ) { unc_count++; continue; } if ( !strncmp( info.symbol, "OFFCORE_RESPONSE_0", 18 ) ) { offcore_count++; continue; } } if ( s->cntr_umasks ) { k = i; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { do { retval = PAPI_get_event_info( k, &info1 ); event_code = ( int ) info1.event_code; if ( check_event ( event_code, info1.symbol ) ) add_count++; else err_count++; } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); } else { event_code = ( int ) info.event_code; if ( check_event( event_code, info.symbol ) ) add_count++; else err_count++; } } else { event_code = ( int ) info.event_code; if ( s->cntr_groups ) event_code &= ~PAPI_NTV_GROUP_AND_MASK; if ( check_event( event_code, info.symbol ) ) add_count++; else err_count++; } } while ( PAPI_enum_event( &i, PAPI_ENUM_EVENTS ) == PAPI_OK ); } printf( "\n\nSuccessfully found and added %d events (in %d eventsets).\n", add_count , add_count); if ( err_count ) printf( "Failed to add %d events.\n", err_count ); if (( unc_count ) || (offcore_count)) { char warning[BUFSIZ]; sprintf(warning,"%d Uncore and %d Offcore events were ignored", unc_count,offcore_count); test_warn( __FILE__, __LINE__, warning, 1 ); } if ( add_count > 0 ) test_pass( __FILE__, NULL, 0 ); else test_fail( __FILE__, __LINE__, "No events added", 1 ); exit( 1 ); }