<commit_before>/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * helloDataManReader_nompi.cpp
 *
 *  Created on: Jan 9, 2017
 *      Author: <NAME>
 */

#include <chrono>
#include <iostream>
#include <numeric>
#include <thread>
#include <vector>

#include <adios2.h>

// matches Signature2 in ADIOS2
void UserCallBack(void *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[])
{
    // Application variable
    MPI_Init(&argc, &argv);
    int rank, size;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    int timeout = 5;

    if(argc == 2){
        timeout = atoi(argv[1]);
    }

    try
    {
        adios2::ADIOS adios(adios2::DebugON);

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

        adios2::IO &dataManIO = adios.DeclareIO("WAN");
        dataManIO.SetEngine("DataManReader");
        dataManIO.SetParameters({{"real_time", "yes"},
                                 {"method_type", "stream"},
                                 {"method", "dump"}});
        dataManIO.AddOperator(callbackFloat); // progated to all Engines

        adios2::Engine &dataManReader =
            dataManIO.Open("myDoubles.bp", adios2::Mode::Read);

        std::this_thread::sleep_for(std::chrono::seconds(timeout));

        dataManReader.Close();
    }
    catch (std::invalid_argument &e)
    {
        std::cout << "Invalid argument exception, STOPPING PROGRAM from rank "
                  << rank << "\n";<commit_msg>minor changes<commit_after>/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * helloDataManReader_nompi.cpp
 *
 *  Created on: Jan 9, 2017
 *      Author: <NAME>
 */

#include <chrono>
#include <iostream>
#include <numeric>
#include <thread>
#include <vector>

#include <adios2.h>

// matches Signature2 in ADIOS2
void UserCallBack(void *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[])
{
    // Application variable
    MPI_Init(&argc, &argv);
    int rank, size;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    int timeout = 5;

    if (argc == 2)
    {
        timeout = atoi(argv[1]);
    }

    try
    {
        adios2::ADIOS adios(adios2::DebugON);

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

        adios2::IO &dataManIO = adios.DeclareIO("WAN");
        dataManIO.SetEngine("DataManReader");
        dataManIO.SetParameters({{"real_time", "yes"},
                                 {"method_type", "stream"},
                                 {"method", "dump"}});
        dataManIO.AddOperator(callbackFloat); // progated to all Engines

        adios2::Engine &dataManReader =
            dataManIO.Open("myDoubles.bp", adios2::Mode::Read);

        std::this_thread::sleep_for(std::chrono::seconds(timeout));

        dataManReader.Close();
    }
    catch (std::invalid_argument &e)
    {
        std::cout << "Invalid argument exception, STOPPING PROGRAM from rank "
                  << rank << "\n";
{'fraction_non_alphanumeric': 0.15384615384615385, 'fraction_numerical': 0.009247583018074821, 'mean_word_length': 2.351408450704225, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4621360', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1482, 'n_words': 333}