Skip to content
Snippets Groups Projects
helloDataManReader.cpp 3.01 KiB
Newer Older
wfg's avatar
wfg committed
/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * helloDataManReader_nompi.cpp
wfg's avatar
wfg committed
 *
 *  Created on: Jan 9, 2017
 *      Author: Jason Wang
wfg's avatar
wfg committed
 */

#include <iostream>
#include <numeric>
#include <vector>
wfg's avatar
wfg committed

#include <adios2.h>
wfg's avatar
wfg committed

// matches Signature1 in ADIOS2
template <class T>
void UserCallBack(const T *data, const std::string &doid,
                  const std::string &var, const std::string &dtype,
                  const std::vector<std::size_t> &varshape)
    std::cout << "data object ID = " << doid << "\n";
    std::cout << "variable name = " << var << "\n";
    std::cout << "data type = " << dtype << "\n";
    std::size_t varsize = std::accumulate(varshape.begin(), varshape.end(), 1,
                                          std::multiplies<std::size_t>());
    for (unsigned int i = 0; i < varsize; ++i)
        std::cout << ((float *)data)[i] << " ";
    std::cout << std::endl;
int main(int argc, char *argv[])
wfg's avatar
wfg committed
{
    // Application variable
    MPI_Init(&argc, &argv);
    int rank, size;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
wfg's avatar
wfg committed
    {
        adios2::ADIOS adios(adios2::DebugON);
wfg's avatar
wfg committed

        adios2::Operator &callbackFloat = adios.DefineOperator(
            "Print float Variable callback",
            std::function<void(const float *, const std::string &,
                               const std::string &, const std::string &,
                               const adios2::Dims &)>(UserCallBack<float>));

        adios2::IO &dataManIO = adios.DeclareIO("WAN");
        dataManIO.SetEngine("DataManReader");
        dataManIO.SetParameters({{"real_time", "yes"},
                                 {"method_type", "stream"},
                                 {"method", "dump"}});
        adios2::Engine &dataManReader =
            dataManIO.Open("myDoubles.bp", adios2::Mode::Read);
wfg's avatar
wfg committed

        // dataManReader.SetCallBack(UserCallBack);

        for (unsigned int i = 0; i < 3; ++i)
        {
            std::this_thread::sleep_for(std::chrono::milliseconds(1000));
        }
        adios2::Variable<double> *ioMyDoubles =
            dataManIO.InquireVariable<double>("ioMyDoubles");
        if (ioMyDoubles == nullptr)
            std::cout << "Variable ioMyDoubles not read...yet\n";
wfg's avatar
wfg committed

    }
    catch (std::invalid_argument &e)
wfg's avatar
wfg committed
    {
        std::cout << "Invalid argument exception, STOPPING PROGRAM from rank "
                  << rank << "\n";
        std::cout << e.what() << "\n";
wfg's avatar
wfg committed
    }
    catch (std::ios_base::failure &e)
wfg's avatar
wfg committed
    {
        std::cout << "IO System base failure exception, STOPPING PROGRAM "
                     "from rank "
                  << rank << "\n";
        std::cout << e.what() << "\n";
wfg's avatar
wfg committed
    }
    catch (std::exception &e)
wfg's avatar
wfg committed
    {
        std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n";
        std::cout << e.what() << "\n";
wfg's avatar
wfg committed

wfg's avatar
wfg committed
}