
#include <iostream>
#include <cstdlib>
using namespace std;

#include "tbb/task_scheduler_init.h"
#include "tbb/tick_count.h"
using namespace tbb;

#include "sudoku.h"
#include "SudokuTask.h"

int main(int argc, char* argv[]) {
	cout << "Sudoku Solver Using Intel's Threading Building Blocks." << endl;

	task_scheduler_init init(argc==3 ? atoi(argv[2]) : task_scheduler_init::default_num_threads());

	Sudoku* puzzle=new Sudoku;
	puzzle->read(argv[1]);
	puzzle->print();

	unsigned long subtasks=0;
	SudokuTask* root=new(task::allocate_root())SudokuTask(puzzle,&subtasks);

	tick_count t0=tick_count::now();
	task::spawn_root_and_wait(*root);
	tick_count t1=tick_count::now();

	cout << "Found " << subtasks << " tasks to be evaluated." << endl;
	cout << "Searching time was " << (t1-t0).seconds() << "." << endl;

	return 0;
}
