?????? ?????????? ???????????? ???????? ??? ????????????????? ?????? ? ????? ??????? (???????? OpenMP) - PowerPoint PPT Presentation

About This Presentation
Title:

?????? ?????????? ???????????? ???????? ??? ????????????????? ?????? ? ????? ??????? (???????? OpenMP)

Description:

Title: - 16 Subject: Author – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 36
Provided by: 2332
Category:
Tags: openmp | openmp

less

Transcript and Presenter's Notes

Title: ?????? ?????????? ???????????? ???????? ??? ????????????????? ?????? ? ????? ??????? (???????? OpenMP)


1
????????????? ??????????????? ??????????? ??.
?.?. ????????????
????? ?????????? ? ???????? ????????????
?????????? ?????? 16 ?????? ??????????
???????????? ???????? ??? ?????????????????
?????? ? ????? ??????? (???????? OpenMP) 2
2
??????????
  • ????????? OpenMP
  • ?????????????
  • ????????? master, critical, barrier, atomic,
    flush, ordered, threadprivate
  • ?????????? ???????? ????????? ??????
  • ????????? ???????? shared, private, firstprivate,
    lastprivate, copyin, default, reduction
  • ????????????? ???????? ? ?? ??????????
  • ?????????? ??????? OpenMP
  • ??????? ??? ????????/??????? ?????????? ?????
    ??????????
  • ??????? ?????????????
  • ?????????? ?????
  • ?????????? OpenMP

3
????????? OpenMP
?????????????


????????? master ?????????? ???????? ????,
??????? ?????? ???? ???????? ?????? ????????
??????? ??? ????????? ?????? ?????????? ??????
???????? ???? (?????????? ????????? ?? ?????????
?? ????????????????) pragma omp master newline
structured_block


4
????????? OpenMP
?????????????

????????? critical ?????????? ???????? ????,
??????? ?????? ??????????? ?????? ????? ??????? ?
?????? ??????? ?????? ??????? (???????????
??????) ???????? ??????? ??? ????????? ??????
?????????? ?????? ???????? ???? (??????????
????????? ?? ????????? ?? ????????????????) prag
ma omp critical name newline
structured_block


5
????????? OpenMP
?????????????


????????? critical (??????) include ltomp.hgt
main() int x x 0 pragma omp
parallel shared(x) pragma omp critical
x x 1 / end of parallel section /


6
????????? OpenMP
?????????????


????????? barrier ?????????? ?????
?????????????, ??????? ?????? ?????????? ???
???????? ??? ??????????? ?????????? (?????????
?????? ???? ??????? ? ????) pragma omp barrier
newline


7
????????? OpenMP
?????????????

  • ????????? atomic ?????????? ??????????, ??????
    ? ??????? (??????/??????) ?????? ???? ?????????
    ??? ????????? ????????
  • pragma omp atomic newline
  • statement_expression
  • ????????? ?????? ?????? ?????????
  • x binop expr , x, x, x--, --x
  • x ?????? ???? ????????? ??????????
  • expr ?? ?????? ????????? ?? x
  • binop ?????? ???? ??????????????? ????????? ????
  • , -, , /, , , , gtgt, ltlt



8
????????? OpenMP
?????????????
  • ????????? flush ?????????? ????? ?????????????,
    ? ??????? ???????? ?????? ???? ?????????? ??????
    ??? ???? ????????? ????????? ?????? (?.?. ????
    ??????? ?????-???? ???????? ??????????? ?? ??????
    ??? ???????????, ?????????? ???????? ???????????
    ?????? ???? ???????? ? ????? ??????)
  • pragma omp flush (list) newline
  • ???? ?????? ?????? list, ?? ?????????????????
    ?????? ????????? ??????????
  • ????????? flush ??????? ??????? ???????????? ?
    ?????????? barrier, critical, ordered, parallel,
    for, sections, single



