A proposal for User-Defined Reductions in OpenMP
- A. Duran1, R. Ferrer1, M. Klemm2, B. de Supinski3, E. Ayguadé1
1BSC, 2Intel, 3LLNL
A proposal for User-Defined Reductions in OpenMP A. Duran 1 , R. - - PowerPoint PPT Presentation
A proposal for User-Defined Reductions in OpenMP A. Duran 1 , R. Ferrer 1 , M. Klemm 2 , B. de Supinski 3 , E. Ayguad 1 1 BSC, 2 Intel, 3 LLNL June 16th 2010 Outline Motivation 1 UDR Design rationale 2 Declaring UDRs 3 Array reductions 4
1BSC, 2Intel, 3LLNL
Duran et al. () UDRs in OpenMP June 16th 2010 2 / 28
Motivation
Duran et al. () UDRs in OpenMP June 16th 2010 3 / 28
Motivation
Duran et al. () UDRs in OpenMP June 16th 2010 4 / 28
Motivation
Duran et al. () UDRs in OpenMP June 16th 2010 4 / 28
Motivation
1 complex_t complex_mul ( complex_t a ,
2 3 void example ( complex_t ∗array ,
4
5 6 7 8 9
10
11 12
13
14
15 16
17 18 19 } Duran et al. () UDRs in OpenMP June 16th 2010 5 / 28
Motivation
1 complex_t complex_mul ( complex_t a ,
2 3 void example ( complex_t ∗array ,
4
5 6
7
8 9
10
11
12
13
14
15
16
17 18
19
20 21 } Duran et al. () UDRs in OpenMP June 16th 2010 5 / 28
Motivation
Duran et al. () UDRs in OpenMP June 16th 2010 6 / 28
Motivation
Duran et al. () UDRs in OpenMP June 16th 2010 6 / 28
Motivation
Duran et al. () UDRs in OpenMP June 16th 2010 7 / 28
Motivation
Duran et al. () UDRs in OpenMP June 16th 2010 7 / 28
UDR Design rationale
Duran et al. () UDRs in OpenMP June 16th 2010 8 / 28
UDR Design rationale
Duran et al. () UDRs in OpenMP June 16th 2010 9 / 28
Declaring UDRs
Duran et al. () UDRs in OpenMP June 16th 2010 10 / 28
Declaring UDRs
1
1 #pragma omp declare reduction ( [ template <template−params >]
: type−l i s t ) [ clause ]
1
1 identity( expression | brace−i n i t i a l i z e r C/C++ | constructor [ ( argument−l i s t ) ] C++ ) Duran et al. () UDRs in OpenMP June 16th 2010 11 / 28
Declaring UDRs
1
2 3 #pragma omp declare reduction( complex_mul
4
5 6 void example ( complex_t ∗array ,
7
8 9
10
11
12 13
Duran et al. () UDRs in OpenMP June 16th 2010 12 / 28
Declaring UDRs
Duran et al. () UDRs in OpenMP June 16th 2010 13 / 28
Declaring UDRs
Duran et al. () UDRs in OpenMP June 16th 2010 14 / 28
Array reductions
Duran et al. () UDRs in OpenMP June 16th 2010 15 / 28
Array reductions
Duran et al. () UDRs in OpenMP June 16th 2010 16 / 28
Array reductions
1 const int N = 10; 2 void vector_add
3 4 #pragma omp declare reduction (
5 6 void foo
7
8
9
10
11 12
13
14
Duran et al. () UDRs in OpenMP June 16th 2010 17 / 28
C++ specific extensions
Duran et al. () UDRs in OpenMP June 16th 2010 18 / 28
C++ specific extensions
Duran et al. () UDRs in OpenMP June 16th 2010 19 / 28
C++ specific extensions
1
Duran et al. () UDRs in OpenMP June 16th 2010 19 / 28
C++ specific extensions
Duran et al. () UDRs in OpenMP June 16th 2010 20 / 28
C++ specific extensions
Duran et al. () UDRs in OpenMP June 16th 2010 20 / 28
C++ specific extensions
Duran et al. () UDRs in OpenMP June 16th 2010 21 / 28
C++ specific extensions
1 #pragma omp declare \ 2
3 4 void foo
5
6
7
8 9
10
11
12
Duran et al. () UDRs in OpenMP June 16th 2010 21 / 28
C++ specific extensions
Duran et al. () UDRs in OpenMP June 16th 2010 22 / 28
C++ specific extensions
1 /∗ #pragma omp declare
2
3 4 #pragma omp declare \ 5
6 7 void foo
8
9
10
11 12
13
14
Duran et al. () UDRs in OpenMP June 16th 2010 22 / 28
Conclusions
Duran et al. () UDRs in OpenMP June 16th 2010 23 / 28
Conclusions
Duran et al. () UDRs in OpenMP June 16th 2010 24 / 28
Conclusions
Duran et al. () UDRs in OpenMP June 16th 2010 25 / 28
Conclusions
1 #pragma omp declare \ 2
3
4 #pragma omp declare \ 5
6
Duran et al. () UDRs in OpenMP June 16th 2010 26 / 28
Conclusions
1 i n l i n e void pointMin ( Point ∗a , Point ∗b ) 2 { 3 i f ( a− >x < b− >x ) a− >x = b− >x ; 4 i f ( a− >y < b− >y ) a− >y = b− >y ; 5 } 6 7 i n l i n e void pointMax ( Point ∗a , Point ∗b ) 8 { 9 i f ( a− >x > b− >x ) a− >x = b− >x ; 10 i f ( a− >y > b− >y ) a− >y = b− >y ; 11 } 12 13 #pragma omp declare reduction ( pointMax : Point ∗) 14 #pragma omp declare reduction ( pointMin : Point ∗) 15 16 void findMinMax ( PointVector points , index_t n , Point∗ minPoint , 17 Point∗ maxPoint ) 18 { 19 20 #pragma omp parallel for schedule( static ) \ 21 reduction( pointMin : minPoint ) reduction( pointMax : maxPoint ) 22 for ( index_t i = 1; i < n ; i ++) { 23 i f ( points [ i ] . x < min . x ) minPoint− >x = points [ i ] . x ; 24 i f ( points [ i ] . y < min . y ) minPoint− >y = points [ i ] . y ; 25 i f ( points [ i ] . x > max. x ) maxPoint− >x = points [ i ] . x ; 26 i f ( points [ i ] . y > max. y ) maxPoint− >y = points [ i ] . y ; 27 } 28 } 29 } Duran et al. () UDRs in OpenMP June 16th 2010 27 / 28
Conclusions
1 void array_rvec_add ( rvec ∗a , rvec ∗b , int n ) 2 { 3 for ( int i = 0; i < n ; i ++) { 4 a [ i ] . xx += b [ i ] . xx ; 5 a [ i ] . yy += b [ i ] . yy ; 6 a [ i ] . zz += b [ i ] . zz ; 7 } 8 } 9 10 void real_array_add ( real ∗a , real ∗b , int n ) 11 { 12 for ( int i = 0; i < n ; i ++) a [ i ] += b [ i ] ; 13 } 14 15 #pragma omp declare reduction ( array_rvec_add : rvec [ ] ) identity ( { 0 . 0 , 0 . 0 , 0 . 0 } ) 16 #pragma omp declare reduction ( array_real_add : real [ ] ) identity ( 0 . 0 ) 17 18 . . . 19 neg2 = mdatoms− >nenergrp∗mdatoms− >nenergrp ; 20 21 rvec (∗ pf ) [ mdatoms− >nr ] = ( rvec (∗) [ mdatoms− >nr ] ) f ; 22 rvec (∗ p f s h i f t ) [ SHIFTS ] = ( rvec (∗) [ SHIFTS ] ) p f s h i f t ; 23 real (∗ pegcoul ) [ neg2 ] = ( real (∗) [ neg2 ] ) egcoul ; 24 real (∗pegnb ) [ neg2 ] = ( real (∗) [ neg2 ] ) egnb ; 25 26 #pragma omp parallel for reduction( array_rvec_add : pf , p f s h i f t ) \ 27 reduction( array_real_add : pegcoul , pegnb ) 28 for ( b=0; b<nb ; b++) 29 function ( p f s h i f t , pf , pegcoul , pegnb ) ; 30 31 . . . Duran et al. () UDRs in OpenMP June 16th 2010 28 / 28