/** * NOTICE: This program was developed as part of a graduate-level project for my M.S. in Computer Science at the University of West Florida * * Main Driver class for Collatz Sequence Project: * This program utilizes Threads to generate a Collatz sequence for numbers 2 to N and calculates the frequency of Collatz Stopping Times * * @author Lorenzo Waguespack * @date 7/5/2020 * @info Course COP5518 - University of West Florida * */ package driver; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import threads.CThread; import threads.ThreadData; public class CollatzSeq { public static void main(String[] args) { CThread ct = new CThread(); Instant start = Instant.now(); Instant end; Duration diff; int usrRange = Integer.parseInt(args[0]); int usrThreads = Integer.parseInt(args[1]); ThreadData shared = new ThreadData(usrRange,usrThreads); ArrayList<Thread> threadList = new ArrayList<Thread>(); for (int i=0; i<usrThreads; i++) { ct = new CThread("Thread"+(i+1),shared,usrRange); //Adds thread to threadList based on number indicated by user threadList.add(ct); } for (Thread t:threadList) { t.start(); } try { for (Thread t:threadList) { t.join(); //Joins threads once completed } } catch (Exception e) { System.err.println("Unable to join threads."); } int[] completeHist = shared.getHistogramArray(); //Return Histogram array and print frequencies to stdout from 1 to k (Largest stopping time) int k = shared.getLargestST(); int freq; for (int s=0; s<k; s++) { freq = 0; for (int j=0; j<completeHist.length; j++) { if (completeHist[j] == (s+1)) { freq++; } } System.out.println("<" + (s + 1) + ">,<" + freq + ">"); } end = Instant.now(); //Get the stopping time of the program to calculate total duration diff = Duration.between(start, end); System.out.println("\n"); System.err.println(usrRange + "," + usrThreads + "," + diff.toSecondsPart() + "." + diff.toNanosPart()); } }