CS 4000 Homework # 1:Introduction to OpenMP

$45.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (7 votes)

Introduction
This homework provides some practice with features of OpenMP.
1. (5 pts.) Consider the program hello_world.cc as your first attempt at building an
OpenMP parallel program. You compile this program (using g++ -fopenmp hello_world.cc
) and run it. It should print
Greetings from Thread 0
There are 4 threads
Greetings from Thread 1
There are 4 threads
Greetings from Thread 3
There are 4 threads
…..
Unfortunately, it only prints:
Greetings from Thread 0
There are 1 threads
So, there is clearly an error in the program. Find it and fix it. Provide appropriate
documentation in your program that indicates the location and cause of the error.
(Hint: try to use the compiler to help you find the error.)
2. (20 pts.) I have written a program called count_primes.cc that counts the number of
prime numbers between two numbers a and b. For example, if you input the values 2
and 10, it will output 4 (those primes are 2, 3, 5, and 7). This program can also find the
number of primes between two large numbers, e.g., 5 billion and 5 billion plus 500,000.
But, it’s slow. Using those two numbers as input, this program takes 38 seconds to
complete (and return the answer 22266). Your task is to modify this program using
OpenMP to make it faster.
For this assignment, modify this program using OpenMP to count the number of
primes between a and b. You are required to the use the OpenMP reduction clause
somewhere in your program for this assignment.
Please provide appropriate documentation in your program that describes how your
program computes the solution in parallel.
Submission and Grading
Implement each program as a single C++ file. Make sure to provide adequate documentation.
You should have a header comment with your name, date, etc. You should also document
any functions within your code.
Submit your code via Blackboard.