List of usage examples for com.google.common.util.concurrent AtomicDoubleArray AtomicDoubleArray
public AtomicDoubleArray(double[] array)
From source file:com.analog.lyric.dimple.parameters.ParameterListN.java
protected ParameterListN(ParameterListN<Key> that) { AtomicDoubleArray thoseValues = that._values; int size = thoseValues.length(); _values = new AtomicDoubleArray(size); for (int i = 0; i < size; ++i) { _values.set(i, thoseValues.get(i)); }//from w ww. jav a 2s .c om AtomicIntegerArray thatFixedMask = that._fixedMask; int fixedMaskSize = thatFixedMask.length(); _fixedMask = new AtomicIntegerArray(fixedMaskSize); for (int i = 0; i < fixedMaskSize; ++i) { _fixedMask.set(i, thatFixedMask.get(i)); } }
From source file:org.kairosdb.util.UniformReservoir.java
/** * Creates a new {@link UniformReservoir}. * * @param size the number of samples to keep in the sampling reservoir *///ww w . ja va 2 s .c o m public UniformReservoir(int size) { this.values = new AtomicDoubleArray(size); for (int i = 0; i < values.length(); i++) { values.set(i, 0); } count.set(0); random = new Random(); }
From source file:com.analog.lyric.dimple.parameters.ParameterListN.java
protected ParameterListN(double... values) { _values = new AtomicDoubleArray(values); int maskSize = maskSize(values.length); _fixedMask = new AtomicIntegerArray(maskSize); }
From source file:com.analog.lyric.dimple.parameters.ParameterListN.java
protected ParameterListN(int size, double defaultValue) { _values = new AtomicDoubleArray(size); for (int i = 0; i < size; ++i) { _values.set(i, defaultValue);/* w ww. jav a 2 s. c om*/ } _fixedMask = new AtomicIntegerArray(maskSize(size)); }
From source file:com.twitter.graphjet.algorithms.MultiThreadedPageRank.java
private void iterate(double dampingAmount, LongArrayList noOuts, final LongArrayList[] nodePartitions) { AtomicDoubleArray nextPR = new AtomicDoubleArray((int) (maxNodeId + 1)); // First compute how much mass is trapped at the dangling nodes. double dangleSum = 0.0; LongIterator iter = noOuts.iterator(); while (iter.hasNext()) { dangleSum += prVector.get((int) iter.nextLong()); }//from w w w . j av a2 s . c o m dangleSum = dampingFactor * dangleSum / nodeCount; final double d = dangleSum; // We use a CountDownLatch as a sync barrier to wait for all threads to finish on their // respective partitions. final CountDownLatch latch = new CountDownLatch(threads); // Start all the worker threads over each partition. for (int i = 0; i < threads; i++) { new PageRankWorker(i, nextPR, nodePartitions[i], latch, dampingAmount + d).start(); } // Note that an alternative implementation would be to use a CyclicBarrier so we don't need to // respawn new threads each time, but for a graph of any size, the cost of respawning new // threads is small relative to the cost the actual iterations. // Wait for all the threads to finish. try { latch.await(); } catch (InterruptedException ex) { // Something bad happened, just abort. throw new RuntimeException("Error running PageRank!"); } normL1 = computeL1Norm(prVector, nextPR); prVector = nextPR; }
From source file:com.twitter.graphjet.algorithms.MultiThreadedPageRank.java
/** * Runs PageRank, either until the max number of iterations has been reached or the L1 norm of * the difference between PageRank vectors drops below the tolerance. * * @return number of iterations that was actually run *///ww w . j av a2 s . c o m public int run() { LongArrayList noOuts = new LongArrayList(); LongIterator iter = nodes.iterator(); while (iter.hasNext()) { long v = iter.nextLong(); if (graph.getOutDegree(v) == 0) { noOuts.add(v); } } double dampingAmount = (1.0 - dampingFactor) / nodeCount; prVector = new AtomicDoubleArray((int) (maxNodeId + 1)); nodes.forEach(v -> prVector.set((int) (long) v, 1.0 / nodeCount)); // We're going to divide the nodes into partitions, one for each thread. LongArrayList[] nodePartitions = new LongArrayList[threads]; int partitionSize = nodes.size() / threads; for (int i = 0; i < threads; i++) { int startPos = i * partitionSize; // The final partition get the rest of the nodes. int endPos = i == (threads - 1) ? nodes.size() : (i + 1) * partitionSize; nodePartitions[i] = new LongArrayList(nodes.subList(startPos, endPos)); } int i = 0; while (i < this.maxIterations && normL1 > tolerance) { iterate(dampingAmount, noOuts, nodePartitions); i++; } return i; }
From source file:org.apache.hadoop.ipc.DecayRpcScheduler.java
/** * Create a decay scheduler./*from w ww.j a va2 s.c om*/ * @param numLevels number of priority levels * @param ns config prefix, so that we can configure multiple schedulers * in a single instance. * @param conf configuration to use. */ public DecayRpcScheduler(int numLevels, String ns, Configuration conf) { if (numLevels < 1) { throw new IllegalArgumentException("Number of Priority Levels must be " + "at least 1"); } this.numLevels = numLevels; this.namespace = ns; this.decayFactor = parseDecayFactor(ns, conf); this.decayPeriodMillis = parseDecayPeriodMillis(ns, conf); this.identityProvider = this.parseIdentityProvider(ns, conf); this.thresholds = parseThresholds(ns, conf, numLevels); this.backOffByResponseTimeEnabled = parseBackOffByResponseTimeEnabled(ns, conf); this.backOffResponseTimeThresholds = parseBackOffResponseTimeThreshold(ns, conf, numLevels); // Setup response time metrics responseTimeTotalInCurrWindow = new AtomicLongArray(numLevels); responseTimeCountInCurrWindow = new AtomicLongArray(numLevels); responseTimeAvgInLastWindow = new AtomicDoubleArray(numLevels); responseTimeCountInLastWindow = new AtomicLongArray(numLevels); topUsersCount = conf.getInt(DECAYSCHEDULER_METRICS_TOP_USER_COUNT, DECAYSCHEDULER_METRICS_TOP_USER_COUNT_DEFAULT); Preconditions.checkArgument(topUsersCount > 0, "the number of top users for scheduler metrics must be at least 1"); // Setup delay timer Timer timer = new Timer(); DecayTask task = new DecayTask(this, timer); timer.scheduleAtFixedRate(task, decayPeriodMillis, decayPeriodMillis); metricsProxy = MetricsProxy.getInstance(ns, numLevels); metricsProxy.setDelegate(this); }