/* * utiity function(s) for Java parallel programs */ package csci3366sample; public class ThreadUtility { public static class Exception extends java.lang.Exception { public Exception(String message) { super(message); } } /* get number of threads from environment variable NUM_THREADS */ public static int getNumThreads() throws Exception { return getIntegerEnv("NUM_THREADS"); } /* get integer environment variable */ public static int getIntegerEnv(String name) throws Exception { int n = 0; try { String s = System.getenv(name); if (s == null) { throw new Exception( "environment variable " + name + " must be set"); } else { n = Integer.parseInt(s); } } catch (NumberFormatException e) { throw new Exception("non-numeric value for " + name); } return n; } }