Ask C/C++ Expert


Home >> C/C++

Project

Simple OpenMP Experiment

Introduction

A great use for parallel programming is identical operations on large arrays of numbers.

Requirements

1. Pick an array size to do the arithmetic on. Don't pick something too huge, as your machine may not allow you to use that much memory. Don't pick something too small, as the overhead of using threading might dominate the parallelism gains.

2. Using OpenMP, add up two large floating-point arrays, putting the results in another array.

3. Do this for one thread and do this for four threads. (I.e.,
#define NUMT 1 and
#define NUMT 4

4. Time the two runs. Convert the timing results into "Mega-Multiplies per Second".

5. Review the Project Notes pages on "How Reliable is the Timing?"

6. What speedup are you seeing when you move from 1 thread to 4 threads? S = (Execution time with one thread) / (Execution time with four threads)

7. If your 4-thread-to-one-thread speedup is S (S > 1.), compute the parallel fraction:

8. float Fp = (4./3.)*( 1. - (1./S) );

Don't worry what this means just yet. This will become more meaningful soon.

9. Your commentary write-up (turned in as a PDF file) should include:

1. Tell what machine you ran this on

2. What performance results did you get?

3. What was your 4-thread-to-one-thread speedup?

4. Why do you think it is behaving this way?

5. What was your Parallel Fraction, Fp?

The main Program

Your main program would then look something like this:

#include
#include
#include
#define NUMT 4
#define ARRAYSIZE ??
#define NUMTRIES ??

int main( )
{
#ifndef _OPENMP
fprintf( stderr, "OpenMP is not supported here -- sorry.\n" ); return 1;
#endif

float *A = new float[ARRAYSIZE]; float *B = new float[ARRAYSIZE]; float *C = new float[ARRAYSIZE];

omp_set_num_threads( NUMT );
fprintf( stderr, "Using %d threads\n", NUMT );

double maxMegaMults = 0.; double sumMegaMults = 0.;

for( int t = 0; t < NUMTRIES; t++ )
{
double time0 = omp_get_wtime( );

#pragma omp parallel for
for( int i = 0; i < ARRAYSIZE; i++ )
{
C[i] = A[i] * B[i];
}

double time1 = omp_get_wtime( );
double megaMults = (double)ARRAYSIZE/(time1-time0)/1000000.; sumMegaMults += megaMults;
if( megaMults > maxMegaMults ) maxMegaMults = megaMults;
}

double avgMegaMults = sumMegaMults/(double)NUMTRIES );
printf( " Peak Performance = %8.2lf MegaMults/Sec\n", maxMegaMults
);

printf( "Average Performance = %8.2lf MegaMults/Sec\n", avgMegaMults
);

// note: %lf stands for "long float", which is what printf calls a "double"
// %d stands for "decimal integer", not "double"

return 0;
}

Project Turn-In Procedures
- Your project turnins will all be electronic.
- Your electronic turnin will be done at http://engr.oregonstate.edu/teach and will consist of:

1. Source files of everything (.cpp, .cl)

2. A Linux or Windows executable file, if needed.

3. A report in PDF format.

Electronic submissions are due at 23:59:59 on the listed due date.

- Your PDF report will include:

1. A title area, including your name, project number, and project name.

2. Any tables or graphs to show your results.

3. An explanation of what you did and why it worked the way it did. Your submission will not be considered valid unless you at least attempt to explain why it works the way it does.

You can turn in all of your files, if you want, in a .zip file except the PDF report. Please leave the PDF report out of the .zip file. (I have a script that vacuums up all your PDF files so I can read them as one big PDF. I can get your project grades back to you faster this way.)

- Your project will be graded and the score posted to the class web page.

If you want to know why you did not receive full credit, send me an email asking about it, or see me during Office Hours.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92254651
  • Price:- $50

Priced at Now at $50, Verified Solution

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As