Example usage for java.lang Long SIZE

List of usage examples for java.lang Long SIZE

Introduction

In this page you can find the example usage for java.lang Long SIZE.

Prototype

int SIZE

To view the source code for java.lang Long SIZE.

Click Source Link

Document

The number of bits used to represent a long value in two's complement binary form.

Usage

From source file:com.alibaba.jstorm.utils.JStormUtils.java

public static long bytesToLong(byte[] bytes) {
    ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE);
    buffer.put(bytes);// w w  w  .  j a  v a  2 s .c o m
    buffer.flip();// need flip
    return buffer.getLong();
}

From source file:it.unimi.dsi.webgraph.algo.HyperBall.java

/** Performs a new iteration of HyperBall. */
public void iterate() throws IOException {
    ensureOpen();/*from ww  w.  j  ava2  s  .co m*/
    try {
        iteration++;

        // Let us record whether the previous computation was systolic or local.
        final boolean previousWasSystolic = systolic;
        final boolean previousWasLocal = local;

        /* If less than one fourth of the nodes have been modified, and we have the transpose, 
         * it is time to pass to a systolic computation. */
        systolic = gotTranspose && iteration > 0 && modified.get() < numNodes / 4;

        /* Non-systolic computations add up the value of all counter. 
         * Systolic computations modify the last value by compensating for each modified counter. */
        current = systolic ? last : 0;

        // If we completed the last iteration in pre-local mode, we MUST run in local mode.
        local = preLocal;

        // We run in pre-local mode if we are systolic and few nodes where modified.
        preLocal = systolic && modified.get() < .1 * numNodes * numNodes / numArcs;

        info("Starting " + (systolic ? "systolic iteration (local: " + local + "; pre-local: " + preLocal + ")"
                : "standard " + (external ? "external " : "") + "iteration"));

        if (!external) {
            if (previousWasLocal)
                for (int x : localCheckList)
                    modifiedResultCounter[x] = false;
            else
                BooleanArrays.fill(modifiedResultCounter, false);
            assert !BooleanUtils.or(modifiedResultCounter);
        }

        if (local) {
            /* In case of a local computation, we convert the set of must-be-checked for the 
             * next iteration into a check list. */
            localCheckList = localNextMustBeChecked.toIntArray();
            Arrays.sort(localCheckList);
            localNextMustBeChecked.clear();
        } else if (systolic) {
            // Systolic, non-local computations store the could-be-modified set implicitly into this array.
            BooleanArrays.fill(nextMustBeChecked, false);
            // If the previous computation wasn't systolic, we must assume that all registers could have changed.
            if (!previousWasSystolic)
                BooleanArrays.fill(mustBeChecked, true);
        }

        adaptiveGranularity = granularity;

        if (numberOfThreads > 1 && !local) {
            if (iteration > 0) {
                adaptiveGranularity = (long) Math.min(Math.max(1, numNodes / numberOfThreads),
                        granularity * (numNodes / Math.max(1., modified())));
                adaptiveGranularity = (adaptiveGranularity + Long.SIZE - 1) & ~(Long.SIZE - 1);
            }
            info("Adaptive granularity for this iteration: " + adaptiveGranularity);
        }

        modified.set(0);
        totalIoMillis = 0;
        numberOfWrites = 0;
        final ProgressLogger npl = pl == null ? null : new ProgressLogger(LOGGER, 1, TimeUnit.MINUTES, "arcs");

        if (npl != null) {
            arcs.set(0);
            npl.expectedUpdates = systolic || local ? -1 : numArcs;
            npl.start("Scanning graph...");
        }

        nodes.set(0);
        nextArcs = nextNode = 0;
        unwritten.set(0);
        if (external)
            fileChannel.position(0);

        // Start all threads.
        lock.lock();
        try {
            phase = 0;
            aliveThreads = numberOfThreads;
            start.signalAll();

            // Wait for all threads to complete their tasks, logging some stuff in the mean time.
            while (aliveThreads != 0) {
                allWaiting.await(1, TimeUnit.MINUTES);
                if (threadThrowable != null)
                    throw new RuntimeException(threadThrowable);
                final int aliveThreads = this.aliveThreads;
                if (npl != null && aliveThreads != 0) {
                    if (arcs.longValue() != 0)
                        npl.set(arcs.longValue());
                    if (external && numberOfWrites > 0) {
                        final long time = npl.millis();
                        info("Writes: " + numberOfWrites + "; per second: "
                                + Util.format(1000.0 * numberOfWrites / time));
                        info("I/O time: " + Util.format((totalIoMillis / 1000.0)) + "s; per write: "
                                + (totalIoMillis / 1000.0) / numberOfWrites + "s");
                    }
                    if (aliveThreads != 0)
                        info("Alive threads: " + aliveThreads + " ("
                                + Util.format(100.0 * aliveThreads / numberOfThreads) + "%)");
                }
            }
        } finally {
            lock.unlock();
        }

        if (npl != null) {
            npl.done(arcs.longValue());
            if (!external)
                info("Unwritten counters: " + Util.format(unwritten.intValue()) + " ("
                        + Util.format(100.0 * unwritten.intValue() / numNodes) + "%)");
            info("Unmodified counters: " + Util.format(numNodes - modified.intValue()) + " ("
                    + Util.format(100.0 * (numNodes - modified.intValue()) / numNodes) + "%)");
        }

        if (external) {
            if (npl != null) {
                npl.itemsName = "counters";
                npl.start("Updating counters...");
            }

            // Read into memory the newly computed counters.

            fileChannel.truncate(fileChannel.position());
            fileChannel.position(0);

            // In pre-local mode, we do not clear modified counters.
            if (!preLocal)
                BooleanArrays.fill(modifiedCounter, false);

            lock.lock();
            try {
                phase = 1;
                //System.err.println( "Starting phase 1..." );
                aliveThreads = numberOfThreads;
                start.signalAll();
                // Wait for all threads to complete the counter update.
                if (aliveThreads != 0)
                    allWaiting.await();
                if (threadThrowable != null)
                    throw new RuntimeException(threadThrowable);
            } finally {
                lock.unlock();
            }

            if (npl != null) {
                npl.count = modified();
                npl.done();
            }
        } else {
            // Switch the bit vectors.
            for (int i = 0; i < bits.length; i++) {
                if (npl != null)
                    npl.update(bits[i].length);
                final LongBigList r = registers[i];
                registers[i] = resultRegisters[i];
                resultRegisters[i] = r;
                final long[] b = bits[i];
                bits[i] = resultBits[i];
                resultBits[i] = b;
            }

            // Switch modifiedCounters and modifiedResultCounters.
            final boolean[] t = modifiedCounter;
            modifiedCounter = modifiedResultCounter;
            modifiedResultCounter = t;
        }

        if (systolic) {
            // Switch mustBeChecked and nextMustBeChecked.
            final boolean[] t = mustBeChecked;
            mustBeChecked = nextMustBeChecked;
            nextMustBeChecked = t;
        }

        last = current;
        /* We enforce monotonicity. Non-monotonicity can only be caused
         * by approximation errors. */
        final double lastOutput = neighbourhoodFunction.getDouble(neighbourhoodFunction.size() - 1);
        if (current < lastOutput)
            current = lastOutput;
        relativeIncrement = current / lastOutput;

        if (pl != null) {
            pl.logger().info("Pairs: " + current + " (" + current * 100.0 / squareNumNodes + "%)");
            pl.logger().info("Absolute increment: " + (current - lastOutput));
            pl.logger().info("Relative increment: " + relativeIncrement);
        }

        neighbourhoodFunction.add(current);

        if (pl != null)
            pl.updateAndDisplay();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}