0% found this document useful (0 votes)
21 views3 pages

Program 2

The document provides instructions for creating an OpenMP program that divides iterations into chunks of 2 using static scheduling. It includes steps for setting up a project in Dev C++, writing the code, and executing the program to display which iterations are handled by each thread. The provided code snippet demonstrates a parallel for loop that outputs the thread number and corresponding iteration number for the specified number of iterations.

Uploaded by

8867sneha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Program 2

The document provides instructions for creating an OpenMP program that divides iterations into chunks of 2 using static scheduling. It includes steps for setting up a project in Dev C++, writing the code, and executing the program to display which iterations are handled by each thread. The provided code snippet demonstrates a parallel for loop that outputs the thread number and corresponding iteration number for the specified number of iterations.

Uploaded by

8867sneha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Write an OpenMP program that divides the Iterations into chunks containing 2 iterations,

respectively (OMP_SCHEDULE=static,2). Its input should be the number of iterations, and

its output should be which iterations of a parallelized for loop are executed by which thread.

For example, if there are two threads and four iterations, the output might be the following:

a. Thread 0 : Iterations 0 −− 1

b. Thread 1 : Iterations 2 – 3

STEP1

Open Dev C++

STEP2

Click on File----Project----Select Console----OpenMP

Select Project as C++ and press OK

STEP3

After Project is created under project create set.cpp file and type code as in below
#include <stdio.h>
#include <omp.h>

int main() {
int n;

printf("Enter number of iterations: ");


scanf("%d", &n);

// Parallel for loop with static scheduling and chunk size 2


#pragma omp parallel for schedule(static, 2)
for (int i = 0; i < n; i++) {
int tid = omp_get_thread_num();
printf("Thread %d : Iteration %d\n", tid, i);
}

return 0;
}

Final Step Goto Execute Menu and click on Compile and Run You can see the Thread execution based
on number of Iterations

You might also like