Архитектура Аудит Военная наука Иностранные языки Медицина Металлургия Метрология
Образование Политология Производство Психология Стандартизация Технологии


Describe Directive #pragma omp for.



Pragmas that let you define how work is distributed or shared across the threads in a parallel region (#pragma omp section, #pragma omp for, #pragma omp single, #pragma omp task).

The omp for directive instructs the compiler to distribute loop iterations within the team of threads that encounters this work-sharing construct.

Pragmas can be controlled by clauses. For example, a num_threads clause can be used to control a parallel region pragma.

Pragma directives generally appear immediately before the section of code to which they apply. For example, the following example defines a parallel region in which iterations of a for loop can run in parallel:

#pragma omp parallel

{

#pragma omp for

for (i=0; i<n; i++)

...

}

1.10.Give examples of pipelined commands. Describe the architecture of von Neumann.

Von Neumann architecture is based on the stored-program computer concept, where instruction data and program data are stored in the same memory.

The Central Processing Unit (CPU) is the electronic circuit responsible for executing the instructions of a computerprogram. It is sometimes referred to as the microprocessor or processor.

Specify iteration distribution modes cycle in OpenMP threads

Loop parallelism is a very common type of parallelism in scientific codes, so OpenMP has an easy mechanism for it. OpenMP parallel loops are a first example of OpenMP worksharing constructs: constructs that take an amount of work and distribute it over the available threads in a parallel region.

A more natural option is to use the parallel for pragma:

#pragma omp parallel#pragma omp forfor (i=0; i<N; i++) { // do something with i}

This has several advantages. For one, you don't have to calculate the loop bounds for the threads yourself, but you can also tell OpenMP to assign the loop iterations according to different schedules.

Usually you will have many more iterations in a loop than there are threads. Thus, there are several ways you can assign your loop iterations to the threads. OpenMP lets you specify this with the schedule clause. #pragma omp for schedule(....).

With static schedules, the iterations are assigned purely based on the number of iterations and the number of threads (and the chunk parameter; see later). In dynamic schedules, on the other hand, iterations are assigned to threads that are unoccupied. Dynamic schedules are a good idea if iterations take an unpredictable amount of time, so that load balancing is needed.


Поделиться:



Последнее изменение этой страницы: 2019-04-01; Просмотров: 204; Нарушение авторского права страницы


lektsia.com 2007 - 2024 год. Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав! (0.006 с.)
Главная | Случайная страница | Обратная связь