9
????????? OpenMP
?????????????
  • ????????? ordered ????????? ???????? ????
    ????????????? ?????, ??????? ?????? ???????????
    ????? ? ????? ?? ???????, ??? ? ???
    ???????????????? ??????????
  • pragma omp ordered newline
  • structured_block
  • ? ?????? ?????? ??????? ? ????? ordered ?????
    ?????????? ?????? ???? ?????
  • ?? ????? ???????? ????? ????? ???? ?????? ????
    ????????? ordered ? ??? ????????? ?????
    ??????????? ?????? ??????????
  • ????, ? ??????? ??????? ????????? ordered,
    ?????? ????? ???????? ordered



10
????????? OpenMP
?????????????


????????? threadprivate ???????????? ???
???????? ???????? ????? ??? ?????????? ??????????
????????? ????????? ????? ?? ?????? ?????
????????, ?? ?????????? ?? ??? ????? ??????????
????????? pragma omp threadprivate (list)


11
????????? OpenMP
?????????? ???????? ????????? ??????


????? (??????????? ????? ????????, shared)
?????????? static, ?????????? ? ????????
????????? ? ???????? ????? ?????????
(private) ?????? ??????? - ??????????
????? ?????????? ???????? ?????????
?????????????? ??? ?????? ?????????? (clause)
???????? private, firstprivate, lastprivate,
shared, default, reduction, copyin ???????
??????????, ????? ??????????? ?????????? ?????
??????????? ???????????????? ? ????????????
?????????? ??????????? ?????????


12
????????? OpenMP
?????????? ???????? ????????? ??????


???????? shared ?????????? ?????? ??????????,
??????? ????? ?????? ??? ???? ???????
???????????? ??????? ???????????? ?????????????
????? ?????????? ?????? ??????????????
????????????? shared (list) ???????? private
?????????? ?????? ??????????, ??????? ?????
?????????? ??? ??????? ?????? ??????????
????????? ? ?????? ???????????? ???????
???????????? ??????? ????????? ????????
?????????? ???????? ?????????????? private (list)


13
????????? OpenMP
?????????? ???????? ????????? ??????


???????? firstprivate ????????? ??????? ?????????
?????????? ???????, ??????? ????? ??????????????
???????????????? ?????????? ????????
?????????? firstprivate (list) ????????
lastprivate ????????? ??????? ?????????
?????????? ???????, ???????? ??????? ????????????
? ???????? ?????????? ????? ??????????
???????????? ??????? (???????????? ????????
??????, ???????????? ????????? ???????? ????? ???
????????? ??????) lastprivate (list)


14
????????? OpenMP
?????????? ???????? ????????? ??????


???????? copyin ????????? ????????? ?????????????
?????????? ????????? threadprivate copyin
(list) ???????? default ????????????? ???????
????????? ?????????? ?? ????????? default (shared
none)


15
????????? OpenMP
?????????? ???????? ????????? ??????


???????? reduction ?????????? ?????? ??????????,
??? ??????? ??????????? ???????? ???????? ?????
??????????? ???????????? ??????? ??? ???????
?????? ????????? ????? ???? ??????????, ??????
????????? ???????? ? ????? ????????? ?????????? ?
??? ?????????? ???????????? ??????? ?? ?????
?????????? ?????????? ??????????? ???????????
???????? ????????, ?????????? ???????
???????????? ? ???????? (??????????)
?????????? reduction (operator list)


16
????????? OpenMP
?????????? ???????? ????????? ??????

  • ???????? reduction (??????? ??????)
  • ????????? ?????? ?????? ?????????
  • x x op expr
  • x expr op x
  • x binop expr
  • x, x, x--, --x
  • x ?????? ???? ????????? ??????????
  • expr ?? ?????? ????????? ?? x
  • op (operator) ?????? ???? ???????????????
    ????????? ????
  • , -, , /, , , , ,
  • binop ?????? ???? ??????????????? ????????? ????
  • , -, , /, , ,



