#include <stdio.h>
#include <iostream>
#include <omp.h>
#include <vector>
#include <stack>
#include <queue>
#include <climits>
using namespace std;



vector<int> arr;


void initialize(int size){
	srand(time(0));

	arr.resize(size, 1);	

	for(int i = 0; i < arr.size(); i++){
		arr[i] = rand() % arr.size();
	}

}



void summation_p(){
	int sum = 0;
	
	#pragma omp paralle for reduction(+:sum)
	for(int i = 0; i < arr.size(); i++){
		sum += arr[i];

	}

	cout << sum << endl;

}




void summation(){
        int sum = 0;

       // #pragma omp paralle for reduction(+:sum)
        for(int i = 0; i < arr.size(); i++){
                sum += arr[i];

        }

        cout << sum << endl;

}




void avger_p(){
        int sum = 0;

        #pragma omp paralle for reduction(+:sum)
        for(int i = 0; i < arr.size(); i++){
                sum += arr[i];

        }

        cout << float(float(sum)/float(arr.size())) << endl;

}


void avger(){
        int sum = 0;

//        #pragma omp paralle for reduction(+:sum)
        for(int i = 0; i < arr.size(); i++){
                sum += arr[i];

        }

        cout <<float( float(sum)/ float(arr.size())) << endl;

}





void maxi_p(){
        int maxi = INT_MIN;

        #pragma omp paralle for reduction(max: maxi)
        for(int i = 0; i < arr.size(); i++){
                if(arr[i] > maxi){
			maxi = arr[i];
		}

        }

        cout << maxi << endl;

}

void maxi(){
        int maxi = INT_MIN;

 //       #pragma omp paralle for reduction(max: maxi)
        for(int i = 0; i < arr.size(); i++){
                if(arr[i] > maxi){
                        maxi = arr[i];
                }

        }

        cout << maxi << endl;

}




void mini_p(){
        int mini = INT_MAX;

        #pragma omp paralle for reduction(min: mini)
        for(int i = 0; i < arr.size(); i++){
                if(arr[i] < mini){
                        mini = arr[i];
                }

        }

        cout << mini << endl;

}




void mini(){
        int mini = INT_MAX;

//        #pragma omp paralle for reduction(min: mini)
        for(int i = 0; i < arr.size(); i++){
                if(arr[i] < mini){
                        mini = arr[i];
                }

        }

        cout << mini << endl;

}




int main(){
	
	initialize(4096);

	double start, end;

	start = omp_get_wtime();
	mini();
	end = omp_get_wtime();

	cout << (end - start) << endl;


        start = omp_get_wtime();
        mini_p();
        end = omp_get_wtime();

        cout << (end - start) << endl;



        start = omp_get_wtime();
        maxi();
        end = omp_get_wtime();

        cout << (end - start) << endl;




        start = omp_get_wtime();
        maxi_p();
        end = omp_get_wtime();

        cout << (end - start) << endl;






        start = omp_get_wtime();
        summation_p();
        end = omp_get_wtime();

        cout << (end - start) << endl;






        start = omp_get_wtime();
        summation();
        end = omp_get_wtime();

        cout << (end - start) << endl;








        start = omp_get_wtime();
        avger_p();
        end = omp_get_wtime();

        cout << (end - start) << endl;





        start = omp_get_wtime();
        avger();
        end = omp_get_wtime();

        cout << (end - start) << endl;




	return 0;
}
