Question
/* * Usage info: * g++ -fopenmp -o prob6 prob6.cpp * ./prob6 * To save the output in a file, redirect stdout to a file,
/* * Usage info: * g++ -fopenmp -o prob6 prob6.cpp * ./prob6 * To save the output in a file, redirect stdout to a file, i.e., * ./prob6 > file.txt * where file.txt is the desired name of the output file. */
#include #include #include #include #include
using namespace std;
int sumWithLoop(int * A, int n); int sumWithLoop_OMP(int * A, int n); int sumRec(int * A, int n, int start, int end); int sumRec_OMP(int * A, int n, int start, int end);
int main() { double wtime; int n; printf ( " How many random numbers do you want to generate? " ); scanf ( "%d", &n ); int * A; A = new int[n];
//generate n of random numbers srand( (unsigned) time(NULL) ); for(int i = 0; i
int num_procs = omp_get_num_procs ( ); int max_threads = omp_get_max_threads ( ); printf ( " Number of processors available = %d ", num_procs ); printf ( " Number of threads = %d ", max_threads ); //executing sumWithLoop and also mesuring its execution time wtime = omp_get_wtime ( ); int sum1 = sumWithLoop(A, n); wtime = omp_get_wtime ( ) - wtime; printf( " sum loop is %d ", sum1 ); printf ( " time %14f ", wtime );
//executing sumWithLoop_OMP and also mesuring its execution time wtime = omp_get_wtime ( ); int sum2 = sumWithLoop_OMP(A, n); wtime = omp_get_wtime ( ) - wtime; printf( " sum loop OMP is %d ", sum2 ); printf ( " time %14f ", wtime ); //executing sumRec and also mesuring its execution time wtime = omp_get_wtime ( ); int sum3 = sumRec(A, n, 0, n-1); wtime = omp_get_wtime ( ) - wtime; printf( " sum recursion is %d ", sum3 ); printf ( " time %14f ", wtime ); //executing sumRec_OMP and also mesuring its execution time wtime = omp_get_wtime ( ); int sum4 = sumRec_OMP(A, n, 0, n-1); wtime = omp_get_wtime ( ) - wtime; printf( " sum recursion OMP is %d ", sum4 ); printf ( " time %14f ", wtime ); }
int sumWithLoop(int * A, int n) { //TO BE COMPLETED }
int sumWithLoop_OMP(int * A, int n) { //TO BE COMPLETED }
int sumRec(int * A, int n, int start, int end) { //TO BE COMPLETED }
int sumRec_OMP(int * A, int n, int start, int end) { //TO BE COMPLETED }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started