??????????? ?? ??? ????????? ?????????? Hyper-Threading ? ??????? OpenMP - PowerPoint PPT Presentation

About This Presentation
Title:

??????????? ?? ??? ????????? ?????????? Hyper-Threading ? ??????? OpenMP

Description:

Hyper-Threading OpenMP Intel Threading Toolkit – PowerPoint PPT presentation

Number of Views:168
Avg rating:3.0/5.0
Slides: 43
Provided by: KlKI3
Category:

less

Transcript and Presenter's Notes

Title: ??????????? ?? ??? ????????? ?????????? Hyper-Threading ? ??????? OpenMP


1
??????????? ?? ??? ????????? ??????????
Hyper-Threading? ??????? OpenMP ?Intel
Threading Toolkit
?????? ???????? maxim.perminov_at_intel.com??????
????? ??, ?????????? Intel
2
??????????
  • ?????????? Hyper-Threading ???????????????
    OpenMP
  • ???? ?????? ????????? ?? OpenMP
  • ???? ?????? ?????????? ????????? ?? OpenMP
  • ??????????? ?????????????????? ? ??????? Intel
    Threading Toolkit

3
??? ???????? ?????????? HT
?????????? ??????????
?????????? ?????????? ??????? ??? ??
?????????? ????????? ????????????? ????????
?? ??????
?????
?????? 1 ?????? 2 ?????? 3
??? Hyper-Threading
????? 2
????? 1
?????? ????????????? ???????? ? ????? ???????
?????????????????? ????????? ???? ????????????
?????????????? ???????
4
?????????? ???? ?????????? ?? ????????? ???????
  • ???? ????????? ???????????????
  • ????????????????? ??????
  • ????????????????? ??????
  • ???? ????????? ???????????????
  • ????? ???????????????? (C, Java)
  • API / ?????????? (Win32, P-??????, MPI)
  • ?????????? ?????? ???????????????? (OpenMP)

OpenMP ????????? ???????? ????????????????? ?????
? ??????
5
??? ????? OpenMP?
  • ?????????? ??????????? ??? ???????
    ?????????????????
  • ?? ?????? ??? C/C
  • ??? ??????????
  • pragma (????????? ???????????) ????? ??????
  • API ? ?????????? Runtime
  • ?????????? ?????????
  • ????????????
  • ?????? ???? ????????????? Hyper-Threading
  • ????????????? ? ??????????????
  • ??????????? ?????????????????
  • ??????????? ??????????? ??????????????

6
?????? ????????????????
  • ?????????????? ???? ????????????-??????????
  • ???????? ????? ????????? ?????? ??????????????
    ???????
  • ?????? ??????? ??????????? ? ????? ???????
    ?????????????????
  • ??? ?????? (??????????) ????????? ???????????? ??
    ?????????
  • ????????????????? ????? ???????????? ??? ?? ?????
  • ???????????????? ????????? ??????????????? ?
    ????????????

???????? ?????
?????? ???????
??????? ?????????????????
7
???? ?????? ????????? ?? OpenMP
  • ??? ?????? OpenMP ?????????? ? omp
  • ?????? parallel ????????? ?????? ?? n ???????
  • ??? ?????? ??????????? n ???!
  • ??? ?????? ???????????? ?????????!

void func() int a, b, c, d a a b c
c d
void func() int a, b, c, d pragma omp
parallel a a b c c d
8
?????????? 1 Hello OpenMP
  • ??????????? ???
  • ???????? ?????? PrimeHT.dsp
  • ????????????? ? ?????????, ????????? ???????????
    ?????????? Microsoft
  • ????????????? ? ?????????, ????????? ??????????
    Intel Compiler ???????? ??????????
  • Hello OpenMP
  • ??????? ? PrimeHT.cpp ????, ???????? ???????? ??
    ??????????????????
  • ???????? ?????? ???? ??????? ?????????????????
    OpenMP
  • ???????? ??? ???????? ??? ???????
    ?????????????????
  • ???????? ? Intel Compiler ????????? OpenMP
  • ????? /Qopenmp
  • ????????????? ? ?????????
  • ?????? ????????? ???????????

