OpenMP: Conditional
Hello there, welcome to HPC education. In this video, we'll be talking about Conditional If statements in OpenMP.
If you're familiar with programming languages like C, C++, Python, Java, etc., you will already know what if and else statements mean.
The syntax for openMP conditional if statements is the same as the other programming languages. However, the meaning might differ.
This is the syntax. The if statement specifies whether a loop should be executed in parallel or in serial.
The expression that is given here, if it evaluates to true that is non zero, it causes the code in the parallel region to execute in parallel, else, if the expression evaluates to false, that is a zero value, the parallel region is executed in serial mode by a single thread.
We will understand this in the following example.
The example that is shown here uses the if and else statements in OpenMP.
Let's try to understand this program. In the main function, we have omp_set_num_threads(), this function sets the total number of threads to 5. In line number 22 and 23, the test function is called with parameter values 0 and 4. The expected output for this is..
Now let's try to understand this.
When the parameter value is 0, omp_in_parallel() returns a zero value because it does not run in a parallel region. And hence, line number 15 is executed because it calls the else statement.
Whereas if the parameter value is 4, omp_in_parallel() returns 1 because it runs in the parallel region and hence the if condition is satisfied and line number 10 is printed.
omp_get_num_threads() returns the total number of threads that is currently running. Because we set the total number of threads to 5, it also returns the total number of threads to 5 and that is why 5 threads are printed.
If applies to the following directives; parallel, for and sections. In the example that we saw, we used parallel directive.
Thank you for watching this video. Hope to see you in the next one.
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «OpenMP: Conditional», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.