Skip to content
Snippets Groups Projects
Commit 75ded757 authored by Wang, Ruonan's avatar Wang, Ruonan
Browse files

finished DataMan Transport Manager refactoring, but full functionality still pending on Read API

parents 9b3ca773 ad527fdd
No related branches found
No related tags found
1 merge request!270Finished DataMan Transport Manager refactoring but full functionality still pending on Read API
Showing
with 595 additions and 34 deletions
...@@ -55,31 +55,40 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) ...@@ -55,31 +55,40 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
include(CMakeDependentOption) include(CMakeDependentOption)
# Setup shared library / -fPIC stuff # Setup shared library defaults. If explicitly specified somehow, then default
# to that. Otherwise base the default on whether or not shared libs are even
# supported.
get_property(SHARED_LIBS_SUPPORTED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS) get_property(SHARED_LIBS_SUPPORTED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
if(DEFINED BUILD_SHARED_LIBS) if(DEFINED ADIOS2_BUILD_SHARED_LIBS)
set(ADIOS2_BUILD_SHARED_LIBS_DEFAULT ${BUILD_SHARED_LIBS})
elseif(DEFINED ADIOS2_BUILD_SHARED_LIBS)
set(ADIOS2_BUILD_SHARED_LIBS_DEFAULT ${ADIOS2_BUILD_SHARED_LIBS}) set(ADIOS2_BUILD_SHARED_LIBS_DEFAULT ${ADIOS2_BUILD_SHARED_LIBS})
elseif(DEFINED BUILD_SHARED_LIBS)
set(ADIOS2_BUILD_SHARED_LIBS_DEFAULT ${BUILD_SHARED_LIBS})
else() else()
set(ADIOS2_BUILD_SHARED_LIBS_DEFAULT ${SHARED_LIBS_SUPPORTED}) set(ADIOS2_BUILD_SHARED_LIBS_DEFAULT ${SHARED_LIBS_SUPPORTED})
endif() endif()
unset(BUILD_SHARED_LIBS) cmake_dependent_option(ADIOS2_BUILD_SHARED_LIBS
option(ADIOS2_BUILD_SHARED_LIBS "Build shared libraries (so/dylib/dll)." ${ADIOS2_BUILD_SHARED_LIBS}) "Build shared libraries (so/dylib/dll)." ${ADIOS2_BUILD_SHARED_LIBS_DEFAULT}
"SHARED_LIBS_SUPPORTED" OFF
)
set(BUILD_SHARED_LIBS ${ADIOS2_BUILD_SHARED_LIBS}) set(BUILD_SHARED_LIBS ${ADIOS2_BUILD_SHARED_LIBS})
if(NOT SHARED_LIBS_SUPPORTED) mark_as_advanced(BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
message(WARNING "A shared library build was requested but is not supported on this platform / compiler. Unexpected build results will likely occur") # Setup PIC defaults. If explicitly specified somehow, then default
endif() # to that. Otherwise base the default on whether or not shared libs are even
set(BUILD_SHARED_LIBS OFF) # supported.
if(DEFINED ADIOS2_ENABLE_PIC)
set(ADIOS2_ENABLE_PIC_DEFAULT ${ADIOS2_ENABLE_PIC})
elseif(DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(ADIOS2_ENABLE_PIC_DEFAULT ${CMAKE_POSITION_INDEPENDENT_CODE})
else()
set(ADIOS2_ENABLE_PIC_DEFAULT ${SHARED_LIBS_SUPPORTED})
endif() endif()
cmake_dependent_option(ADIOS2_ENABLE_PIC cmake_dependent_option(ADIOS2_ENABLE_PIC
"Build with Position Independent Code" ON "Build with Position Independent Code" ${ADIOS2_ENABLE_PIC_DEFAULT}
"SHARED_LIBS_SUPPORTED" OFF) "SHARED_LIBS_SUPPORTED" OFF
if(ADIOS2_ENABLE_PIC) )
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ${ADIOS2_ENABLE_PIC})
endif() mark_as_advanced(CMAKE_POSITION_INDEPENDENT_CODE)
adios_option(BZip2 "Enable support for BZip2 transforms" AUTO) adios_option(BZip2 "Enable support for BZip2 transforms" AUTO)
adios_option(ZFP "Enable support for ZFP transforms" AUTO) adios_option(ZFP "Enable support for ZFP transforms" AUTO)
...@@ -162,10 +171,13 @@ message("") ...@@ -162,10 +171,13 @@ message("")
message(" Installation prefix: ${CMAKE_INSTALL_PREFIX}") message(" Installation prefix: ${CMAKE_INSTALL_PREFIX}")
message(" Features:") message(" Features:")
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
message(" Library Type: shared") set(msg_lib_type "shared")
elseif(CMAKE_POSITION_INDEPENDENT_CODE)
set(msg_lib_type "static (with PIC)")
else() else()
message(" Library Type: static") set(msg_lib_type "static (without PIC)")
endif() endif()
message(" Library Type: ${msg_lib_type}")
message(" Build Type: ${CMAKE_BUILD_TYPE}") message(" Build Type: ${CMAKE_BUILD_TYPE}")
message(" Testing: ${BUILD_TESTING}") message(" Testing: ${BUILD_TESTING}")
message(" Build Options:") message(" Build Options:")
......
...@@ -19,7 +19,8 @@ namespace adios2 ...@@ -19,7 +19,8 @@ namespace adios2
ADIOSPy::ADIOSPy(const std::string configFile, MPI_Comm mpiComm, ADIOSPy::ADIOSPy(const std::string configFile, MPI_Comm mpiComm,
const bool debugMode) const bool debugMode)
: m_DebugMode(debugMode), m_ADIOS(configFile, mpiComm, debugMode) : m_DebugMode(debugMode),
m_ADIOS(std::make_shared<adios2::ADIOS>(configFile, mpiComm, debugMode))
{ {
} }
...@@ -29,7 +30,7 @@ ADIOSPy::ADIOSPy(MPI_Comm mpiComm, const bool debugMode) ...@@ -29,7 +30,7 @@ ADIOSPy::ADIOSPy(MPI_Comm mpiComm, const bool debugMode)
} }
ADIOSPy::ADIOSPy(const std::string configFile, const bool debugMode) ADIOSPy::ADIOSPy(const std::string configFile, const bool debugMode)
: ADIOSPy("", MPI_COMM_SELF, debugMode) : ADIOSPy(configFile, MPI_COMM_SELF, debugMode)
{ {
} }
...@@ -39,7 +40,7 @@ ADIOSPy::ADIOSPy(const bool debugMode) : ADIOSPy("", MPI_COMM_SELF, debugMode) ...@@ -39,7 +40,7 @@ ADIOSPy::ADIOSPy(const bool debugMode) : ADIOSPy("", MPI_COMM_SELF, debugMode)
IOPy ADIOSPy::DeclareIO(const std::string name) IOPy ADIOSPy::DeclareIO(const std::string name)
{ {
return IOPy(m_ADIOS.DeclareIO(name), m_DebugMode); return IOPy(m_ADIOS->DeclareIO(name), m_DebugMode);
} }
} // end namespace adios } // end namespace adios
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#define ADIOS2_BINDINGS_PYTHON_SOURCE_ADIOSPY_H_ #define ADIOS2_BINDINGS_PYTHON_SOURCE_ADIOSPY_H_
/// \cond EXCLUDE_FROM_DOXYGEN /// \cond EXCLUDE_FROM_DOXYGEN
#include <memory> //std::shared_ptr
#include <string> #include <string>
/// \endcond /// \endcond
...@@ -32,13 +33,14 @@ public: ...@@ -32,13 +33,14 @@ public:
ADIOSPy(MPI_Comm mpiComm, const bool debugMode); ADIOSPy(MPI_Comm mpiComm, const bool debugMode);
ADIOSPy(const std::string configFile, const bool debugMode); ADIOSPy(const std::string configFile, const bool debugMode);
ADIOSPy(const bool debugMode); ADIOSPy(const bool debugMode);
~ADIOSPy() = default; ~ADIOSPy() = default;
IOPy DeclareIO(const std::string name); IOPy DeclareIO(const std::string name);
private: private:
const bool m_DebugMode; const bool m_DebugMode;
adios2::ADIOS m_ADIOS; std::shared_ptr<adios2::ADIOS> m_ADIOS;
}; };
} // end namespace adios } // end namespace adios
......
if(NOT BUILD_SHARED_LIBS)
message(ERROR "Python bindings are only supported for shared libraries")
endif()
set(Python_ADDITIONAL_VERSIONS 3 2.7) set(Python_ADDITIONAL_VERSIONS 3 2.7)
find_package(PythonInterp REQUIRED) find_package(PythonInterp REQUIRED)
find_package(PythonLibsNew REQUIRED) find_package(PythonLibsNew REQUIRED)
......
...@@ -68,7 +68,7 @@ adios2::ADIOSPy ADIOSPyInit(adios2::pyObject &object, const bool debugMode) ...@@ -68,7 +68,7 @@ adios2::ADIOSPy ADIOSPyInit(adios2::pyObject &object, const bool debugMode)
adios2::ADIOSPy ADIOSPyInitConfig(const std::string configFile, adios2::ADIOSPy ADIOSPyInitConfig(const std::string configFile,
const bool debugMode) const bool debugMode)
{ {
return adios2::ADIOSPy(debugMode); return adios2::ADIOSPy(configFile, debugMode);
} }
adios2::ADIOSPy ADIOSPyInit(const bool debugMode) adios2::ADIOSPy ADIOSPyInit(const bool debugMode)
......
...@@ -94,7 +94,7 @@ list(INSERT CMAKE_MODULE_PATH 0 ...@@ -94,7 +94,7 @@ list(INSERT CMAKE_MODULE_PATH 0
"${ADIOS2_SOURCE_DIR}/thirdparty/pybind11/pybind11/tools" "${ADIOS2_SOURCE_DIR}/thirdparty/pybind11/pybind11/tools"
) )
if(ADIOS2_USE_Python STREQUAL AUTO) if(ADIOS2_USE_Python STREQUAL AUTO)
if(BUILD_SHARED_LIBS) if(SHARED_LIBS_SUPPORTED AND ADIOS2_ENABLE_PIC)
set(Python_ADDITIONAL_VERSIONS 3 2.7) set(Python_ADDITIONAL_VERSIONS 3 2.7)
find_package(PythonInterp) find_package(PythonInterp)
find_package(PythonLibsNew) find_package(PythonLibsNew)
......
...@@ -70,6 +70,8 @@ int main(int argc, char *argv[]) ...@@ -70,6 +70,8 @@ int main(int argc, char *argv[])
// Get io settings from the config file or // Get io settings from the config file or
// create one with default settings here // create one with default settings here
adios2::IO &io = adios.DeclareIO("Output"); adios2::IO &io = adios.DeclareIO("Output");
// io.SetEngine("ADIOS1Writer");
// io.AddTransport("File", {{"library", "MPI"}});
/* /*
* Define joinable local array: type, name, global and local size * Define joinable local array: type, name, global and local size
......
...@@ -15,6 +15,44 @@ ...@@ -15,6 +15,44 @@
#include "PrintData.h" #include "PrintData.h"
void printData(double *xy, size_t *size, size_t *offset, int rank, int steps)
{
std::ofstream myfile;
std::string filename = "data." + std::to_string(rank);
myfile.open(filename);
double *data = xy;
uint64_t nelems = size[0] * size[1];
for (int step = 0; step < steps; step++)
{
myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1]
<< " offsets=" << offset[0] << ":" << offset[1]
<< " step=" << step << std::endl;
myfile << " time row columns " << offset[1] << "..."
<< offset[1] + size[1] - 1 << std::endl;
myfile << " ";
for (int j = 0; j < size[1]; j++)
{
myfile << std::setw(9) << offset[1] + j;
}
myfile << std::endl;
myfile << "------------------------------------------------------------"
"--\n";
for (int i = 0; i < size[0]; i++)
{
myfile << std::setw(5) << step << std::setw(5) << offset[0] + i;
for (int j = 0; j < size[1]; j++)
{
myfile << std::setw(9) << std::setprecision(2)
<< data[i * size[1] + j];
}
myfile << std::endl;
}
data += nelems;
}
myfile.close();
}
void printData(double *xy, uint64_t *size, uint64_t *offset, int rank, void printData(double *xy, uint64_t *size, uint64_t *offset, int rank,
int steps) int steps)
{ {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <cstdint> #include <cstdint>
void printData(double *xy, size_t *size, size_t *offset, int rank, int steps);
void printData(double *xy, uint64_t *size, uint64_t *offset, int rank, void printData(double *xy, uint64_t *size, uint64_t *offset, int rank,
int steps); int steps);
......
...@@ -93,8 +93,8 @@ int main(int argc, char *argv[]) ...@@ -93,8 +93,8 @@ int main(int argc, char *argv[])
} }
// 1D decomposition of the columns, which is inefficient for reading! // 1D decomposition of the columns, which is inefficient for reading!
std::vector<uint64_t> readsize({gndx, gndy / nproc}); adios2::Dims readsize({gndx, gndy / nproc});
std::vector<uint64_t> offset({0LL, rank * readsize[1]}); adios2::Dims offset({0LL, rank * readsize[1]});
if (rank == nproc - 1) if (rank == nproc - 1)
{ {
// last process should read all the rest of columns // last process should read all the rest of columns
......
...@@ -19,3 +19,12 @@ endif() ...@@ -19,3 +19,12 @@ endif()
if(ADIOS2_HAVE_HDF5) if(ADIOS2_HAVE_HDF5)
add_subdirectory(hdf5Writer) add_subdirectory(hdf5Writer)
endif() endif()
if(ADIOS2_HAVE_BZip2)
add_subdirectory(bpBZip2Wrapper)
endif()
if(ADIOS2_HAVE_ZFP)
add_subdirectory(bpZfpWrapper)
endif()
#------------------------------------------------------------------------------#
# Distributed under the OSI-approved Apache License, Version 2.0. See
# accompanying file Copyright.txt for details.
#------------------------------------------------------------------------------#
if(ADIOS2_HAVE_MPI)
find_package(MPI COMPONENTS C REQUIRED)
add_executable(hello_bpBZip2Wrapper helloBPBZip2Wrapper.cpp)
target_include_directories(hello_bpBZip2Wrapper PRIVATE ${MPI_C_INCLUDE_PATH})
target_link_libraries(hello_bpBZip2Wrapper ${MPI_C_LIBRARIES})
else()
add_executable(hello_bpBZip2Wrapper helloBPBZip2Wrapper_nompi.cpp)
endif()
target_link_libraries(hello_bpBZip2Wrapper adios2)
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* helloBPBZip2Wrapper.cpp: Simple self-descriptive example of how to write a
* variable to a BP File that lives in several MPI processes and is compressed
* with BZip2 http://www.bzip.org/
*
* Created on: Jul 26, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include <mpi.h>
#include <ios> //std::ios_base::failure
#include <iostream> //std::cout
#include <numeric> //std::iota
#include <stdexcept> //std::invalid_argument std::exception
#include <vector>
#include <adios2.h>
int main(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
/** Application variable uints from 0 to 1000 */
std::vector<unsigned int> myUInts(1000);
std::iota(myUInts.begin(), myUInts.end(), 0.f);
const std::size_t Nx = myUInts.size();
const std::size_t inputBytes = Nx * sizeof(unsigned int);
try
{
/** ADIOS class factory of IO class objects, DebugON is recommended */
adios2::ADIOS adios(MPI_COMM_WORLD, adios2::DebugON);
// Get a Transform of type BZip2
adios2::Transform &adiosBZip2 = adios.GetTransform("bzip2");
/*** IO class object: settings and factory of Settings: Variables,
* Parameters, Transports, and Execution: Engines */
adios2::IO &bpIO = adios.DeclareIO("BPFile_N2N_BZip2");
/** global array : name, { shape (total) }, { start (local) }, { count
* (local) }, all are constant dimensions */
adios2::Variable<unsigned int> &bpUInts =
bpIO.DefineVariable<unsigned int>("bpUInts", {size * Nx},
{rank * Nx}, {Nx},
adios2::ConstantDims);
// 1st way: adding transform metadata to variable to Engine can decide:
// &adiosBZip2 gets mapped to bpUInts.TransformInfo[bzip2ID].Operator
const unsigned int bzip2ID =
bpUInts.AddTransform(adiosBZip2, {{"BlockSize100K", "9"}});
// 2nd way: treat Transforms as wrappers to underlying library.
// you can redefine parameters
const std::size_t estimatedSize =
adiosBZip2.BufferMaxSize(Nx * bpUInts.m_ElementSize);
std::vector<char> compressedBuffer(estimatedSize);
size_t compressedSize = adiosBZip2.Compress(
myUInts.data(), bpUInts.m_Count, bpUInts.m_ElementSize,
bpUInts.m_Type, compressedBuffer.data(), {{"BlockSize100K", "1"}});
compressedBuffer.resize(compressedSize);
std::cout << "Rank " << rank << "\n";
std::cout << "Compression summary:\n";
std::cout << "Input data size: " << inputBytes << " bytes\n";
std::cout << "BZip2 estimated output size: " << estimatedSize
<< " bytes\n";
std::cout << "BZip2 final output size: " << compressedSize
<< " bytes\n\n";
// 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));
std::cout << "Decompression summary:\n";
std::cout << "Decompressed size: " << decompressedSize << " bytes\n";
std::cout << "Data:\n";
for (const auto number : decompressedBuffer)
{
if (number % 25 == 0)
{
std::cout << "\n";
}
std::cout << number << " ";
}
std::cout << "\n";
}
catch (std::invalid_argument &e)
{
std::cout << "Invalid argument exception, STOPPING PROGRAM from rank "
<< rank << "\n";
std::cout << e.what() << "\n";
}
catch (std::ios_base::failure &e)
{
std::cout
<< "IO System base failure exception, STOPPING PROGRAM from rank "
<< rank << "\n";
std::cout << e.what() << "\n";
}
catch (std::exception &e)
{
std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n";
std::cout << e.what() << "\n";
}
MPI_Finalize();
return 0;
}
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* helloBPBZip2Writer_nompi.cpp sequential non-mpi version of helloBPBZip2Writer
* using BZip2 http://www.bzip.org/
*
* Created on: Jul 26, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include <ios> //std::ios_base::failure
#include <iostream> //std::cout
#include <numeric> //std::iota
#include <stdexcept> //std::invalid_argument std::exception
#include <vector>
#include <adios2.h>
int main(int argc, char *argv[])
{
/** Application variable uints from 0 to 1000 */
std::vector<unsigned int> myUInts(1000);
std::iota(myUInts.begin(), myUInts.end(), 0.f);
const std::size_t Nx = myUInts.size();
const std::size_t inputBytes = Nx * sizeof(unsigned int);
try
{
/** ADIOS class factory of IO class objects, DebugON is recommended */
adios2::ADIOS adios(adios2::DebugON);
// Get a Transform of type BZip2
adios2::Transform &adiosBZip2 = adios.GetTransform("bzip2");
/*** IO class object: settings and factory of Settings: Variables,
* Parameters, Transports, and Execution: Engines */
adios2::IO &bpIO = adios.DeclareIO("BPFile_N2N_BZip2");
/** global array : name, { shape (total) }, { start (local) }, { count
* (local) }, all are constant dimensions */
adios2::Variable<unsigned int> &bpUInts =
bpIO.DefineVariable<unsigned int>("bpUInts", {}, {}, {Nx},
adios2::ConstantDims);
// 1st way: adding transform metadata to variable to Engine can decide:
bpUInts.AddTransform(adiosBZip2, {{"BlockSize100K", "10"}});
// 2nd way: treat Transforms as wrappers to underlying library:
const std::size_t estimatedSize =
adiosBZip2.BufferMaxSize(Nx * bpUInts.m_ElementSize);
std::vector<char> compressedBuffer(estimatedSize);
size_t compressedSize = adiosBZip2.Compress(
myUInts.data(), bpUInts.m_Count, bpUInts.m_ElementSize,
bpUInts.m_Type, compressedBuffer.data(), {{"BlockSize100K", "9"}});
compressedBuffer.resize(compressedSize);
std::cout << "Compression summary:\n";
std::cout << "Input data size: " << inputBytes << " bytes\n";
std::cout << "BZip2 estimated output size: " << estimatedSize
<< " bytes\n";
std::cout << "BZip2 final output size: " << compressedSize
<< " bytes\n\n";
// 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));
std::cout << "Decompression summary:\n";
std::cout << "Decompressed size: " << decompressedSize << " bytes\n";
std::cout << "Data:\n";
for (const auto number : decompressedBuffer)
{
if (number % 25 == 0)
{
std::cout << "\n";
}
std::cout << number << " ";
}
std::cout << "\n";
}
catch (std::invalid_argument &e)
{
std::cout << "Invalid argument exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
catch (std::ios_base::failure &e)
{
std::cout << "IO System base failure exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
catch (std::exception &e)
{
std::cout << "Exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
return 0;
}
...@@ -29,7 +29,6 @@ int main(int argc, char *argv[]) ...@@ -29,7 +29,6 @@ int main(int argc, char *argv[])
/*** IO class object: settings and factory of Settings: Variables, /*** IO class object: settings and factory of Settings: Variables,
* Parameters, Transports, and Execution: Engines */ * Parameters, Transports, and Execution: Engines */
adios2::IO &bpIO = adios.DeclareIO("BPFile_N2N"); adios2::IO &bpIO = adios.DeclareIO("BPFile_N2N");
bpIO.AddTransport("File", {{"Library", "stdio"}});
/** global array: name, { shape (total dimensions) }, { start (local) }, /** global array: name, { shape (total dimensions) }, { start (local) },
* { count (local) }, all are constant dimensions */ * { count (local) }, all are constant dimensions */
......
#------------------------------------------------------------------------------#
# Distributed under the OSI-approved Apache License, Version 2.0. See
# accompanying file Copyright.txt for details.
#------------------------------------------------------------------------------#
if(ADIOS2_HAVE_MPI)
find_package(MPI COMPONENTS C REQUIRED)
add_executable(hello_bpZfpWrapper helloBPZfpWrapper.cpp)
target_include_directories(hello_bpZfpWrapper PRIVATE ${MPI_C_INCLUDE_PATH})
target_link_libraries(hello_bpZfpWrapper ${MPI_C_LIBRARIES})
else()
add_executable(hello_bpZfpWrapper helloBPZfpWrapper_nompi.cpp)
endif()
target_link_libraries(hello_bpZfpWrapper adios2)
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* helloBPZfpWrapper.cpp: Simple self-descriptive example of how to write a
* variable to a BP File that lives in several MPI processes and is compressed
* with Zfp https://computation.llnl.gov/projects/floating-point-compression
*
* Created on: Jul 26, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include <mpi.h>
#include <cstdint> //std::int32_t
#include <ios> //std::ios_base::failure
#include <iostream> //std::cout
#include <numeric> //std::iota
#include <stdexcept> //std::invalid_argument std::exception
#include <vector>
#include <adios2.h>
int main(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
/** Application variable uints from 0 to 100 */
std::vector<float> myFloats(100);
std::iota(myFloats.begin(), myFloats.end(), 0.f);
const std::size_t Nx = myFloats.size();
const std::size_t inputBytes = Nx * sizeof(float);
try
{
/** ADIOS class factory of IO class objects, DebugON is recommended */
adios2::ADIOS adios(MPI_COMM_WORLD, adios2::DebugON);
// Get a Transform of type BZip2
adios2::Transform &adiosZfp = adios.GetTransform("zfp");
/*** IO class object: settings and factory of Settings: Variables,
* Parameters, Transports, and Execution: Engines */
adios2::IO &bpIO = adios.DeclareIO("BPFile_N2N_Zfp");
/** global array : name, { shape (total) }, { start (local) }, { count
* (local) }, all are constant dimensions */
adios2::Variable<float> &bpFloats = bpIO.DefineVariable<float>(
"bpFloats", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims);
// 1st way: adding transform metadata to variable to Engine can decide:
const unsigned int zfpID =
bpFloats.AddTransform(adiosZfp, {{"Rate", "8"}});
// 2nd way: treat Transforms as wrappers to underlying library:
const std::size_t estimatedSize =
adiosZfp.BufferMaxSize(myFloats.data(), bpFloats.m_Count,
bpFloats.m_TransformsInfo[zfpID].Parameters);
// Compress
std::vector<char> compressedBuffer(estimatedSize);
size_t compressedSize = adiosZfp.Compress(
myFloats.data(), bpFloats.m_Count, bpFloats.m_ElementSize,
bpFloats.m_Type, compressedBuffer.data(),
bpFloats.m_TransformsInfo[zfpID].Parameters);
compressedBuffer.resize(compressedSize);
std::cout << "Compression summary:\n";
std::cout << "Input data size: " << inputBytes << " bytes\n";
std::cout << "Zfp estimated output size: " << estimatedSize
<< " bytes\n";
std::cout << "Zfp final output size: " << compressedSize
<< " bytes\n\n";
// Allocate original data size
std::vector<float> decompressedBuffer(Nx);
size_t decompressedSize = adiosZfp.Decompress(
compressedBuffer.data(), compressedBuffer.size(),
decompressedBuffer.data(), bpFloats.m_Count, bpFloats.m_Type,
bpFloats.m_TransformsInfo[zfpID].Parameters);
std::cout << "Decompression summary:\n";
std::cout << "Decompressed size: " << decompressedSize << " bytes\n ";
std::cout << "Data:\n";
for (const auto number : decompressedBuffer)
{
if (static_cast<int>(number) % 25 == 0 && number != 0)
{
std::cout << "\n";
}
std::cout << number << " ";
}
std::cout << "\n";
}
catch (std::invalid_argument &e)
{
std::cout << "Invalid argument exception, STOPPING PROGRAM from rank "
<< rank << "\n";
std::cout << e.what() << "\n";
}
catch (std::ios_base::failure &e)
{
std::cout
<< "IO System base failure exception, STOPPING PROGRAM from rank "
<< rank << "\n";
std::cout << e.what() << "\n";
}
catch (std::exception &e)
{
std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n";
std::cout << e.what() << "\n";
}
MPI_Finalize();
return 0;
}
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* helloBPZfpWriter_nompi.cpp sequential non-mpi version of helloBPZfpWrapper
* using Zfp https://computation.llnl.gov/projects/floating-point-compression
*
* Created on: Jul 26, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include <cstdint> //std::int32_t
#include <ios> //std::ios_base::failure
#include <iostream> //std::cout
#include <numeric> //std::iota
#include <stdexcept> //std::invalid_argument std::exception
#include <vector>
#include <adios2.h>
int main(int argc, char *argv[])
{
/** Application variable uints from 0 to 100 */
std::vector<float> myFloats(100);
std::iota(myFloats.begin(), myFloats.end(), 0.f);
const std::size_t Nx = myFloats.size();
const std::size_t inputBytes = Nx * sizeof(float);
try
{
/** ADIOS class factory of IO class objects, DebugON is recommended */
adios2::ADIOS adios(adios2::DebugON);
// Get a Transform of type BZip2
adios2::Transform &adiosZfp = adios.GetTransform("zfp");
/*** IO class object: settings and factory of Settings: Variables,
* Parameters, Transports, and Execution: Engines */
adios2::IO &bpIO = adios.DeclareIO("BPVariable_Zfp");
/** global array : name, { shape (total) }, { start (local) }, { count
* (local) }, all are constant dimensions */
adios2::Variable<float> &bpFloats = bpIO.DefineVariable<float>(
"bpUInts", {}, {}, {Nx}, adios2::ConstantDims);
// Adding transform metadata to variable:
// Options:
// Rate double
// Tolerance
// Precision
const unsigned int zfpID =
bpFloats.AddTransform(adiosZfp, {{"Rate", "8"}});
// Treat Transforms as wrappers to underlying library (zfp):
const std::size_t estimatedSize =
adiosZfp.BufferMaxSize(myFloats.data(), bpFloats.m_Count,
bpFloats.m_TransformsInfo[zfpID].Parameters);
// Compress
std::vector<char> compressedBuffer(estimatedSize);
size_t compressedSize = adiosZfp.Compress(
myFloats.data(), bpFloats.m_Count, bpFloats.m_ElementSize,
bpFloats.m_Type, compressedBuffer.data(),
bpFloats.m_TransformsInfo[zfpID].Parameters);
compressedBuffer.resize(compressedSize);
std::cout << "Compression summary:\n";
std::cout << "Input data size: " << inputBytes << " bytes\n";
std::cout << "Zfp estimated output size: " << estimatedSize
<< " bytes\n";
std::cout << "Zfp final output size: " << compressedSize
<< " bytes\n\n";
// Decompress, allocate original data size
std::vector<float> decompressedBuffer(Nx);
size_t decompressedSize = adiosZfp.Decompress(
compressedBuffer.data(), compressedBuffer.size(),
decompressedBuffer.data(), bpFloats.m_Count, bpFloats.m_Type,
bpFloats.m_TransformsInfo[zfpID].Parameters);
std::cout << "Decompression summary:\n";
std::cout << "Decompressed size: " << decompressedSize << " bytes\n ";
std::cout << "Data:\n";
for (const auto number : decompressedBuffer)
{
if (static_cast<int>(number) % 25 == 0 && number != 0)
{
std::cout << "\n";
}
std::cout << number << " ";
}
std::cout << "\n";
}
catch (std::invalid_argument &e)
{
std::cout << "Invalid argument exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
catch (std::ios_base::failure &e)
{
std::cout << "IO System base failure exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
catch (std::exception &e)
{
std::cout << "Exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
return 0;
}
...@@ -27,10 +27,10 @@ ...@@ -27,10 +27,10 @@
/* CMake Option: ADIOS_USE_MPI=OFF */ /* CMake Option: ADIOS_USE_MPI=OFF */
#cmakedefine ADIOS2_HAVE_MPI #cmakedefine ADIOS2_HAVE_MPI
/* CMake Option: ADIOS_USE_ZFP=OFF */ /* CMake Option: ADIOS_USE_ZFP=ON */
#cmakedefine ADIOS2_HAVE_ZFP #cmakedefine ADIOS2_HAVE_ZFP
/* CMake Option: ADIOS_USE_BZip2=OFF */ /* CMake Option: ADIOS_USE_BZip2=ON */
#cmakedefine ADIOS2_HAVE_BZIP2 #cmakedefine ADIOS2_HAVE_BZIP2
/* CMake Option: ADIOS_USE_ADIOS1=ON */ /* CMake Option: ADIOS_USE_ADIOS1=ON */
......
...@@ -56,4 +56,10 @@ ...@@ -56,4 +56,10 @@
MACRO(float) \ MACRO(float) \
MACRO(double) MACRO(double)
#define ADIOS2_FOREACH_ZFP_TYPE_1ARG(MACRO) \
MACRO(int32_t) \
MACRO(int64_t) \
MACRO(float) \
MACRO(double)
#endif /* ADIOS2_ADIOSMACROS_H */ #endif /* ADIOS2_ADIOSMACROS_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment