Search in sources :

Example 1 with IntelInflaterFactory

use of com.intel.gkl.compression.IntelInflaterFactory in project gatk by broadinstitute.

the class CommandLineProgram method instanceMainPostParseArgs.

public Object instanceMainPostParseArgs() {
    // Provide one temp directory if the caller didn't
    if (this.TMP_DIR == null)
        this.TMP_DIR = new ArrayList<>();
    if (this.TMP_DIR.isEmpty())
        TMP_DIR.add(IOUtil.getDefaultTmpDir());
    // Build the default headers
    final ZonedDateTime startDateTime = ZonedDateTime.now();
    this.defaultHeaders.add(new StringHeader(commandLine));
    this.defaultHeaders.add(new StringHeader("Started on: " + Utils.getDateTimeForDisplay(startDateTime)));
    // propagate the VERBOSITY level to logging frameworks
    LoggingUtils.setLoggingLevel(VERBOSITY);
    for (final File f : TMP_DIR) {
        // need a tmp_dir. If this fails, the problem will be discovered downstream.
        if (!f.exists())
            f.mkdirs();
        f.setReadable(true, false);
        f.setWritable(true, false);
        // in loop so that last one takes effect
        System.setProperty("java.io.tmpdir", f.getAbsolutePath());
    }
    //Set defaults (note: setting them here means they are not controllable by the user)
    if (!useJdkDeflater) {
        BlockCompressedOutputStream.setDefaultDeflaterFactory(new IntelDeflaterFactory());
    }
    if (!useJdkInflater) {
        BlockGunzipper.setDefaultInflaterFactory(new IntelInflaterFactory());
    }
    if (!QUIET) {
        System.err.println("[" + Utils.getDateTimeForDisplay(startDateTime) + "] " + commandLine);
        // Output a one liner about who/where and what software/os we're running on
        try {
            System.err.println("[" + Utils.getDateTimeForDisplay(startDateTime) + "] Executing as " + System.getProperty("user.name") + "@" + InetAddress.getLocalHost().getHostName() + " on " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch") + "; " + System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version") + "; Version: " + getVersion());
            // Print important settings to the logger:
            printSettings();
        } catch (final Exception e) {
        /* Unpossible! */
        }
    }
    try {
        return runTool();
    } finally {
        // Emit the time even if program throws
        if (!QUIET) {
            final ZonedDateTime endDateTime = ZonedDateTime.now();
            final double elapsedMinutes = (Duration.between(startDateTime, endDateTime).toMillis()) / (1000d * 60d);
            final String elapsedString = new DecimalFormat("#,##0.00").format(elapsedMinutes);
            System.err.println("[" + Utils.getDateTimeForDisplay(endDateTime) + "] " + getClass().getName() + " done. Elapsed time: " + elapsedString + " minutes.");
            System.err.println("Runtime.totalMemory()=" + Runtime.getRuntime().totalMemory());
        }
    }
}
Also used : IntelDeflaterFactory(com.intel.gkl.compression.IntelDeflaterFactory) StringHeader(htsjdk.samtools.metrics.StringHeader) ZonedDateTime(java.time.ZonedDateTime) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) IntelInflaterFactory(com.intel.gkl.compression.IntelInflaterFactory) MetricsFile(htsjdk.samtools.metrics.MetricsFile) File(java.io.File) CommandLineException(org.broadinstitute.barclay.argparser.CommandLineException)

Example 2 with IntelInflaterFactory

use of com.intel.gkl.compression.IntelInflaterFactory in project gatk by broadinstitute.

the class IntelInflaterDeflaterIntegrationTest method deflateInflateWithIntel.

@Test
public void deflateInflateWithIntel() throws DataFormatException {
    if (!isIntelInflaterDeflaterSupported()) {
        throw new SkipException("IntelInflater/IntelDeflater not available on this platform");
    }
    // create buffers and random input
    final int LEN = 64 * 1024;
    final byte[] input = new RandomDNA().nextBases(LEN);
    final byte[] compressed = new byte[2 * LEN];
    final byte[] result = new byte[LEN];
    final IntelInflaterFactory intelInflaterFactory = new IntelInflaterFactory();
    final IntelDeflaterFactory intelDeflaterFactory = new IntelDeflaterFactory();
    Assert.assertTrue(intelInflaterFactory.usingIntelInflater());
    Assert.assertTrue(intelDeflaterFactory.usingIntelDeflater());
    for (int i = 0; i < 10; i++) {
        // create deflater with compression level i
        final Deflater deflater = intelDeflaterFactory.makeDeflater(i, true);
        // setup deflater
        deflater.setInput(input);
        deflater.finish();
        // compress data
        int compressedBytes = 0;
        // so this loop should always finish in one iteration
        while (!deflater.finished()) {
            compressedBytes = deflater.deflate(compressed, 0, compressed.length);
        }
        deflater.end();
        // decompress and check output == input
        Inflater inflater = intelInflaterFactory.makeInflater(true);
        inflater.setInput(compressed, 0, compressedBytes);
        inflater.inflate(result);
        inflater.end();
        Assert.assertEquals(input, result);
        // clear compressed and result buffers for next iteration
        Arrays.fill(compressed, (byte) 0);
        Arrays.fill(result, (byte) 0);
    }
}
Also used : IntelDeflaterFactory(com.intel.gkl.compression.IntelDeflaterFactory) IntelDeflater(com.intel.gkl.compression.IntelDeflater) Deflater(java.util.zip.Deflater) IntelInflaterFactory(com.intel.gkl.compression.IntelInflaterFactory) RandomDNA(org.broadinstitute.hellbender.utils.RandomDNA) Inflater(java.util.zip.Inflater) IntelInflater(com.intel.gkl.compression.IntelInflater) SkipException(org.testng.SkipException) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

IntelDeflaterFactory (com.intel.gkl.compression.IntelDeflaterFactory)2 IntelInflaterFactory (com.intel.gkl.compression.IntelInflaterFactory)2 IntelDeflater (com.intel.gkl.compression.IntelDeflater)1 IntelInflater (com.intel.gkl.compression.IntelInflater)1 MetricsFile (htsjdk.samtools.metrics.MetricsFile)1 StringHeader (htsjdk.samtools.metrics.StringHeader)1 File (java.io.File)1 DecimalFormat (java.text.DecimalFormat)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 Deflater (java.util.zip.Deflater)1 Inflater (java.util.zip.Inflater)1 CommandLineException (org.broadinstitute.barclay.argparser.CommandLineException)1 RandomDNA (org.broadinstitute.hellbender.utils.RandomDNA)1 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)1 SkipException (org.testng.SkipException)1 Test (org.testng.annotations.Test)1