Question: Distributed dot product calculations My question is about Distributed dot product calculations, where I have to write a parallel MPI version of the code given
Distributed dot product calculations
My question is about Distributed dot product calculations, where I have to write a parallel MPI version of the code given below:
__________________
#include #include #include #include
#define SIZE 10000000
volatile float a[SIZE]; volatile float b[SIZE];
int main(int argc, char **argv) { long int i; double sum; struct timeval time1, time2;
srand(time(0)); for (i = 0; i < SIZE; i++) { a[i] = rand(); b[i] = rand(); } gettimeofday(&time1, 0); sum = 0.0; for (i = 0; i < SIZE; i++) { sum = sum + a[i]*b[i]; }
gettimeofday(&time2, 0); printf("Elapsed time (us) = %d ", (time2.tv_sec-time1.tv_sec)*1000000 + time2.tv_usec - time1.tv_usec);
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
