Answers for "openmp program to find the dot product of two vectors"

C
1

openmp program to find the dot product of two vectors

#include <omp.h>

main ()
{
  int   i, n, chunk;
  float a[100], b[100], result;

  /* Some initializations */
  n = 100;
  chunk = 10;
  result = 0.0;
  for (i=0; i < n; i++) {
      a[i] = i * 1.0;
      b[i] = i * 2.0;
  }

  #pragma omp parallel for      \  
      default(shared) private(i)  \  
      schedule(static,chunk)      \  
      reduction(+:result)  

    for (i=0; i < n; i++)
        result += (a[i] * b[i]);

  printf("Final result= %f\n",result);
}
Posted by: Guest on September-12-2021

Code answers related to "openmp program to find the dot product of two vectors"

Code answers related to "C"

Browse Popular Code Answers by Language