9
???????????? ????? ???????
  • ??????????? ?????? ?????? ??????????? ??????
    ???????
  • ?????? sections ??????????? ????????????? ??????

void func() int a, b, c, d pragma omp
parallel pragma omp sections pragma
omp section a a b //one thread pragma
omp section c c d //another thread
10
??????, ??????????? ??????
  • ??????, ??????????? ??????, ????? ?????????? ?
    ??????? parallel

void func() int a, b, c, d pragma omp
parallel sections pragma omp section a
a b //one thread pragma omp section c c
d //another thread
  • ??? ???????, ????????????? ???????????

pragma omp parallel sections pragma omp
section do_compress() pragma omp
section do_encrypt()
pragma omp parallel sections?????????????????
?? ?????? ???????!
11
?????????? 2 Parallel Sections
  • ???????? ???????? ???? ?? ???
  • ????????, from .. to/2 ? to/2 .. to
  • ?????????? ????? ??????? ? ??????????? parallel
    sections
  • ????????? ?????? ??????? ? ???? ??????
  • ????????????? ? ????????? (???????????)
    ????????? ?????????

12
?????????? ?????? ?? ??????
  • ?????? for ??????????? ????? ???????
  • ???? ????????? ???????? ??????? ???
  • ????? ??????, ??? ???????? ? ??????????? ????????

void func() int aN, sum 0 pragma omp
parallel for for (int i 0 i lt N i) sum
ai
pragma omp parallel for????????????????? ??
?????? ??????!
13
?????????? 3 Parallel For
  • ???????????? ???? ???????? ????
  • from .. to
  • ?????????? ????? ??????? ? ??????????? parallel
    for
  • ????????????? ? ?????????
  • ????????? ?????????

14
??????? ?????????? ??????????
  • ??????? ??????? 1 ??? ??????????, ????????????
    ??? omp parallel, ???????? ??????????? ??? ????
    ???????
  • ??????? ??????? 2 ??? ??????????, ????????????
    ?????? omp parallel, ???????? ?????????? ???
    ??????? ??????
  • ??????? ?????????? ? ?????? omp for, ???????
    ????? ?????? ??????? ??? ??????? ??????
  • ????? ??????? 1 ??????????, ??????????? ?
    shared(), ???????? ??????????? ??? ???? ???????
  • ????? ??????? 2 ??????????, ??????????? ?
    private(), ???????? ?????????? ??? ??????? ??????

15
????? ?????????? ?????????, ? ????? ???????????
void func() int a, i pragma omp parallel for
\ shared(c) private(d, e) for (i 0 i lt
N i) int b, c, d, e a a b c c d
e
16
?????????? 4 ??????? ???????? ??????????
  • ? ??????? ????????? ???? ?????? ??????????
    ??????? ???????? ?????????? ? ???????? ?????
  • ????????????? ? ?????????
  • ????????? ?????????

17
???????? ?????????????
??????? ??????????
??? C
mov eax, sum add eax, 1 mov sum, eax
sum
?????
????? 1eax
????? 2eax
s
????? 1 ?????????
????? 1 ?????????
????
s
s
s
t0
mov eax, sum
mov eax, sum
add eax, 1
add eax, 1
s1
s
s1
t1
t2
mov sum, eax
s1
s1
s1
t3
s1
mov sum, eax
s1
?? ??, ??? ?? ???????!
18
?????? ?????????????
  • pragma omp single ????????? ????????? ???????
    ?????? ? ??????? ?????? (??????????) ??????
  • pragma omp barrier ?????????? ?????? ? ????
    ?????, ???? ??? ?????? ?? ?????? ??????
  • pragma omp atomic ???????? ????????? ?????????
    ???????? ??????? ? ?????? (?.?. ??? ?????????? ??
    ?????? ??????)
  • pragma omp critical ??? ?????? ?????????
    ?????? ?????? ?????? ??????? ? ??????????
    ????????? ???????

int aN, sum 0 pragma omp parallel for for
(int i 0 i lt N i) pragma omp
critical sum ai // one thread at a time
19
?????????? 5 ?????????????
  • ??? ??????? ????? ???????? ?????????????
    ??????????? ?????? ?????? ?????????????
  • ????????????? ? ?????????

