• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Biref Introduction to OpenMP
 

Biref Introduction to OpenMP

on

  • 954 views

 

Statistics

Views

Total Views
954
Views on SlideShare
954
Embed Views
0

Actions

Likes
0
Downloads
10
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Biref Introduction to OpenMP Biref Introduction to OpenMP Presentation Transcript

    • OPENMP A Brief Introduction to OpenMP Û[U/ Jerry He hejw06@gmail.com June 19, 2010 Jerry He (Tsinghua University) A Brief Introduction to OpenMP 1 / 31
    • ̇SN 1 OpenMP0 2 OpenMPA5 Jerry He (Tsinghua University) A Brief Introduction to OpenMP 2 / 31
    • ̇SN 1 OpenMP0 2 OpenMPA5 Jerry He (Tsinghua University) A Brief Introduction to OpenMP 2 / 31
    • 0 OpenMP0 Jerry He (Tsinghua University) A Brief Introduction to OpenMP 3 / 31
    • 0 OpenMP0 OpenMP OpenMP´dOpenMP Architecture Review BoardVÞJÑ §¿® 2• É §^u •S•¿1XÚ õ‚§ §S O ˜@• 55º(Compiler Directive)"OpenMP|± ?§Šó•)CŠ ó!C++ÚFortran¶ |±OpenMP ?Èì•)Sun Compiler§GNU CompilerÚIntel Compiler "OpenMPJ ø é¿1Ž{ p Ä–£ã§§S ÏL3 “è ¥;^ pragma5•²gC ¿ã§dd?ÈìŒ ±gÄò§S?1¿1z§¿37‡ƒ?ÓÚp½± 9Ï&" ÀJ Ñù pragma§½ö?ÈìØ| ±OpenMP ž§§SqŒòz•Ï~ §S(˜„•G 1)§“èE,Œ± ~$Š§•´ØU|^õ‚§5 „§S‰1" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 4 / 31
    • 0 OpenMP0 OpenMP dã´˜‡;. OpenMP§S «¿ã§·‚Œ±w §´dG1“ èÚ¿1“è †|¤ §¿1“è «•·‚r§ ‰/¿1«0" Ì‚§˜ ?¿1«§ÒgÄ )Ñõ‡‚§§5¿1 ‰1" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 5 / 31
    • 0 OpenMP0 XÛ3“襦^ ?Èì ˜ MS VS2008: 3Property–>language¥§support openmp. gcc: -fopenmp 'u•õ?Èì |±ë„OpenMP Compilers “èCz <omp.h>Þ©‡ ¿ ˜ #pragma•-=Œ" “è3šopenmpeEU?È" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 6 / 31
    • 0 OpenMP0 OpenMPS• . ¤k ‚§é kêâÑkƒ Ó •µŒ„!ŒÖ!Œ " ˜¬ê⌱úk§Œ±h k" úkêâ ¤k‚§¦^" hkêâ= T‚§¦^" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 7 / 31
    • 0 OpenMP0 OpenMPS• . éA OpenMP§Sp§z‡êâÑk˜‡–¯á5" k2«a.µ Shared •kdêâ ˜‡¢~" ¤k‚§ÓÚÖ " dêâ UCéÙ§‚§ÑŒ„" Private z‡‚§ÑÕkdêâ" Ù§‚§ØU–¯dêâ" UC•=éd‚§Œ„" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 8 / 31
    • 0 OpenMP0 OpenMP$1Å› Jerry He (Tsinghua University) A Brief Introduction to OpenMP 9 / 31
    • 0 OpenMP0 ¿1«Vg M¿1« O˜1“è#pragma omp parallel ^s)ÒrI‡˜3¿1 «S Šé)å5 ¿1«pz‡‚§Ñ¬ ‰1¿ 1«¥ “è" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 10 / 31
    • 0 OpenMP0 ¿1«Vg ››¿1«¥‚§ êþ %@œ¹e§¿1«S‚§ ê=XÚ¥Ø ‡ê •{˜µset OMP NUM THREADS=4 Jerry He (Tsinghua University) A Brief Introduction to OpenMP 11 / 31
    • OpenMPA 5 A OpenMP’s Hello world Program 1 #i n c l u d e <omp . h> 2 #i n c l u d e < s t d i o . h> 3 i n t main ( ) { 4 #pragma omp p a r a l l e l // come i n t o p a r a l l e l i z a t i o n 5 p r i n t f ( ” H e l l o w o r l d from t h r e a d %d , n t h r e a d s %dn” , 6 omp get thread num () , omp get num threads () ) ; 7 } // come o u t o f p a r a l l e l i z a t i o n ÑÑ(J 1 H e l l o w o r l d from t h r e a d 0 , n t h r e a d s 2 2 H e l l o w o r l d from t h r e a d 1 , n t h r e a d s 2 Jerry He (Tsinghua University) A Brief Introduction to OpenMP 12 / 31
    • OpenMPA 5 A OpenMP’s for #pragma omp for ¦^ù‡Šé§·‚ÒŒ±r˜‡forÌ‚ óŠ þ£~Xµ1...N¤© ‰ØÓ‚§"ù‡Šé ¡7L;‹˜ ‡forÌ‚§¦UédforÌ‚ óŠþ?1© " du 21openmp pragma¢3k 憧·‚Œ±r21½õ 1openmp pragmaÜ¿¤˜1" 1 #pragma omp p a r a l l e l 1 #pragma omp p a r a l l e l f o r 2 #pragma omp f o r 2 f o r ( i =0; i <MAX;++ i ) { 3 f o r ( i =0; i <MAX;++ i ) { 3 cout <<i <<e n d l ; 4 cout <<i <<e n d l ; 4 } 5 } Jerry He (Tsinghua University) A Brief Introduction to OpenMP 13 / 31
    • OpenMPA 5 A OpenMP’s for #pragma omp for ¦^ù‡Šé§·‚ÒŒ±r˜‡forÌ‚ óŠ þ£~Xµ1...N¤© ‰ØÓ‚§"ù‡Šé ¡7L;‹˜ ‡forÌ‚§¦UédforÌ‚ óŠþ?1© " du 21openmp pragma¢3k 憧·‚Œ±r21½õ 1openmp pragmaÜ¿¤˜1" 1 #pragma omp p a r a l l e l 1 #pragma omp p a r a l l e l f o r 2 #pragma omp f o r 2 f o r ( i =0; i <MAX;++ i ) { 3 f o r ( i =0; i <MAX;++ i ) { 3 cout <<i <<e n d l ; 4 cout <<i <<e n d l ; 4 } 5 } Jerry He (Tsinghua University) A Brief Introduction to OpenMP 13 / 31
    • OpenMPA 5 A if/shared/privateŠ{ c¡®²J OpenMP S• .§ùA‡'…i^5 ˜êâ –¯ a." 1 int x [5]={1 ,2 ,3 ,4 ,5}; 2 int y [5]={2 ,3 ,4 ,5 ,6}; 3 int c [5]; 4 int a ,b, i ; 5 #pragma omp p a r a l l e l f o r p r i v a t e ( a , b , i ) s h a r e d ( x , y , c ) 6 f o r ( i =0; i <5;++ i ) { 7 a=x [ i ] ; b=y [ i ] ; 8 c [ i ]= a+b ; 9 } 10 f o r ( i =0; i <5;++ i ) 11 p r i n t f ( ”%d ” , c [ i ] ) ; 1 3 5 7 9 11 Jerry He (Tsinghua University) A Brief Introduction to OpenMP 14 / 31
    • OpenMPA 5 A if/shared/privateŠ{ c¡®²J OpenMP S• .§ùA‡'…i^5 ˜êâ –¯ a." 1 int x [5]={1 ,2 ,3 ,4 ,5}; 2 int y [5]={2 ,3 ,4 ,5 ,6}; 3 int c [5]; 4 int a ,b, i ; 5 #pragma omp p a r a l l e l f o r p r i v a t e ( a , b , i ) s h a r e d ( x , y , c ) 6 f o r ( i =0; i <5;++ i ) { 7 a=x [ i ] ; b=y [ i ] ; 8 c [ i ]= a+b ; 9 } 10 f o r ( i =0; i <5;++ i ) 11 p r i n t f ( ”%d ” , c [ i ] ) ; 1 3 5 7 9 11 Jerry He (Tsinghua University) A Brief Introduction to OpenMP 14 / 31
    • OpenMPA 5 A if/shared/privateŠ{ c¡®²J OpenMP S• .§ùA‡'…i^5 ˜êâ –¯ a." 1 int x [5]={1 ,2 ,3 ,4 ,5}; 2 int y [5]={2 ,3 ,4 ,5 ,6}; 3 int c [5]; 4 int a ,b, i ; 5 #pragma omp p a r a l l e l f o r p r i v a t e ( a , b , i ) s h a r e d ( x , y , c ) 6 f o r ( i =0; i <5;++ i ) { 7 a=x [ i ] ; b=y [ i ] ; 8 c [ i ]= a+b ; 9 } 10 f o r ( i =0; i <5;++ i ) 11 p r i n t f ( ”%d ” , c [ i ] ) ; 1 3 5 7 9 11 Jerry He (Tsinghua University) A Brief Introduction to OpenMP 14 / 31
    • OpenMPA 5 A default(none|shared) 1 int x [5]={1 ,2 ,3 ,4 ,5}; 2 int y [5]={2 ,3 ,4 ,5 ,6}; 3 int c [5]; 4 int a ,b, i ; 5 #pragma omp p a r a l l e l f o r d e f a u l t ( s h a r e d ) p r i v a t e ( a , b , i ) 6 f o r ( i =0; i <5;++ i ) { 7 a=x [ i ] ; b=y [ i ] ; 8 c [ i ]= a+b ; 9 } 10 f o r ( i =0; i <5;++ i ) 11 p r i n t f ( ”%d ” , c [ i ] ) ; %@•default(shared)§Øparallel¬S½Â CþÙ§CþÑ •shareda." 핦^default(private) Jerry He (Tsinghua University) A Brief Introduction to OpenMP 15 / 31
    • OpenMPA 5 A default(none|shared) 1 int x [5]={1 ,2 ,3 ,4 ,5}; 2 int y [5]={2 ,3 ,4 ,5 ,6}; 3 int c [5]; 4 int a ,b, i ; 5 #pragma omp p a r a l l e l f o r d e f a u l t ( s h a r e d ) p r i v a t e ( a , b , i ) 6 f o r ( i =0; i <5;++ i ) { 7 a=x [ i ] ; b=y [ i ] ; 8 c [ i ]= a+b ; 9 } 10 f o r ( i =0; i <5;++ i ) 11 p r i n t f ( ”%d ” , c [ i ] ) ; %@•default(shared)§Øparallel¬S½Â CþÙ§CþÑ •shareda." 핦^default(private) Jerry He (Tsinghua University) A Brief Introduction to OpenMP 15 / 31
    • OpenMPA 5 A firstprivate,lastprivate 1 i n t a =10 , b =20 , c =30 , d =40; 2 int i ; 3 p r i n t f ( ” a=%d , b=%d , c=%d , d=%dn” , a , b , c , d ) ; 4 #pragma omp p a r a l l e l f o r p r i v a t e ( a ) f i r s t p r i v a t e ( b , d ) la stp riv ate (c , d) 5 f o r ( i =0; i <1;++ i ) { 6 p r i n t f ( ” a=%d , b=%d c=%d , d=%dn” , a , b , c , d ) ; 7 a++;b++;c++;d++; 8 } 9 p r i n t f ( ” a=%d , b=%d , c=%d , d=%dn” , a , b , c , d ) ; (J 1 a =10 , b =20 , c =30 , d=40 2 a =2,b=20 c =4072624 , d=40 3 a =10 , b =20 , c =4072625 , d=41 Jerry He (Tsinghua University) A Brief Introduction to OpenMP 16 / 31
    • OpenMPA 5 A firstprivate,lastprivate 1 i n t a =10 , b =20 , c =30 , d =40; 2 int i ; 3 p r i n t f ( ” a=%d , b=%d , c=%d , d=%dn” , a , b , c , d ) ; 4 #pragma omp p a r a l l e l f o r p r i v a t e ( a ) f i r s t p r i v a t e ( b , d ) la stp riv ate (c , d) 5 f o r ( i =0; i <1;++ i ) { 6 p r i n t f ( ” a=%d , b=%d c=%d , d=%dn” , a , b , c , d ) ; 7 a++;b++;c++;d++; 8 } 9 p r i n t f ( ” a=%d , b=%d , c=%d , d=%dn” , a , b , c , d ) ; o( privateCþ´™½Â " firstprivateCþ3?¿1«c¬l ¡Ó¶CþDŠ" lastprivateCþ3Ñ¿1«c¬DŠ ¡Ó¶Cþ" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 16 / 31
    • OpenMPA 5 A 8 reduction 1 f l o a t dot product ( f l o a t ∗ a , 1 f l o a t dot product ( f l o a t ∗ a , f l o a t ∗b , i n t N) { f l o a t ∗b , i n t N) { 2 f l o a t sum = 0 . 0 ; 2 f l o a t sum = 0 . 0 ; 3 int i ; 3 int i ; 4 #pragma omp p a r a l l e l f o r 4 #pragma omp p a r a l l e l f o r r e d u c t i o n (+: sum ) p r i v a t e ( s h a r e d ( sum ) p r i v a t e ( i ) i) 5 f o r ( i =0; i <N;++ i ) 5 f o r ( i =0; i <N;++ i ) 6 sum+=a [ i ] ∗ b [ i ] ; 6 sum+=a [ i ] ∗ b [ i ] ; 7 r e t u r n sum ; 7 r e t u r n sum ; 8 } 8 } |± 8 öŠ +, −, ∗, /, · · · Jerry He (Tsinghua University) A Brief Introduction to OpenMP 17 / 31
    • OpenMPA 5 A 8 reduction 1 f l o a t dot product ( f l o a t ∗ a , 1 f l o a t dot product ( f l o a t ∗ a , f l o a t ∗b , i n t N) { f l o a t ∗b , i n t N) { 2 f l o a t sum = 0 . 0 ; 2 f l o a t sum = 0 . 0 ; 3 int i ; 3 int i ; 4 #pragma omp p a r a l l e l f o r 4 #pragma omp p a r a l l e l f o r r e d u c t i o n (+: sum ) p r i v a t e ( s h a r e d ( sum ) p r i v a t e ( i ) i) 5 f o r ( i =0; i <N;++ i ) 5 f o r ( i =0; i <N;++ i ) 6 sum+=a [ i ] ∗ b [ i ] ; 6 sum+=a [ i ] ∗ b [ i ] ; 7 r e t u r n sum ; 7 r e t u r n sum ; 8 } 8 } |± 8 öŠ +, −, ∗, /, · · · Jerry He (Tsinghua University) A Brief Introduction to OpenMP 17 / 31
    • OpenMPA 5 A 8 reduction 1 f l o a t dot product ( f l o a t ∗ a , 1 f l o a t dot product ( f l o a t ∗ a , f l o a t ∗b , i n t N) { f l o a t ∗b , i n t N) { 2 f l o a t sum = 0 . 0 ; 2 f l o a t sum = 0 . 0 ; 3 int i ; 3 int i ; 4 #pragma omp p a r a l l e l f o r 4 #pragma omp p a r a l l e l f o r r e d u c t i o n (+: sum ) p r i v a t e ( s h a r e d ( sum ) p r i v a t e ( i ) i) 5 f o r ( i =0; i <N;++ i ) 5 f o r ( i =0; i <N;++ i ) 6 sum+=a [ i ] ∗ b [ i ] ; 6 sum+=a [ i ] ∗ b [ i ] ; 7 r e t u r n sum ; 7 r e t u r n sum ; 8 } 8 } |± 8 öŠ +, −, ∗, /, · · · Jerry He (Tsinghua University) A Brief Introduction to OpenMP 17 / 31
    • OpenMPA 5 A .«critical 1 f l o a t d o t p r o d u c t ( f l o a t ∗ a , f l o a t ∗b , i n t N) { 2 f l o a t sum = 0 . 0 ; 3 int i ; 4 #pragma omp p a r a l l e l f o r s h a r e d ( sum ) p r i v a t e ( i ) 5 f o r ( i =0; i <N;++ i ) 6 #pragma omp c r i t i c a l 7 sum+=a [ i ] ∗ b [ i ] ; 8 r e t u r n sum ; 9 } „Œ±¦^·¶ .«§½•”þ4 atomic" ë„OpenMP(•© " Jerry He (Tsinghua University) A Brief Introduction to OpenMP 18 / 31
    • OpenMPA 5 A .«critical 1 f l o a t d o t p r o d u c t ( f l o a t ∗ a , f l o a t ∗b , i n t N) { 2 f l o a t sum = 0 . 0 ; 3 int i ; 4 #pragma omp p a r a l l e l f o r s h a r e d ( sum ) p r i v a t e ( i ) 5 f o r ( i =0; i <N;++ i ) 6 #pragma omp c r i t i c a l 7 sum+=a [ i ] ∗ b [ i ] ; 8 r e t u r n sum ; 9 } „Œ±¦^·¶ .«§½•”þ4 atomic" ë„OpenMP(•© " Jerry He (Tsinghua University) A Brief Introduction to OpenMP 18 / 31
    • OpenMPA 5 A ?ÖNÝschedule kn «static,dynamic,guidedn« NÝ•ª" static²þ© §?Èž( ½" dynamic§ ¤˜¬§2©˜ ¬" Ódynamic§ O3u¬ Œ ¬•ê~ " Jerry He (Tsinghua University) A Brief Introduction to OpenMP 19 / 31
    • OpenMPA 5 A ?ÖNÝschedule kn «static,dynamic,guidedn« NÝ•ª" static²þ© §?Èž( ½" dynamic§ ¤˜¬§2©˜ ¬" Ódynamic§ O3u¬ Œ ¬•ê~ " Jerry He (Tsinghua University) A Brief Introduction to OpenMP 19 / 31
    • OpenMPA 5 A ?ÖNÝschedule kn «static,dynamic,guidedn« NÝ•ª" static²þ© §?Èž( ½" dynamic§ ¤˜¬§2©˜ ¬" Ódynamic§ O3u¬ Œ ¬•ê~ " Jerry He (Tsinghua University) A Brief Introduction to OpenMP 19 / 31
    • OpenMPA 5 A ?ÖNÝschedule kn «static,dynamic,guidedn« NÝ•ª" static²þ© §?Èž( ½" dynamic§ ¤˜¬§2©˜ ¬" Ódynamic§ O3u¬ Œ ¬•ê~ " Jerry He (Tsinghua University) A Brief Introduction to OpenMP 19 / 31
    • OpenMPA 5 A ?ÖNÝschedule kn «static,dynamic,guidedn« NÝ•ª" static²þ© §?Èž( ½" dynamic§ ¤˜¬§2©˜ ¬" Ódynamic§ O3u¬ Œ ¬•ê~ " Jerry He (Tsinghua University) A Brief Introduction to OpenMP 19 / 31
    • OpenMPA 5 A ?ÖNÝschedule schedule(<type> [,<chunk>])•½Ì‚NÝ•ª" 1 #pragma omp p a r a l l e l f o r s c h e d u l e ( s t a t i c ) 2 ... 3 #pragma omp p a r a l l e l f o r s c h e d u l e ( dynamic , chunk ) 4 ... 5 #pragma omp p a r a l l e l f o r s c h e d u l e ( g u i d e d , chunk ) 6 ... 7 #pragma omp p a r a l l e l f o r s c h e d u l e ( a u t o ) 8 ... // o n l y s u p p o r t by OpenMP 3 . 0 . Jerry He (Tsinghua University) A Brief Introduction to OpenMP 20 / 31
    • OpenMPA 5 A section 1 #pragma omp s e c t i o n s [ c l a u s e ( s ) ] 2 { 3 #pragma omp s e c t i o n 4 <c o d e b l o c k 1 > 5 #pragma omp s e c t i o n 6 <c o d e b l o c k 2 > 7 #pragma omp s e c t i o n 8 <c o d e b l o c k 3 > 9 ... 10 } |± clauseskµ private firstprivate lastprivate reduction nowait Jerry He (Tsinghua University) A Brief Introduction to OpenMP 21 / 31
    • OpenMPA 5 A section 1 #pragma omp s e c t i o n s [ c l a u s e ( s ) ] 2 { 3 #pragma omp s e c t i o n 4 <c o d e b l o c k 1 > 5 #pragma omp s e c t i o n 6 <c o d e b l o c k 2 > 7 #pragma omp s e c t i o n 8 <c o d e b l o c k 3 > 9 ... 10 } |± clauseskµ private firstprivate lastprivate reduction nowait Jerry He (Tsinghua University) A Brief Introduction to OpenMP 21 / 31
    • OpenMPA 5 A barrier,nowait 1 #pragma omp p a r a l l e l 2 { 3 print (a) ; 4 #pragma omp b a r r i e r 5 print (b) ; 6 #pragma omp f o r 7 ... 8 print (c) ; 9 #pragma omp f o r n o w a i t 10 ... 11 } Øfor §Nõ•- ¡Û¹kbarrier" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 22 / 31
    • OpenMPA 5 A barrier,nowait 1 #pragma omp p a r a l l e l 2 { 3 print (a) ; 4 #pragma omp b a r r i e r 5 print (b) ; 6 #pragma omp f o r 7 ... 8 print (c) ; 9 #pragma omp f o r n o w a i t 10 ... 11 } Øfor §Nõ•- ¡Û¹kbarrier" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 22 / 31
    • OpenMPA 5 A single,master 4,¬“è•k˜‡‚§‰1" 1 #pragma omp p a r a l l e l 2 { 3 print (a) ; 4 #pragma omp s i n g l e 5 print (b) ; 6 #pragma omp m a s t e r 7 print (c) ; 8 } singleÚmaster «O" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 23 / 31
    • OpenMPA 5 A single,master 4,¬“è•k˜‡‚§‰1" 1 #pragma omp p a r a l l e l 2 { 3 print (a) ; 4 #pragma omp s i n g l e 5 print (b) ; 6 #pragma omp m a s t e r 7 print (c) ; 8 } singleÚmaster «O" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 23 / 31
    • OpenMPA 5 A single,master 4,¬“è•k˜‡‚§‰1" 1 #pragma omp p a r a l l e l 2 { 3 print (a) ; 4 #pragma omp s i n g l e 5 print (b) ; 6 #pragma omp m a s t e r 7 print (c) ; 8 } singleÚmaster «O" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 23 / 31
    • OpenMPA 5 A ~^ Û¼ê omp get num procs§ˆ£$1 ‚§ õ?nÅ ?nì‡ê omp get num threads§ˆ£ c¿1«¥¹Ä ‚§‡ê omp get thread num§ˆ£‚§Ò§XJkt‡¹Ä‚§§‚§Ò •0 t-1" omp set num threads§?U¿1‰1“èž‚§ ‡ê"‚§êŒ U‡LŒ^ ?nìê§džõ‡‚§¬ N Ó˜‡?nì þ"d¼ê7L3G1Ü© N^" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 24 / 31
    • OpenMPA 5 A OpenMP 3.0 Task 1 v e c t o r vec (100) ; ¿1i@ 2 vector : : iterator i t ; 3 #pragma omp f o r d e f a u l t ( none ) s h a r e d ( v e c ) 4 f o r ( i t =v e c . b e g i n ( ) ; i t < v e c . end ( ) ; i t ++) 5 // do y o u r work . Jerry He (Tsinghua University) A Brief Introduction to OpenMP 25 / 31
    • OpenMPA 5 A OpenMP 3.0 Task ¿1i@ Jerry He (Tsinghua University) A Brief Introduction to OpenMP 25 / 31
    • OpenMPA 5 A OpenMP 3.0 Task ¿1i@ Jerry He (Tsinghua University) A Brief Introduction to OpenMP 25 / 31
    • OpenMPA 5 A Performance:Amdahl’s law Definition 1 speedup(p) = (1) s + (1 − s)/p p: core nums s: serial code 1-s: can parallel code Jerry He (Tsinghua University) A Brief Introduction to OpenMP 26 / 31
    • OpenMPA 5 A Performance:Amdahl’s law Definition 1 speedup(p) = (1) s + (1 − s)/p p: core nums s: serial code 1-s: can parallel code Jerry He (Tsinghua University) A Brief Introduction to OpenMP 26 / 31
    • OpenMPA 5 A One Myth A program use all cores can scale. éuG1“èkvk•Ð `z" 1 double a [ 1 0 0 0 ] [ 1 0 0 0 ] ; 2 f o r ( i n t i =0; i <1000; i ++) 3 f o r ( i n t j =0; j <1000; j ++) 4 a [ i ] [ j ] = 0 . 0 // o r a [ j ] [ i ] = 0 . 0 5 // c++’ s a r r a y i s row− f i r s t . ´Ä• zÜ© Ñž" S•§– •. . . Jerry He (Tsinghua University) A Brief Introduction to OpenMP 27 / 31
    • OpenMPA 5 A One Myth A program use all cores can scale. éuG1“èkvk•Ð `z" 1 double a [ 1 0 0 0 ] [ 1 0 0 0 ] ; 2 f o r ( i n t i =0; i <1000; i ++) 3 f o r ( i n t j =0; j <1000; j ++) 4 a [ i ] [ j ] = 0 . 0 // o r a [ j ] [ i ] = 0 . 0 5 // c++’ s a r r a y i s row− f i r s t . ´Ä• zÜ© Ñž" S•§– •. . . Jerry He (Tsinghua University) A Brief Introduction to OpenMP 27 / 31
    • OpenMPA 5 A One Myth A program use all cores can scale. éuG1“èkvk•Ð `z" 1 double a [ 1 0 0 0 ] [ 1 0 0 0 ] ; 2 f o r ( i n t i =0; i <1000; i ++) 3 f o r ( i n t j =0; j <1000; j ++) 4 a [ i ] [ j ] = 0 . 0 // o r a [ j ] [ i ] = 0 . 0 5 // c++’ s a r r a y i s row− f i r s t . ´Ä• zÜ© Ñž" S•§– •. . . Jerry He (Tsinghua University) A Brief Introduction to OpenMP 27 / 31
    • OpenMPA 5 A One Myth A program use all cores can scale. éuG1“èkvk•Ð `z" 1 double a [ 1 0 0 0 ] [ 1 0 0 0 ] ; 2 f o r ( i n t i =0; i <1000; i ++) 3 f o r ( i n t j =0; j <1000; j ++) 4 a [ i ] [ j ] = 0 . 0 // o r a [ j ] [ i ] = 0 . 0 5 // c++’ s a r r a y i s row− f i r s t . ´Ä• zÜ© Ñž" S•§– •. . . Jerry He (Tsinghua University) A Brief Introduction to OpenMP 27 / 31
    • OpenMPA 5 A OpenMP Demo Jerry He (Tsinghua University) A Brief Introduction to OpenMP 28 / 31
    • OpenMPA 5 A o( OpenMPJø˜‡ §%rŒ ¿1 ." Œ^u?¿Œ •S•ªXÚ¥" A Ü?ÈìÑ|±OpenMP" 3 ¡|±OpenMP 3.0" OpenMP 3.0¥ taskA5¦ÙA^•2" Sun CompileréOpenMP|±•2" Jerry He (Tsinghua University) A Brief Introduction to OpenMP 29 / 31
    • OpenMPA 5 A ë•] OpenMP(• Õ Free lunch is over Ruud van der Pas: An overview of OpenMP 3.0 Wikipedia OpenMP OpenMP Application Program Interface Version 3.0 May 2008 Summary of OpenMP 3.0 C/C++ Syntax Jerry He (Tsinghua University) A Brief Introduction to OpenMP 30 / 31
    • OpenMPA 5 A Thanks for your attention! Q&A Jerry He (Tsinghua University) ã: A Brief Introduction to OpenMP 31 / 31