test_class.declarator: sum
test_class.original_string: long sum;
test_class.type: long
test_class.var_name: sum
test_class.file: src/parallel/ParallelTest.java
test_class.identifier: ParallelTest
test_case.body: @Test
  	public void test ()
  	{
  		Random rgen = new Random();
  		int HK = 1000000; 
  		List<Short> array = new ArrayList<Short>(HK);
  		long expTotal = 0;
  		for (int i=0; i<HK; i++)
  		{
  			array.add((short) (rgen.nextInt() % Short.MAX_VALUE));
  			expTotal += array.get(i);
  		}
  		
  		long startTime = System.currentTimeMillis();
  		long endTime;
  		try {
  			sum = 0;
  			final Lock lock = new ReentrantLock();
  			Parallel.For(array, new Parallel.Operation<Short>() {
  				@Override
  				public void perform(int index, Short pParameter) {
  					lock.lock();
  					sum += pParameter;
  					lock.unlock();
  				}
  			});
  		} finally {
  			endTime = System.currentTimeMillis();
  		}
  		long duration = endTime - startTime;
  		System.out.println ("Parallel took " + duration+ " milliseconds");
  		assertTrue(sum == expTotal);
  	
  		startTime = System.currentTimeMillis();
  		ReducibleTotaller mrt = new ReducibleTotaller();
  		try {
  			mrt = ThreadPool.mapReduce (array, mrt, 
  					new ThreadPool.Operation<ReducibleTotaller,Short>() {
  						public void perform(ReducibleTotaller tot, int index, Short val)
  						{
  							tot.add(val);
  						}
  			});
  			
  		} finally {
  			endTime = System.currentTimeMillis();
  		}
  		duration = endTime - startTime;
  		System.out.println ("Mapreduce took " + duration+ " milliseconds");
  		assertTrue(mrt.sum == expTotal);
  	}
test_case.class_method_signature: ParallelTest.test()
test_case.full_signature: @Test public void test()
test_case.identifier: test
test_case.invocations: add nextInt get currentTimeMillis For lock unlock currentTimeMillis println assertTrue currentTimeMillis mapReduce add currentTimeMillis println assertTrue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void test()
focal_class.declarator: NUM_CORES = Runtime.getRuntime().availableProcessors()
focal_class.modifier: private static final
focal_class.original_string: private static final int NUM_CORES = Runtime.getRuntime().availableProcessors();
focal_class.type: int
focal_class.var_name: NUM_CORES
focal_class.declarator: forPool
focal_class.modifier: private static
focal_class.original_string: private static ExecutorService forPool;
focal_class.type: ExecutorService
focal_class.var_name: forPool
focal_class.declarator: poolSize = NUM_CORES
focal_class.modifier: private static
focal_class.original_string: private static int poolSize = NUM_CORES;
focal_class.type: int
focal_class.var_name: poolSize
focal_class.file: src/parallel/Parallel.java
focal_class.identifier: Parallel
focal_class.class_method_signature: Parallel.setPoolSize(int poolSize)
focal_class.full_signature: public static void setPoolSize(int poolSize)
focal_class.identifier: setPoolSize
focal_class.modifiers: public static
focal_class.parameters: (int poolSize)
focal_class.return: void
focal_class.signature: void setPoolSize(int poolSize)
focal_class.class_method_signature: Parallel.For(final Collection<T> pElements, final Operation<T> pOperation)
focal_class.full_signature: public static void For(final Collection<T> pElements, final Operation<T> pOperation)
focal_class.identifier: For
focal_class.modifiers: public static
focal_class.parameters: (final Collection<T> pElements, final Operation<T> pOperation)
focal_class.return: void
focal_class.signature: void For(final Collection<T> pElements, final Operation<T> pOperation)
focal_class.class_method_signature: Parallel.shutdown()
focal_class.full_signature: public void shutdown()
focal_class.identifier: shutdown
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void shutdown()
focal_method.body: public static <T,F> void For(final Collection<T> pElements, final Operation<T> pOperation) {
  		forPool = Executors.newFixedThreadPool(poolSize);
  		
  		List<Future<?>> futures = new LinkedList<Future<?>>();
  		List<Pair<Integer,T>> indexedElements = new ArrayList<Pair<Integer,T>>(pElements.size());
  		
  		int index = 0;
  		for(final T element : pElements)
  		{
  			indexedElements.add( new Pair<Integer,T>(index,element) );
  			index++;
  		}
  		int size = index;
  		
  		for (final Pair<Integer,T> element : indexedElements) {
  			try{
  				Future<?> future = forPool.submit(new Runnable() {
  					@Override
  					public void run() {
  						pOperation.perform(element.getFirst(), element.getSecond());					
  					}
  				});
  				futures.add(future);
  			}
  			catch(Exception e)
  			{
  				System.err.println(e.getMessage());
  				e.printStackTrace();
  			}
  			
  		}
  
  		int numComplete = 0;
  		for (Future<?> f : futures) {
  			try {
  				f.get();
  				numComplete++;
  				if (numComplete % 5000 == 0)
  					System.out.printf (".");
  			} catch (InterruptedException e) {
  				System.err.println(e.getMessage());
  			} catch (ExecutionException e) {
  				System.err.println(e.getMessage());
  			} catch (Exception e) {
  				System.err.println(e.getMessage());
  			}
  		}
  		if (size > 5000)
  			System.out.printf ("\n");
  		
  		forPool.shutdown();
  	}
focal_method.class_method_signature: Parallel.For(final Collection<T> pElements, final Operation<T> pOperation)
focal_method.full_signature: public static void For(final Collection<T> pElements, final Operation<T> pOperation)
focal_method.identifier: For
focal_method.invocations: newFixedThreadPool size add submit perform getFirst getSecond add println getMessage printStackTrace get printf println getMessage println getMessage println getMessage printf shutdown
focal_method.modifiers: public static
focal_method.parameters: (final Collection<T> pElements, final Operation<T> pOperation)
focal_method.return: void
focal_method.signature: void For(final Collection<T> pElements, final Operation<T> pOperation)