#include <iostream>
#include <vector>
#include <omp.h>
using namespace std;

int main(){
	cout<<"========================================"<<endl;
	cout<<"      OPENMP: THE PARALLEL FOR LOOP     "<<endl;
	cout<<"========================================\n"<<endl;
	const int ARRAY_SIZE=1000000;
	vector<int> numbers(ARRAY_SIZE, 1);
	long long total_sum=0;
	cout<<"[SYSTEM] Array of "<<ARRAY_SIZE<<" items initialized."<<endl;
	cout<<"[SYSTEM] Firing up the CPU cores..."<<endl;
	double start_time=omp_get_wtime();
	#pragma omp parallel for reduction(+:total_sum)
	for(int i=0; i<ARRAY_SIZE;i++){
		total_sum+=numbers[i];
	}
	double end_time=omp_get_wtime();
	cout<<"\n[RESULT] Final Sum: "<<total_sum<<" (Should be exactly 1000000)"<<endl;
	cout<<"[TIME] 1 Million items processed in "<<(end_time-start_time)<<" seconds."<<endl;
	cout<<"=================================================="<<endl;
	return 0;
}
