Esempio n. 1
0
TEST_F(ADIOSBZip2Wrapper, WrongParameterValue)
{
    /** Application variable uints from 0 to 1000 */
    std::vector<unsigned int> myUInts(100);
    std::iota(myUInts.begin(), myUInts.end(), 0.f);
    const std::size_t Nx = myUInts.size();
    const std::size_t inputBytes = Nx * sizeof(unsigned int);

    // Define ADIOS variable
    auto &var_UInt = io.DefineVariable<unsigned int>("myUInts", {}, {}, {Nx},
                                                     adios2::ConstantDims);

    // Verify the return type is as expected
    ::testing::StaticAssertTypeEq<decltype(var_UInt),
                                  adios2::Variable<unsigned int> &>();

    // Define bzip2 transform
    adios2::Operator &adiosBZip2 =
        adios.DefineOperator("BZip2Compressor", "BZip2");

    const unsigned int bzip2ID =
        var_UInt.AddTransform(adiosBZip2, {{"BlockSize100K", "10"}});

    const std::size_t estimatedSize =
        adiosBZip2.BufferMaxSize(Nx * var_UInt.m_ElementSize);
    std::vector<char> compressedBuffer(estimatedSize);

    EXPECT_THROW(size_t compressedSize = adiosBZip2.Compress(
                     myUInts.data(), var_UInt.m_Count, var_UInt.m_ElementSize,
                     var_UInt.m_Type, compressedBuffer.data(),
                     var_UInt.m_OperatorsInfo[bzip2ID].Parameters),
                 std::invalid_argument);
}
	InputCompressedFileStreamBufferData(const std::string fileName)
	:	readPosition(0)
	{
		std::ifstream stream(fileName.c_str(), std::ios::binary);
		if(!stream)
			return;

		std::filebuf *streamBuffer = stream.rdbuf();
		if(!streamBuffer)
			return;
		std::streamsize compressedSize = streamBuffer->in_avail() - sizeof(int);

		int bytes = 0;
		stream.read((char *) &bytes, sizeof(int));
		if(!bytes)
			return;

		buffer.resize(bytes);
		std::vector<char> compressedBuffer((int) compressedSize);
		stream.read(&compressedBuffer[0],  compressedSize);

		Bytef *source = (Bytef *) &compressedBuffer[0];
		uLong sourceLength = compressedBuffer.size();
		Bytef *destination = &buffer[0];
		uLong destinationLength = buffer.size();

		int code = ::uncompress(destination, &destinationLength, source, sourceLength);
		if(code != Z_OK)
			int a = 0;
	}
Esempio n. 3
0
void Logger::writeThread()
{
  OutBinaryFile file(logFilename);
  ASSERT(file.exists());
  file << logFileCompressed; // Write magic byte that indicates a compressed log file

  const size_t compressedSize = snappy_max_compressed_length(parameters.blockSize + 2 * sizeof(unsigned));
  std::vector<char> compressedBuffer(compressedSize + sizeof(unsigned)); // Also reserve 4 bytes for header

  while(writerThread.isRunning()) // Check if we are expecting more data
    if(framesToWrite.wait(100)) // Wait 100 ms for new data then check again if we should quit
    {
      writerIdle = false;
      MessageQueue& queue = *buffer[readIndex];
      if(queue.getNumberOfMessages() > 0)
      {
        size_t size = compressedSize;
        VERIFY(snappy_compress(queue.getStreamedData(), queue.getStreamedSize(),
                               compressedBuffer.data() + sizeof(unsigned), &size) == SNAPPY_OK);
        (unsigned&) compressedBuffer[0] = (unsigned) size;
        file.write(compressedBuffer.data(), size + sizeof(unsigned));
        queue.clear();
      }
      readIndex = (readIndex + 1) % parameters.maxBufferSize;
    }
    else if(!writerIdle)
    {
      writerIdle = true;
      writerIdleStart = SystemCall::getCurrentSystemTime();
    }
}
Esempio n. 4
0
TEST_F(ADIOSBZip2Wrapper, UInt100)
{
    /** Application variable uints from 0 to 1000 */
    std::vector<unsigned int> myUInts(100);
    std::iota(myUInts.begin(), myUInts.end(), 0.f);
    const std::size_t Nx = myUInts.size();
    const std::size_t inputBytes = Nx * sizeof(unsigned int);

    // Define ADIOS variable
    auto &var_UInt = io.DefineVariable<unsigned int>("myUInts", {}, {}, {Nx},
                                                     adios2::ConstantDims);

    // Verify the return type is as expected
    ::testing::StaticAssertTypeEq<decltype(var_UInt),
                                  adios2::Variable<unsigned int> &>();

    // Define bzip2 transform
    adios2::Operator &adiosBZip2 =
        adios.DefineOperator("BZip2Compressor", "BZip2");

    const unsigned int bzip2ID =
        var_UInt.AddTransform(adiosBZip2, {{"BlockSize100K", "2"}});

    const std::size_t estimatedSize =
        adiosBZip2.BufferMaxSize(Nx * var_UInt.m_ElementSize);
    std::vector<char> compressedBuffer(estimatedSize);
    size_t compressedSize = adiosBZip2.Compress(
        myUInts.data(), var_UInt.m_Count, var_UInt.m_ElementSize,
        var_UInt.m_Type, compressedBuffer.data(),
        var_UInt.m_OperatorsInfo[bzip2ID].Parameters);

    EXPECT_LE(compressedSize, estimatedSize);

    compressedBuffer.resize(compressedSize);

    // Allocate original data size
    std::vector<unsigned int> decompressedBuffer(Nx);
    size_t decompressedSize = adiosBZip2.Decompress(
        compressedBuffer.data(), compressedSize, decompressedBuffer.data(),
        decompressedBuffer.size() * sizeof(unsigned int));

    // testing data recovery
    for (size_t i = 0; i < Nx; ++i)
    {
        ASSERT_EQ(decompressedBuffer[i], myUInts[i]);
    }
}