#include "bsp_5_3_lib.h"
#include "mayer_primes.h"
#include <iostream>
#include <algorithm>
#include <chrono>
// BSP 5_3 Goldbach conjunction
using namespace std;

int main()
{
	omp_set_num_threads(8);
	
	cout << "\nChecking for correct result\n";
	cout << "694 has " << single_goldbach_par(694) << " decompositions" << endl;
	
    // Auswertung für n=100000 bzw herausfinden der Zahl, welche die meisten Dekompositionen hat
    vector<int> v = count_goldbach_par(1e5);
    auto ip = max_element(v.begin(), v.end());
    cout << "number in [4,1e5] with most decompositions: " << distance(v.begin(), ip)*2+4 << " has " << *ip << " decompositions" << endl;

    cout << "\nTiming for parallel" << endl;
    vector<int> nvec{static_cast<int>(1e4), static_cast<int>(1e5), static_cast<int>(4*1e5), static_cast<int>(1e6), static_cast<int>(2*1e6)}; // Vektor für n
    for(size_t k=0; k<nvec.size(); ++k)
    {
        auto timestart = omp_get_wtime();
        vector<int> vall = count_goldbach_par(nvec[k]);
        auto time = omp_get_wtime() - timestart;
        cout << "n = " << nvec[k] << "\ttime in s: " << time << endl;
    }
    
    cout << "\nTiming for serial" << endl;
    for(size_t k=0; k<nvec.size(); ++k)
    {
        auto timestart = omp_get_wtime();
        vector<int> vall = count_goldbach(nvec[k]);
        auto time = omp_get_wtime() - timestart;
        cout << "n = " << nvec[k] << "\ttime in s: " << time << endl;
    }
    
    // for large n the parallel version is slower than the sequential
    // the reason is the reduction(VecAdd) which is slow especially for large vectors

//    cout << single_goldbach(694) << endl;
//    cout << count_goldbach(10000)[690/2] << endl;
    return 0;
}
