1.
OpenMP is:
Correct Answer
C. A standard for writing parallel applications that supports shared programming model
Explanation
OpenMP is a standard for writing parallel applications that supports a shared programming model. This means that OpenMP allows multiple threads to work together on a single task, sharing data and resources. It provides a set of directives and libraries that enable developers to parallelize their code and take advantage of multi-core processors. OpenMP is not specifically designed for distributed programming or uniprocessor optimization, although it can be used in those contexts as well. Therefore, the correct answer is "A standard for writing parallel applications that supports shared programming model."
2.
OpenMP follows fork/join model becau
Correct Answer
D. At start of parallel region master creates “team of parallel worker”, threads and at end of parallel region, all threads synchronize, and join master thread
Explanation
OpenMP follows the fork/join model because at the start of a parallel region, the master thread creates a team of parallel worker threads. These threads then execute the statements in the parallel block in parallel. At the end of the parallel region, all the threads synchronize and join the master thread. This model allows for efficient parallel execution of code by dividing the work among multiple threads and then joining them back together.
3.
Barrier synchronizations should be used whenever we want to ensure all threads have completed a common phase of their execution_____________
Correct Answer
A. Before any of them start the next pHase
Explanation
Barrier synchronizations should be used whenever we want to ensure all threads have completed a common phase of their execution before any of them start the next phase. This ensures that all threads have finished their current phase before moving on to the next phase, preventing any potential race conditions or inconsistencies in the program's execution.
4.
Omp_get_num_threads () environment variable gives:
Correct Answer
C. Return number of threads in a team
Explanation
The omp_get_num_threads() environment variable returns the number of threads in a team. This means that it provides information about the total number of threads that are currently active and working together as a team. It does not give the thread ID of all the threads or the maximum number of threads in a team.
5.
Omp_get_thread_num () environment variable gives:
Correct Answer
B. Thread ID of the thread
Explanation
The omp_get_thread_num() environment variable returns the Thread ID of the thread. This means that it provides a unique identifier for each thread in a parallel region. It does not give the maximum number of threads in a team, as that information can be obtained using omp_get_num_threads() function. Therefore, the correct answer is "Thread ID of the thread".
6.
Consider the following piece of code:#include <omp.h>#include <stdio.h> int main(void){#pragma omp parallel{for (i=0; i<100; i++)printf ("Parallel Processing Quiz.\n");}return 0;} How many times “Parallel Processing Quiz” will get printed?
Correct Answer
A. 100 times
Explanation
The code includes a parallel region defined by the pragma omp parallel directive. This means that the code inside the parallel region will be executed by multiple threads in parallel. Inside the parallel region, there is a for loop that iterates 100 times and prints "Parallel Processing Quiz" each time. Since the for loop is executed by multiple threads in parallel, the statement will be printed 100 times.
7.
- Consider the following piece of code:
#include #include int main(void){omp_set_num_threads (10);#pragma omp parallel {for (i=0; i<100; i++)printf ("Parallel Processing Quiz.\n");}return 0;} How many times “Parallel Processing Quiz” will get printed?
Correct Answer
B. 1000 times
Explanation
The code snippet sets the number of threads to 10 using the omp_set_num_threads function. Then, it enters a parallel region using the #pragma omp parallel directive. Within this parallel region, each thread will execute the for loop that iterates 100 times and prints "Parallel Processing Quiz" each time. Since there are 10 threads, each thread will execute the for loop 100 times, resulting in a total of 1000 times that "Parallel Processing Quiz" will be printed.
8.
- Consider the following piece of code:
#include <omp.h>#include <stdio.h> int main(void){ #pragma omp parallel for{for (i=0; i<100; i++)printf ("Parallel Processing Quiz.\n");}return 0;} How many times “Parallel Processing Quiz” will get printed?
Correct Answer
A. 100 times
Explanation
The code snippet is using OpenMP parallel for directive to parallelize the for loop. The loop will be divided among the available threads, and each thread will execute a portion of the loop. Since there is no dependency or synchronization involved, each thread will independently print "Parallel Processing Quiz" 100 times. Therefore, the total number of times "Parallel Processing Quiz" will get printed is 100.
9.
- Is the following piece of code correct?
int main(void){ L1: printf (“\n This is valid\n”);#pragma omp parallel forfor (i=0; i<100; i++){printf ("Parallel Processing Quiz.\n");if (i==i%10)goto L1;}return 0;}
Correct Answer
B. False
Explanation
The given piece of code is incorrect because it contains a label "L1" which is being used with a goto statement inside the parallel for loop. The presence of the goto statement can lead to unpredictable behavior and can cause the program to jump to a different part of the code, which can result in errors or unexpected output.
10.
If both export OMP_NUM_THREADS and omp_set_num_threads both are used in a program than the threads will be set to launch the parallel section in accordance with-
Correct Answer
A. Omp_set_num_threads
Explanation
If both export OMP_NUM_THREADS and omp_set_num_threads are used in a program, the threads will be set to launch the parallel section in accordance with omp_set_num_threads. This is because omp_set_num_threads specifically sets the number of threads to be used in the parallel section, while export OMP_NUM_THREADS is a global environment variable that sets the maximum number of threads that can be used. Therefore, omp_set_num_threads takes precedence over OMP_NUM_THREADS in determining the number of threads to be used in the program.