0% found this document useful (0 votes)
2 views

EX1 mca

The document presents two simple programs demonstrating OpenMP fork-join parallelism. The first program illustrates how to obtain and print the number of threads inside and outside a parallel region, while the second program sets the number of threads to 5 and prints messages from each thread. Both programs aim to showcase the functionality of OpenMP in parallel computing.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

EX1 mca

The document presents two simple programs demonstrating OpenMP fork-join parallelism. The first program illustrates how to obtain and print the number of threads inside and outside a parallel region, while the second program sets the number of threads to 5 and prints messages from each thread. Both programs aim to showcase the functionality of OpenMP in parallel computing.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

EX.

NO:1 SIMPLE PROGRAM TO DEMONSTRATE AN OPENMP FORK-JOIN


a PARALLELISM
DATE:

AIM:
To write a program to demonstrate an openmo fork-join parallelism.

ALGORITHM:

 Start the program and declare variables.

 Get the number of threads outside the parallel region.

 Print thread count outside (usually 1).

 Enter the parallel region using OpenMP.

 Each thread gets and prints the total number of threads.

 Each thread prints its own thread ID.

 Exit the parallel region and end the program.

PROGRAM:

#include <stdio.h>

#include <omp.h>

int main(){

int thread_id;

int count=omp_get_num_threads();

printf("the numbers of threads outside parallel region %d\n",count);

#pragma omp parallel

{
int count=omp_get_num_threads();

printf("the numbers of threads inside parallel region %d\n",count);

printf("\n");

printf("Hello from process: %d\n", omp_get_thread_num());

return 0;

RESULT:

Thus the program to execute an openmp fork-join parallelism.


EX.NO:1b SIMPLE PROGRAM TO DEMONSTRATE AN OPENMP FORK-JOIN
DATE: PARALLELISM

AIM:
To write a program to demonstrate an openmo fork-join parallelism.

ALGORITHM:

 Start the program and declare thread_id.

 Enter a parallel region using #pragma omp parallel.

 Inside the region, set the number of threads to 5 using omp_set_num_threads(5).

 Each thread executes the same code block.

 Each thread prints a message with its thread ID using omp_get_thread_num().

 The output shows messages from multiple threads (up to 5).

 Exit the parallel region and end the program.

PROGRAM:

#include <stdio.h>
#include <omp.h>

int main(int argc, char** argv){


int thread_id;

#pragma omp parallel


{
omp_set_num_threads(5);
printf("Hello from process: %d\n", omp_get_thread_num());
}
return 0;
}
RESULT:

Thus the program to execute an openmp fork-join parallelism.

You might also like