public static void main(String[] args) {
		
		//file names to be analyzed.
		String fileName1 = "resources/text1.txt";
		String fileName2 = "resources/text2.txt";
		
		//Cache for stemming.
		HashMap<String, String> cache = new HashMap<String, String>();
						
		long t = System.currentTimeMillis();
		
		//Create a count down latch object.
		CountDownLatch cdl = new CountDownLatch(2);
		
		//Create 2 workers - 1 for each document.
		Worker w1 = new Worker(fileName1, cdl, cache);
		Worker w2 = new Worker(fileName2, cdl, cache);

		//Create threads and run them.
		Thread th1 = new Thread(w1);
		Thread th2 = new Thread(w2);
		th1.start();
		th2.start();
		
		//wait on latch before continuing.
		try {
			cdl.await();
		} catch (InterruptedException e) {
			System.err.println("Error awaiting on countdown latch");
			e.printStackTrace();
		}
						
	    
	    /*
	     * Calc the cosine similarity matrix.
	     */
	    
	    int blockSize = 25; //Block size for job dispatching.
	    int numOfThreads = 5; //Number of threads to do the dot product calculations.
	    
	    //A list to hold jobs for threads. 
	    ArrayList<JobRange> jobs = new ArrayList<JobRange>();
	    
	    //Set vector sizes.
	    int numOfRows = w1.getVector().size();
	    int numOfColumns = w2.getVector().size();
	    
	    //Create a matrix for results.
		double[][] result = new double[numOfRows][numOfColumns];	
	    
	    //Create jobs.
		for (int i = 0; i < numOfRows; i+=blockSize) {
			for (int j = 0; j < numOfColumns; j+=blockSize) {
				jobs.add(new JobRange(i, (((i+blockSize-1)>numOfRows)? numOfRows-1 :(i+blockSize-1)), j, (((j+blockSize-1)>numOfColumns)? numOfColumns-1 :(j+blockSize-1))));
			}
		}

		//Create a new count down latch object.
		cdl = new CountDownLatch(numOfThreads);
		
		//Create threads and run them.
		for (int i = 0; i < numOfThreads; i++) {
			new Thread(new DotProduct(jobs, w1.getVector(), w2.getVector(),
					result, cdl)).start();
		}

		//wait on latch before continuing.
		try {
			cdl.await();
		} catch (InterruptedException e) {
			System.err.println("Error awaiting on countdown latch");
			e.printStackTrace();
		}
		
	    //Create a string representation of the result matrix.
	    String matrix = PrintMatrix(numOfRows, numOfColumns, result);
	    
	    /*
	     * Print matrix to screen
	     * //TODO To print the result matrix to the standard output, please uncomment the requiered line:
	     * 
	     * System.out.println(matrix);
	     *    
	     */
	    
	    //Write matrix to file.
	    System.out.println("Writing result matrix to file...");
		try {
			Utils.INSTANCE.writeToFile("output.txt", matrix);
		} catch (IOException e) {
			System.err.println("Error writing to file.");
			e.printStackTrace();
		}
	    System.out.println("Process took " + (System.currentTimeMillis() - t));

	}