17
????????? OpenMP
?????????? ???????? ????????? ??????
???????? reduction (??????) include ltomp.hgt
main () / vector dot product / int i, n,
chunk float a100, b100, result / Some
initializations / n 100 chunk 10
result 0.0 for (i0 i lt n i) ai
i 1.0 bi i 2.0 pragma omp
parallel for \ default(shared) private(i) \
schedule(static,chunk) \ reduction(result)
for (i0 i lt n i) result result
(ai bi) printf("Final result
f\n",result)


18
????????? OpenMP
????????????? ???????? ? ?? ??????????



19
?????????? ??????? OpenMP
??????? ??? ????????/??????? ?????????? ?????
??????????

  • void omp_set_num_threads(int num_threads)
  • ????????? ????????? ???????????? ????? ???????
    ??? ????????????? ? ????????? ????????????
    ??????? (???? ??? ????? ????????? ??????
    ???????????). ?????????? ?? ????????????????
    ??????? ?????????.
  • int omp_get_max_threads(void)
  • ?????????? ???????????? ????? ???????.
  • int omp_get_num_threads(void)
  • ?????????? ??????????? ????? ??????? ?
    ???????????? ??????? ?????????.



20
?????????? ??????? OpenMP
??????? ??? ????????/??????? ?????????? ?????
??????????
  • ??????? ??? ????????/??????? ?????????? ?????
    ??????????
  • int omp_get_thread_num(void)
  • ?????????? ????? ??????.
  • int omp_get_num_procs(void)
  • ?????????? ????? ???????????, ?????????
    ??????????.
  • int omp_in_parallel(void)
  • ?????????? .TRUE., ???? ??????? ??
    ???????????? ??????? ?????????.
  • void omp_set_dynamic(int dynamic)
  • int omp_get_dynamic(void)
  • ?????????????/??????????? ????????? ?????,
    ???????????? ??????????? ???????? ????? ???????.
  • void omp_get_nested(int nested)
  • int omp_set_nested(void)
  • ?????????????/??????????? ????????? ?????,
    ???????????? ????????? ???????????.



21
?????????? ??????? OpenMP
??????? ?????????????

  • ? ???????? ?????? ???????????? ????? ??????????
    ???? omp_lock_t ??? omp_nestlock_t. ??????
    ?????????? ?????? ?????????????? ?????? ???
    ????????? ?????????? ?????????????.
  • void omp_init_lock(omp_lock_t lock)void
    omp_nest_init_lock(omp_nest_lock_t lock)
  • ?????????????? ?????, ????????? ? ??????????
  • lock.void omp_destroy_lock(omp_lock_t lock)
  • void omp_destroy_nest__lock(omp_nest_lock_t
    lock)
  • ??????? ?????, ????????? ? ?????????? lock.



22
?????????? ??????? OpenMP
??????? ?????????????

  • void omp_set_lock(omp_lock_t lock)
  • void omp_set_nest__lock(omp_nest_lock_t lock)
  • ?????????? ????????? ????? ?????????
    ???????????? ?????, ? ????? ??????????? ???.
  • void omp_unset_lock(omp_lock_t lock)
  • void omp_unset_nest__lock(omp_nest_lock_t lock)
  • ??????????? ?????, ???? ?? ??? ????????
    ??????? ?????.
  • void omp_test_lock(omp_lock_t lock)
  • void omp_test_nest__lock(omp_nest_lock_t lock)
  • ??????? ????????? ????????? ?????. ???? ???
    ??????????, ?????????? .FALSE.



23
?????????? ?????


OMP_SCHEDULE ?????????? ?????? ?????????????
???????? ? ?????, ???? ? ????????? DO
???????????? ?????? SCHEDULE(RUNTIME).
OMP_NUM_THREADS ?????????? ????? ????? ???
?????????? ???????????? ???????? ??????????.
OMP_DYNAMIC ????????? ??? ?????????
???????????? ????????? ????? ?????. OMP_NESTED
????????? ??? ????????? ?????????
???????????. ?????????? ? ?????????? OpenMP
?????????? ?????? "_OPENMP", ??????? ?????
?????????????? ??? ???????? ?????????? ?????????
??????, ??????????? ??? ???????????? ??????
?????????


24
??????

include ltomp.hgt define THREADNUMS 2 main ()
/ ?????????? ????? ? / long StepNums 10000
double step, x, pi, sum0.0 int i step
1.0/StepNums omp_set_num_threads(THREADNUMS) p
ragma omp parallel for reduction(sun)
private(i,x) for (i0 iltStepNums i)
x(i-0.5)step sum sum 4.0/(1.0-xx)
pi step sum


25
????????? ?????????? MPI ? OpenMP ??? ?????? ?
????? ???????


????????? ??????? ?????????? ?????????????????
???????? ????????? ??? ?????? ??????????
????????? ? ?????????? OpenMP ? MPI ???
2-????????????? ???????


26
????????? ?????????? MPI ? OpenMP ??? ?????? ?
????? ???????

????????? ?????????? ????????? ??? ?????????????
???????????? ??????????


27
????????? ?????????? MPI ? OpenMP ??? ?????? ?
????? ???????


????????? ??????? ?????????? ?????????????????
???????? ????????? ??? ?????? ??????????
????????? ? ?????????? OpenMP ? MPI ???
4-????????????? ???????


28
????????? ?????????? MPI ? OpenMP ??? ?????? ?
????? ???????


????????? ?????????? ????????? ??? ?????????????
???????????? ??????????


29
??????????????? (MPIOpenMP) ??????????
???????????????? ??? ?????? ? ????? ???????


????????? ??????? ?????????? MPI ? MPIOpenMP
????????? ????????? ??? ???? 2-????????????
????????


30
??????????????? (MPIOpenMP) ??????????
???????????????? ??? ?????? ? ????? ???????


????????? ?????????? ????????? ??? ?????????????
?????????? MPIOpenMP ???????? ????????????
?????????


31
?????????? OpenMP
1) Silicon Graphics. Fortran 77/90 (IRIX),
??????????? ????????? OpenMP ??? C/C. 2)
Compaq/DEC. DIGITAL Fortran 3) Kuck Associates
(KAI). Fortran, C/C (Unix, Windows) 4)
Portland Group (PGI). Fortran ? C/C ??? Windows
NT, Linux, Solaris (x86). 5) OdinMP.
OpenMP-???????????? ??? ????? ?, ?????????
????????? ? ????????? POSIX threads. 6) Sun.
??????????? ????????? OpenMP 7) Pacific-Sierra
Research ?????????? ??????????????????
????????????? VAST/Parallel ??? Fortran ? ?,
??????? ???????????? ?????????????? ?????????????
???????????? ? ?????????? ? ??????????
??????????? ????????????? ???????? ?????
?????????? ??????????????? ???????? OpenMP. 8)
Intel. Fortran, C/C (Unix, Windows)


32
?????????????? ???????
  • www.openmp.org
  • ??? ????? OpenMP - http//parallel.ru/tech/tech_de
    v/openmp.html
  • OpenMP C/C specification v1.0 http//
    www.openmp.org
  • Introduction to OpenMP - www.llnl.gov/computing/tu
    torials/workshops/workshop/openMP/MAIN.html
  • Chandra, R., Menon, R., Dagum, L., Kohr, D.,
    Maydan, D., McDonald, J. (2000). Parallel
    Programming in OpenMP. Morgan Kaufmann
    Publishers.

33
??????? ??? ??????????
  • ?????? ????????????? ????????? ?????? ? OpenMP
  • ???????????????? ? ?????????????? ??????????
    ??????? OpenMP

34
??????? ??? ??????????????? ??????
  • ?????????? ???????????? ??????? ??? ?????
    ???????? ??????? ??? ????????????? ??????????
    OpenMP

35
??????????
  • ?????? ????????????? ????????? ??????
  • ?????????? ??????? OpenMP
  • ?????????? ????? ?????????
Write a Comment
User Comments (0)
About PowerShow.com