<commit_before>/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * Reorganize.cpp
 *
 *  Created on: Mar 7, 2018
 *      Author: <NAME>, <EMAIL>
 *
 * Reorganize global arrays
   Assumptions:
     - one output step fits into the memory of the reorganizer.
       Actually, this means, even more memory is needed than the size of output.
       We need to read each variable while also buffering all of them for
 output.
     - output steps contain the same variable set (no changes in variables)
     - attributes are the same for all steps (will write only once here)
 */

#include "Reorganize.h"

#include <assert.h>
#include <iomanip>
#include <iostream>
#include <string>

#include "adios2/common/ADIOSMacros.h"
#include "adios2/core/ADIOS.h"
#include "adios2/core/Engine.h"
#include "adios2/core/IO.h"
#include "adios2/helper/adiosComm.h"
#include "adios2/helper/adiosFunctions.h"
#include "adios2/helper/adiosString.h"

#if ADIOS2_USE_MPI
#include "adios2/helper/adiosCommMPI.h"
#else
#include "adios2/helper/adiosCommDummy.h"
#endif

// C headers
#include <cerrno>
#include <cstdlib>

namespace adios2
{
namespace utils
{

Reorganize::Reorganize(int argc, char *argv[])
: Utils("adios_reorganize", argc, argv)
{
#if ADIOS2_USE_MPI
    {
        auto commWorld = helper::CommWithMPI(MPI_COMM_WORLD);
        m_Comm = commWorld.Split(m_CommSplitColor, 0);
    }
#else
    m_Comm = helper::CommDummy();
#endif
    m_Rank = m_Comm.Rank();
    m_Size = m_Comm.Size();

    if (argc < 5)
    {
        PrintUsage();
        throw std::invalid_argument(
            "ERROR: Not enough arguments. At least 6 are required\n");
    }
    infilename = std::string(argv[1]);
    outfilename = std::string(argv[2]);
    rmethodname = std::string(argv[3]);
    rmethodparam_str = std::string(argv[4]);
    wmethodname = std::string(argv[5]);
    wmethodparam_str = std::string(argv[6]);

    int nd = 0;
    int j = 7;
    char *end;
    while (argc > j && j < 13)
    { // get max 6 dimensions
        errno = 0;
        decomp_values[nd] = std::strtol(argv[j], &end, 10);
        if (errno || (end != 0 && *end != '\0'))<commit_msg>Fix OOB access.<commit_after>/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * Reorganize.cpp
 *
 *  Created on: Mar 7, 2018
 *      Author: <NAME>, <EMAIL>
 *
 * Reorganize global arrays
   Assumptions:
     - one output step fits into the memory of the reorganizer.
       Actually, this means, even more memory is needed than the size of output.
       We need to read each variable while also buffering all of them for
 output.
     - output steps contain the same variable set (no changes in variables)
     - attributes are the same for all steps (will write only once here)
 */

#include "Reorganize.h"

#include <assert.h>
#include <iomanip>
#include <iostream>
#include <string>

#include "adios2/common/ADIOSMacros.h"
#include "adios2/core/ADIOS.h"
#include "adios2/core/Engine.h"
#include "adios2/core/IO.h"
#include "adios2/helper/adiosComm.h"
#include "adios2/helper/adiosFunctions.h"
#include "adios2/helper/adiosString.h"

#if ADIOS2_USE_MPI
#include "adios2/helper/adiosCommMPI.h"
#else
#include "adios2/helper/adiosCommDummy.h"
#endif

// C headers
#include <cerrno>
#include <cstdlib>

namespace adios2
{
namespace utils
{

Reorganize::Reorganize(int argc, char *argv[])
: Utils("adios_reorganize", argc, argv)
{
#if ADIOS2_USE_MPI
    {
        auto commWorld = helper::CommWithMPI(MPI_COMM_WORLD);
        m_Comm = commWorld.Split(m_CommSplitColor, 0);
    }
#else
    m_Comm = helper::CommDummy();
#endif
    m_Rank = m_Comm.Rank();
    m_Size = m_Comm.Size();

    if (argc < 7)
    {
        PrintUsage();
        throw std::invalid_argument(
            "ERROR: Not enough arguments. At least 6 are required\n");
    }
    infilename = std::string(argv[1]);
    outfilename = std::string(argv[2]);
    rmethodname = std::string(argv[3]);
    rmethodparam_str = std::string(argv[4]);
    wmethodname = std::string(argv[5]);
    wmethodparam_str = std::string(argv[6]);

    int nd = 0;
    int j = 7;
    char *end;
    while (argc > j && j < 13)
    { // get max 6 dimensions
        errno = 0;
        decomp_values[nd] = std::strtol(argv[j], &end, 10);
        if (errno || (end != 0 && *end != '\0'))
{'fraction_non_alphanumeric': 0.13129251700680272, 'fraction_numerical': 0.017233560090702947, 'mean_word_length': 3.2992202729044835, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3944590', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1543, 'n_words': 419}