Question: OMP.C /** * You are required to write an OpenMP program that performs multiplication for two n-digits decimal integers * using the basic simple algorithm

 OMP.C /** * You are required to write an OpenMP programthat performs multiplication for two n-digits decimal integers * using the basic

OMP.C

/**

* You are required to write an OpenMP program that performs multiplication for two n-digits decimal integers

* using the basic simple algorithm you learned in primary school

* compiler command: g++ -fopenmp omp.cpp -o omp

* execution command: ./omp num1 num2

* where num1 is the number of test cases and num2 is the number of digits

* */

//============================================================================

#include

#include

#include

using namespace std;

int test_cases;

int digits;

void print(string A, string B, string C);

unsigned short int value(char c);

void OneDigitMultiplier(unsigned short int a, unsigned short int b, unsigned short int Cin, unsigned short int& s, unsigned short int& Cout);

void OneDigitAdder(unsigned short int a, unsigned short int b, unsigned short int cin, unsigned short int& s, unsigned short int& cout);

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

if(argc

printf("You must provide two inputs: number of test cases and number of digits ");

exit(0);

}

test_cases = atoi(argv[1]); // number of test cases

digits = atoi(argv[2]); // number of digits

double exec = omp_get_wtime();

for(int test=1; test

string A = "";

string B = "";

string C = ""; // C = A * B

// initialize A to random decimal integer

for(int j=1; j

int x = rand() % 10;

A = A + to_string(x);

}

// initialize B to random decimal integer

for(int j=1; j

int x = rand() % 10;

B = B + to_string(x);

}

//******************************************//

// your code starts here

// rule1: you are only allowed to perform string operations: concatation, extracting characters ot substrings, etc

// rule2: when arithmatic operations are needed, use the given functions in below. You may not use any arithmatic operation beyond them.

//******************************************//

print(A,B,C); // do not print when measuring execution times

}

exec = omp_get_wtime() - exec;

cout

return 0;

}

//******************************************//

void OneDigitAdder(unsigned short int a, unsigned short int b, unsigned short int cin, unsigned short int& s, unsigned short int& cout){

assert(a

unsigned short int ans = a + b + cin;

s = ans % 10;

cout = ans / 10;

}

void OneDigitMultiplier(unsigned short int a, unsigned short int b, unsigned short int cin, unsigned short int& s, unsigned short int& cout){

assert(a

unsigned short int ans = a * b + cin;

s = ans % 10;

cout = ans / 10;

}

unsigned short int value(char c){

assert(c = '0');

return (int) c - 48;

}

void print(string A, string B, string C){

cout

cout

for(int i=0; i

cout

cout

}

You are required to write a parallel OpenMP program that performs multiplication for two n digits decimal integers using the basic simple algorithm you learned in primary school. You may do this homework in teams of two students. Tasks: 1. In homework\#2, you have developed a serial version of the multiplication operation. Your task now is to simply parallelize your own code using loop-level parallelism in OpenMP. 2. You will be given the file omp.c, put all of your code there. Do not create any additional files. 3. Same as homework\#2, you are only allowed to perform string operations. When arithmetic operations are needed, you may use the given two functions in homework\#1: OneDigitAdder and OneDigitMultiplier. 4. My loop, which is the loop that iterates over tests must remain sequential. Instead, try to parallelize your own loop(s). 5. Make sure parallelism overheads are minimized. 6. You may declare additional strings or arrays of strings, if needed. 7. Report execution time using the below table (make sure you disable any printing when measuring final execution times). Correctness checks: 83993015273964920230111396350338091603218029991444141719756118238037939485783882192885231876788272668989251240849445798314495943084813082106231050973505553295736703219900194408241381575833827959497925885528772206746515609867036 (c) All Rights Reserved

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!