#include <iostream>
#include <chrono>
#include <omp.h>
#include <math.h>

bool isPrime(long number)
{
	//for (int a = 2; a < number; a++)
	//for (int a = 2; a < number / 2; a++)
	for (long a = 2; a <= sqrt(number); a++)
	{
		if (number % a == 0)
		{
			return false;
		}
	}
	return true;
}

int compute_primes(int amount, long min_value)
{
	int total_primes(0);
	//for (int currentNum = 2; ; currentNum++)///currentNum < maximum_value
	for (long currentNum = min_value;; currentNum++)
	{
		if (isPrime(currentNum))
		{
			//std::cout << endl << currentNum << " ";
			total_primes++;
			if (total_primes == amount) return total_primes;
		}
	}
	return 0;
}

int main()
{
	std::cout << "\nOMP: \n";
	double start_time = omp_get_wtime();//start time

    //Share the workload
	// schedule(dynamic)
    #pragma omp parallel for num_threads(4)
    for (int i = 0; i < 100; ++i) 
    {
        double prime0 = compute_primes(20000 + omp_get_thread_num() * 2, 1000000 + +omp_get_thread_num() * 2);
        std::cout << "I am thread " << omp_get_thread_num() << " and I have received index " << i << std::endl;
    }

	double end_time = omp_get_wtime();//end time
	std::cout << "\nSeconds: " << end_time - start_time; //total time
}