20
?????????? 6 ??????????????
  • ???????? ? ??????????? ?????????????? OpenMP
  • /Qopenmp_profile
  • ????????????? ?????
  • ???????? ?????? Intel Thread Profiler ???
    PrimeHT.exe ??????? ??? ????????? ?? ?????????
  • ????????? Intel VTune Performance Analyzer
  • New Project Threading Toolkit Thread Analyzer
    Wizard ????????? Number of Threads 2
  • ????????? ?????? ??????????????
  • ?????????? ????????? ? ????? Summary, Threads,
    Regions

21
omp for schedule ?????
  • schedule ??????????, ??? ???? ????? ?????????????
    ?????? ???????
  • ?????????? ????? ????? ???????????????? ??????
  • ????????? ?????? ???????? ???????
  • ??????????? ?????????????? ?????, ??????????? ??
    ????????? ?????

schedule(static)
schedule(guided, f)
???? ?????
schedule(dynamic, c)
C
N/2
N
f
22
?????????? 7 ????????????
  • ???????????????? ????? ????????????
  • ????????????? ? ????????????????
  • ????????? ??????????? ???????? ??????? ???
    ??????????? ?????????????? ???????? ?? ?????????
    ?????

23
????????
  • ????? ?? ??????? ?????, ??? ???????????????? ???
    ??????? ? ?????? ?????? ???????????
  • ????????????
  • ??????? ?????????? ? ?????? ??????
  • ??? ????????? ?????????????? ???????? ??? ???????
    ?????????? ??????????? (???????? ? ??????) ?
    ?????
  • ???????? ???????? , , -, , , , ,

int aN, sum 0 pragma omp parallel for
reduction( sum) for (int i 0 i lt N
i) sum ai // no synchronization
needed
24
?????????? 8 ????????
  • ??????????? ?????? reduction, ????? ??????????
    ?? ????????????? ? ????????? ? ??? ??????????????
    ????????
  • ????????????? ? ?????????????
  • ??????????? ????????????????? ?????? ? ?????????
    ????????????? ??????
  • ???????????!

25
?????? OpenMP ?? ???????
  • ???????? ??????, ????????? ?????? ???????
  • omp parallel
  • ??????, ??????????? ?????? (????? ?????????? ?
    ??????? parallel)
  • omp sections
  • omp for
  • ???????? ??? ?????, ??????????? ??????
  • private, shared, reduction ??????? ????????
    ??????????
  • schedule ?????????? ?????????????
  • ?????? ?????????????
  • omp critical ??? ??????
  • omp barrier

26
???????
pragma omp parallel for private(cand, max_div,
div) \ reduction( counter, count31) \
schedule(guided, 10) for (cand from
cand lt to cand 2) prime
true max_div ((long)sqrt((double)cand))
1 ...
??? ??? ????????? ??? ????????????
????????????????? ???????? ???? ??????? ?
???????? ???!
27
??? ??? ???? ? OpenMP?
  • ?????? ??????? ??????????? ???????? ????????
    ?????????? ? ?? ?????????????
  • ????? ??????? ?????? ?????????????
  • OpenMP API ? ?????????? ?????????
  • ???????? ?????????? ???????
  • ?????? ?????????????? ?????????????
  • ?????? ??????? ????? ??? ?????????? ???????
  • ??????????, ??????????? ??? Intel ? ???? ??
    ?????????????????
  • ????????????? ? Win32 ? P-????????
  • ? www.openmp.org

28
??????? ??? ?????????? ??????
  • ??? ????? ??????? ????????????? ???????, ??
    ?????????????? ? ????? ??????? ??????

