Parallel & Distributed Computing (L31+32) : Write A Simple Openmp Program To Demonstrate The Parallel Loop Construct

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

DATED-18-07-20 18BCE0707

ASSESSMENT 1 MUSKAN AGRAWAL

PARALLEL & DISTRIBUTED COMPUTING(L31+32)

Aim: Write a simple OpenMP program to demonstrate the parallel loop construct.

a. Use OMP_SET_THREAD_NUM( ) and OMP_GET_THREAD_NUM( ) to find the


number of processing unit
b. Use function invoke to print ‘Hello World’
c. To examine the above scenario, the functions such as omp_get_num_procs(),
omp_set_num_threads(), omp_get_num_threads(), omp_in_parallel(),
omp_get_dynamic() and omp_get_nested() are listed and the explanation is given
below to explore the concept practically.
omp_set_num_threads() - takes an integer argument and requests that the Operating
System provide that number of threads in subsequent parallel regions.
omp_get_num_threads() (integer function) - returns the actual number of threads in
the current team of threads.
omp_get_thread_num() (integer function) - returns the ID of a thread, where the ID
ranges from 0 to the number of threads minus 1. The thread with the ID of 0 is the
master thread.
omp_get_num_procs() - returns the number of processors that are available when the
function is called.
omp_get_dynamic() - returns a value that indicates if the number of threads available
in subsequent parallel region can be adjusted by the run time. o omp_get_nested( )
returns a value that indicates if nested parallelism is enabled.

SOURCE CODE:
#include "stdio.h"

#include "omp.h"

void main(){
DATED-18-07-20 18BCE0707
ASSESSMENT 1 MUSKAN AGRAWAL

if(omp_get_nested())

printf("Nested parallelism: DISABLED.\n");

else

printf("Nested parallelism: DISABLED.\n");

int threads = omp_get_dynamic();

int processors = omp_get_num_procs();

omp_set_num_threads(4);

printf("Number of processors: %d\n", processors);

printf("Number of available threads: %d\n", threads);

#pragma omp parallel

int tnum = omp_get_thread_num();

printf("Hello(%d)", tnum);

printf(" World(%d)\n", tnum);

EXECUTION:

REMARKS: The OPENMP header file to be enclosed for this experiment is “omp.h” which


provides functions for executing programs parallely.

a. When we check for nested parallelism, our program output comes out to be disabled which
means that the return value of the omp_get_nested is 0.
b. #pragma omp parallel is a layout used to store the program which needs to be parallelized.
DATED-18-07-20 18BCE0707
ASSESSMENT 1 MUSKAN AGRAWAL

c. Lastly the no of processes which are in the output screen are 8 which means that the master
process is forked into 8 subprocesses showing output of each one of the sub processes as
shown above.

You might also like