#include <iostream>
#include <tbb/parallel_sort.h>
#include <tbb/task_scheduler_init.h>
#include <tbb/tick_count.h>
#include <math.h>

#define N 5000000

using namespace std;
using namespace tbb;

void SortExample(float *x)
{
	for( int i = 0; i < N; i++ ) {
		x[i] = (float) rand() / RAND_MAX;
	}

	parallel_sort(x, x + N);
}

int main()
{
	task_scheduler_init init;
	tick_count t_start;
	tick_count t_stop;

	float *a = (float *) malloc(N * sizeof(float));

	t_start = tick_count::now();
	SortExample(a);
	t_stop = tick_count::now();

	for (int i=0; i<5; i++) {
		printf("%8d %12.9f\n", i, a[i]);
	}
	cout << endl;
	for (int i=N-5; i<N; i++) {
		printf("%8d %12.9f\n", i, a[i]);
	}
	cout << endl;

	cout << "Time : " << (t_stop-t_start).seconds() << " s" << endl;

	return 0;
}