struct Node int data Node next Node
head for (Node p head p ! NULL p
p-gtnext) process(p-gtdata)
Node p pragma intel omp taskq shared(p) for (p
head p ! NULL p p-gtnext) //only 1
thrd pragma intel omp task process(p-gtdata)
// queue task to be executed // on any
available thread
29
????? ? ??????
  • ?????????? Hyper-Threading ????????
    ?????????????????? ?????????? ??? ????? ??????
    ????????
  • ?????????? HT ???????? ??????? ?? ????????
    ?????????? ??
  • ??? ?????????? ??????????? ?????????? HT,
    ?????????? ?? ?????? ???? ??????????!
  • ??????????? OpenMP ??? ??????? ??????????
    ????????????????? ?????? ??????????!
  • ??? ?????????? ???????????? ??????????????????
    ??????????? Intel Threading Tools

30
???????? ???????
  • ? developer.intel.com/software/products/compilers
    /
  • ? www.openmp.org
  • ??????????? Intel Compiler User Guide

31
??????? ?? ????????!
??????????, ?? ???????? ??????? ??????????? ??????
developer.intel.com
32
?????????????? ?????????
33
????????????? ?????????????????
??????? ????????????????? ??? ???????????? ?????????? ????????
??????? ????????????????, ??????? ?????????????? ??????????,???????????? ????????? ????????. Intel NetBurst(????????????????, ??????????????, ?????????????) ?????????????
?????? SIMD MMX, SSE, SSE2 ??????? ????????
??????, ????? ????????? ??????????? SMP ????
34
????? Intel Compiler??? ??????????????? ?
OpenMP
  • ?????????????? ?????????????????
  • /Qparallel
  • ????????? OpenMP
  • /Qopenmp
  • /Qopenmp_report012

35
???????? ???????
  • ??????????????????? (MP)
  • ?????????? ?????????? ??? ?????????
    ?????????????????? ?? ???? ?????????? ?????
    ???????????
  • ?????????? Hyper-Threading (HT)
  • ?????????? ?????????? ??? ?????????
    ?????????????????? ?? ???? ????? ????????????
    ????????????? ???????? ??????????
  • ??????????????? (MT)
  • ??????????? ?????????? ??? ?????????
    ???????????????? ? ?????????????????? ?? ?? ????
    ????????????? ?????????? (??????????) ???????????

36
HT - ??????????, ??????? ???????
????????? ???????????
Hyper-Threading
?????????? HT ???????? ??????????????????
?????????? ????????? ??????? ?????????????
????????
37
?????????? HT ??? ??????
????????? ????????? ???????
?????? ????????? ??????
Instruction TLB
Return Stack Predictor
Trace Cache Next IP
Trace Cache Fill Buffers
??????? ??????????? ?????????
?????????? HT ???????? ??????????????????
?????????? ??? ??????????? ????????
38
HT ????????????? ???????????
  • HT ????????? ??? ?? ? ??????????
  • ?? ?????? ????? ????????? ???????????
  • ??????? ????????????? ?? ??? ??????????
    ??????????? ?? ?????????? HT
  • ??????????????? ? ???????? ?????? ??????????
  • ??????????????? ????? ?????????? ??????????
  • ????????? ?? ??????? ?? ??????????? ????????????
    ?????????? HT
  • ?????? ???????????? ? ?????? ??????????
    ???????????
  • ????????? ?????????? ??????????? ? ?????? ?????
  • ???????? ? Windows XP, Linux 2.4.x

??? ????????????? ??????????? ?????????? HT
?????????? ???? ?????????? ?? ????????? ???????!
39
?????????? ???? ?????????? ?? ????????? ???????
  • ???? ????????? ???????????????
  • ???? ????????? ???????????????

40
????????????????? ??????
  • ????????? ??? ?????? ?? ????????? ???????????
    ???? ? ?????? ?????
  • ?????????? ??? ?????? ????????????(??????????
    ????????)

????? ??????????
????? ??????
Data
Data
??????
??????
??????
41
????????????????? ??????
  • ????????? ?????? ?? ????????? ??????????? ???? ?
    ?????? ???????
  • ????????? ??? ?????? ???????????? ???????????
    ???????

????? A

????? N
42
????????? ???????????????
  • API / ??????????
  • Win32 API
  • P-??????
  • MPI
  • ????? ????????????????
  • Java
  • C
  • ?????????? ?????? ????????????????
  • OpenMP
Write a Comment
User Comments (0)
About PowerShow.com