fork download
  1. #include <iostream> // Provides standard input/output stream functionality
  2. #include <omp.h> // Provides OpenMP directives and runtime support
  3. using namespace std; // Allows direct use of standard library identifiers
  4.  
  5. int main() // Program entry point
  6. {
  7. int n = 10; // Defines the upper limit of the summation
  8. int total = 0; // Shared variable used to store the final reduced result
  9.  
  10. // Executes the loop in parallel and performs addition reduction on 'total'
  11. #pragma omp parallel for reduction(+:total)
  12. for (int i = 1; i <= n; i++) // Iterates from 1 through n
  13. {
  14. total += i; // Adds the current iteration value to the thread's private copy
  15. }
  16.  
  17. cout << "The total is " << total << endl; // Displays the final reduced sum
  18. return 0; // Terminates the program successfully
  19. }
  20.  
Success #stdin #stdout 0s 5340KB
stdin
Standard input is empty
stdout
The total is 55