Question: #include #include using namespace std; #define ORDER 500 #define AVAL 3.0 #define BVAL 5.0 #define TOL 0.001 #define Ndim ORDER #define Pdim ORDER #define Mdim
#include
#include
using namespace std;
#define ORDER 500
#define AVAL 3.0
#define BVAL 5.0
#define TOL 0.001
#define Ndim ORDER
#define Pdim ORDER
#define Mdim ORDER
int main(int argc, char **argv)
{
double A[Ndim][Pdim], B[Pdim][Mdim], C[Ndim][Mdim];
int i,j,k;
//double *A, *B, *C,
double cval, tmp, err, errsq;
double dN, mflops;
double start_time, run_time;
double sum;
start_time = omp_get_wtime();
/* Initialize matrices */
for (i=0; i
for (j=0; j
A[i][j] = AVAL;
for (i=0; i
for (j=0; j
B[i][j] = BVAL;
for (i=0; i
for (j=0; j
C[i][j] = 0.0;
/* Do the matrix product */
for (i=0; i
for (j=0; j
tmp = 0.0;
for(k=0;k
/* C(i,j) = sum(over k) A(i,k) * B(k,j) */
tmp += A[i][k] * B[k][j];
}
C[i][j] = tmp;
sum += tmp;
}
}
/* Check the answer */
cout << "Summary is " << sum << endl;
cval = Pdim * AVAL * BVAL;
errsq = 0.0;
for (i=0; i
for (j=0; j
err = C[i][j] - cval;
errsq += err * err;
}
}
errsq += sum - cval*Ndim*Mdim;
if (errsq > TOL)
cout << "Errors in multiplication: "<< errsq<< endl;
else
cout << "Hey, it worked! Error is: " << errsq << endl;
run_time = omp_get_wtime() - start_time;
cout << "Order " << ORDER << " multiplication in " << run_time << " seconds "<< endl;
dN = (double)ORDER;
mflops = 2.0 * dN * dN * dN/(1000000.0* run_time);
cout << "Order " << " multiplication at " << mflops << " mflops" << endl;
cout << "All done "<< endl;
return 0;
}
Convert to PARALLEL CODE please, thank you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
