Опубликован: 12.07.2012 | Доступ: свободный | Студентов: 355 / 25 | Оценка: 4.00 / 4.20 | Длительность: 11:07:00
Тема: Программирование
Специальности: Программист
Теги:
Лекция 7:
OpenMP fundamentials
Аннотация: In this lecture describes OpenMP basics. OpenMP workflow and its limitation.
Different variables and sections of the code, critical and concurrent sections, loop parallelization directives, loop iteration scheduling.
Ключевые слова: presentation, CAN, cross-platform, overhead, data parallelism, compiler directive, directive, preprocessor directive, model, sequential, functional parallelism, sequential execution, execution thread, available, end, ALL, NoWait, iteration, space, scattered, method, default behaviour, chunk, execution speed, decrease, implicit, section, option, tutorial, FROM, AND, tuning, distributed, shared memory, SAN, LNCS
OpenMP is
The presentation can be downloaded here.
- An application programming interface (API) that supports shared-memory programming for C/C++ and Fortran
- Pros:
Usage
C/C++
#pragma omp directive [clause, …]
Fortran
!$OMP directive [clause, …] C$OMP directive [clause, …] *$OMP directive [clause, …]
Parallel execution
Parallel Regions
#pragma omp parallel
#pragma omp parallel { printf( "hello world from thread %d of %d\n", omp_get_thread_num(), omp_get_num_threads() ); }
Параллельное исполнение
- Most of the OpenMP instructions are preprocessor directives
- Main construction is "omp parallel [smth]"
OpenMP parallel model
- Memory is shared
- Task is divided into the threads
- Variables can be
- shared by the threads
- private, available only for one thread
- Variables can be
- Uncareful or wrong variable usage can lead to wrong execution results.
- Program execution starts from the master thread
- With OpenMP directive master thread creates the additional threads
- After the parallel region is finished all threads are synchronized
- Main thread continues to execute the sequential part
Основные конструкции OpenMP
- #pragma omp for Each thread gets its own amount of data – data parallelism
- #pragma omp section Each section will be executed in a separate thread – functional parallelism
- #pragma omp single Sequential execution. Only one thread will execute this code
OpenMP sections
#pragma omp sections [ clause [ clause ] ... ] new-line { [#pragma omp section new-line ] structured-block1 [#pragma omp section new-line structured-block2 ] }
#pragma omp parallel #pragma omp sections nowait { thread1_work(); #pragma omp section thread2_work(); #pragma omp section thread3_work(); #pragma omp section thread4_work(); }