fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <omp.h>
  5.  
  6. int main(void) {
  7. int thread_count = 100;
  8. const int n = 1000;
  9. int x[n];
  10.  
  11. for (int i = 0; i < n; i++) {
  12. x[i] = 1;
  13. }
  14. int sum = 0;
  15.  
  16. printf("within %d threads and vector of size %d each element of value 1 \n", thread_count, n);
  17.  
  18. double stime, ftime, exec_time;
  19. //.................................
  20.  
  21. # pragma omp parallel for num_threads(thread_count) reduction(+:sum) schedule(static, 2)
  22. for (int i = 0; i < n; i++) {
  23. sum += x[i];
  24. }
  25.  
  26. //.................................
  27. //.................................
  28.  
  29. printf("sum = %d", sum);
  30. //printf("\n\nTime taken is ====> %f\n", exec_time);
  31.  
  32.  
  33. return 0;
  34. } /* main */
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
within 100 threads and vector of size 1000 each element of value 1 
sum = 1000