Download Analyzing Parallel Computation: Amdahl's Law & Efficiency Losses - Prof. Edgar Gabriel and more Study notes Computer Science in PDF only on Docsity!
Edgar Gabriel
COSC 6374
Parallel Computation
Performance Oriented Software Design
Edgar Gabriel
Spring 2009
COSC 6374 – Parallel ComputationEdgar Gabriel
Amdahl’s Law
- Describes the performance gains by enhancing one part
of the overall system (code, computer)
Performance of entire task using the enhancement Speedup = Performance of entire task not using the enhancement
Or
Execution time of the task not using the enhancement Speedup = Execution time of the task using the enhancement
COSC 6374 – Parallel ComputationEdgar Gabriel
Amdahl’s Law (II)
- Amdahl’s Law depends on two factors:
- Fraction of the execution time affected by enhancement
- The improvement gained by the enhancement for this fraction
- Thus _ _ (( 1 ) ) enh enh org enh enh Speedup Execution time =Execution time −Fraction +Fraction
enh
enh enh enh overall org Speedup
Execution time Fraction Fraction Speedup Execution time − +
= = ( 1 )
1 _
_
(1:27:1)
(1:27:2)
COSC 6374 – Parallel ComputationEdgar Gabriel
Amdahl’s Law (III)
0
1
2
3
4
5
6
0 20 40 60 80 100 Speedup enhanced
Speedup total
Fraction enhanced: 20% Fraction enhanced: 40% Fraction enhanced: 60% Fraction enhanced: 80%
enh
overall enh enh Speedup
Speedup =( 1 −Fraction ) +Fraction 1
COSC 6374 – Parallel ComputationEdgar Gabriel
Which are the most time consuming
code section?
- Need to profile the application
- Standard tools in UNIX like environments: gprof,
valgrind
- Valgrind:
- Collection of various tools to analyze an application at runtime - tool=memcheck: memory debugger - tool=cachegrind: estimate on the cache usage of an application - tool=callgrind: provides a trace of the function calls
- Most tools produce an output file (cachegrind..out>
- kcachegrind: visualization tool of valgrind output files
COSC 6374 – Parallel ComputationEdgar Gabriel
COSC 6374 – Parallel ComputationEdgar Gabriel
How to determine the sources of overhead?
- Get detailed data for different sections of the routine
- get an estimate on the number of operations executed
within these section
- Scaling issues:
- For each process we might end up with
- a large no. of time stamps (e.g. k per process)
- a large no. of measurements per time stamp (e.g. m per time stamp) (Execution time of MPI functions, various PAPI counters, user defined values)
- This leads to (n * k * m) data values for the
performance analysis
COSC 6374 – Parallel ComputationEdgar Gabriel
Data reduction for performance Analysis
- Data reduction for the number of processes analyzed:
- Find processors exposing the same behavior and focus on the performance analysis of a single processor of each group
- Data reduction per process:
- Eliminate the measurements exposing the same information
- Data reduction in time:
- Find a small, typical cycle in the application and ignore the rest.
- Automatic, statistical methods inevitable
COSC 6374 – Parallel ComputationEdgar Gabriel
COSC 6374 – Parallel ComputationEdgar Gabriel
PAPI hardware performance counters
- Modern processors expose a some counters which give
some information about the performance
- Limited number of counters
- No. of simultaneous counters and the supported combination of hardware counters depending on the processor
- Available on most modern operating systems:
- Linux: requires recompiling the kernel
- Windows: works right away, however not very accurate due to some restrictions of the OS on context switches
- Requires modification of your source code to insert the
PAPI calls
COSC 6374 – Parallel ComputationEdgar Gabriel
General Counters
- PAPI_FP_OPS Floating point operations
- PAPI_TOT_CYC Total cycles
- PAPI_HW_INT Hardware interrupts
Slides based on a talk and courtesy ofAndreas Knuepfer and Matthias Mueller, Performance ComputingCenter for Information Services and High Technical University Dresden
COSC 6374 – Parallel ComputationEdgar Gabriel
Instruction Counters
- PAPI_TOT_IIS Instructions issued
- PAPI_TOT_INS Instructions completed
- PAPI_INT_INS Integer instructions
- PAPI_LD_INS Load instructions
- PAPI_SR_INS Store instructions
- PAPI_BR_INS Branch instructions
- PAPI_VEC_INS Vector/SIMD instructions
- PAPI_LST_INS Load/store instr. completed
- PAPI_SYC_INS Synch. instr. completed
Slides based on a talk and courtesy ofAndreas Knuepfer and Matthias Mueller, Center for Information Services and High Performance ComputingTechnical University Dresden
COSC 6374 – Parallel ComputationEdgar Gabriel
PAPI manual example
PAPI_library_init(PAPI_VER_CURRENT);
/* query and set up the right events to monitor / i=1; if (PAPI_query_event(PAPI_FP_INS) == PAPI_OK) { Events[i++] = PAPI_FP_INS; } if ( PAPI_query_event(PAPI_TOT_INS) == PAPI_OK) { Events[i++] = PAPI_TOT_INS; } PAPI_start_counters((int ) Events, NUM_EVENTS); / Execute the real code/ do_flops(NUM_FLOPS); PAPI_read_counters(values, NUM_EVENTS);
COSC 6374 – Parallel ComputationEdgar Gabriel
Vampir: Process Timeline
Slides based on a talk and courtesy ofAndreas Knuepfer and Matthias Mueller, Center for Information Services and High Performance ComputingTechnical University Dresden
COSC 6374 – Parallel ComputationEdgar Gabriel
Example: low FP rate due to FP exceptions
Slides based on a talk and courtesy ofAndreas Knuepfer and Matthias Mueller, Performance ComputingCenter for Information Services and High Technical University Dresden
COSC 6374 – Parallel ComputationEdgar Gabriel
Consequences for software design
- Multi-dimensional allocations in C/C++
- Typical code sequence
- memory allocated might not be contiguous
- lowers performance
double **matrix; matrix = (double **) malloc ( dim1 * sizeof(double *); for ( i=0; i< dim1; i++ ) { matrix[i] = (double *) malloc ( dim2 *sizeof(double)); }
COSC 6374 – Parallel ComputationEdgar Gabriel
- What shall you do if one variable requires access along
the row and one variable along the columns?
- Blocked code versions optimize cache usage
for ( i=0; i<dim; i++ ) for ( j=0; j<dim; j++ ) for ( k=0; k<dim; k++) c[i][j] += a[i][k] * b[k][j];
for ( i=0; i<dim; i+=block ) for ( j=0; j<dim; j+=block ) for ( k=0; k<dim; k+=block) for (ii=i; ii<(i+block); ii++) for (jj=j; jj<(j+block); jj++) for (kk=k; kk<(k+block);kk++) c[ii][jj] += a[ii][kk] * b[kk][jj];
COSC 6374 – Parallel ComputationEdgar Gabriel
Comparison operators
- Comparing integer values is orders of magnitudes faster
than comparing strings
- map options to integers and use if or switch statements
- avoid strcmp or similar functions wherever possible
- Avoid unnecessary memory copy operations
- minimizing memory footprint improves cache behavior
- passing pointers to a subroutine instead of making a copy of the data array
- might have however a negative impact on loops within the subroutine, since the compiler does not know boundaries of the array/loop.
COSC 6374 – Parallel ComputationEdgar Gabriel
Object structures
- Rule of thumb: it is better to have an object containing
a vector of data, than having a vector of objects with
one data point each
- fewer indirections
- better cache usage