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 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 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
