<commit_before>/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * adiosCommMPI.cpp
 */

#include "adiosCommMPI.h"

#include <algorithm>
#include <ios> //std::ios_base::failure
#include <iterator>
#include <utility>

#include "adiosComm.h"
#include "adiosCommDummy.h"

#include "adios2/common/ADIOSTypes.h"

#include <mpi.h>

namespace adios2
{
namespace core
{
void RegisterMPIEngines();
}
namespace helper
{

namespace
{
struct InitMPI
{
    InitMPI() { core::RegisterMPIEngines(); }
};

const MPI_Op OpToMPI[] = {
    MPI_OP_NULL, MPI_MAX,    MPI_MIN,    MPI_SUM,     MPI_PROD,
    MPI_LAND,    MPI_BAND,   MPI_LOR,    MPI_BOR,     MPI_LXOR,
    MPI_BXOR,    MPI_MAXLOC, MPI_MINLOC, MPI_REPLACE, MPI_NO_OP,
};

MPI_Op ToMPI(Comm::Op op) { return OpToMPI[int(op)]; }

const int LockTypeToMPI[] = {MPI_LOCK_EXCLUSIVE, MPI_LOCK_SHARED};

int ToMPI(Comm::LockType lock_type) { return LockTypeToMPI[int(lock_type)]; }

const MPI_Datatype DatatypeToMPI[] = {
    MPI_SIGNED_CHAR,
    MPI_CHAR,
    MPI_SHORT,
    MPI_INT,
    MPI_LONG,
    MPI_UNSIGNED_CHAR,
    MPI_UNSIGNED_SHORT,
    MPI_UNSIGNED,
    MPI_UNSIGNED_LONG,
    MPI_UNSIGNED_LONG_LONG,
    MPI_LONG_LONG_INT,
    MPI_DOUBLE,
    MPI_LONG_DOUBLE,
    MPI_2INT,
    MPI_FLOAT_INT,
    MPI_DOUBLE_INT,
    MPI_LONG_DOUBLE_INT,
    MPI_SHORT_INT,
};

MPI_Datatype ToMPI(CommImpl::Datatype dt) { return DatatypeToMPI[int(dt)]; }

void CheckMPIReturn(const int value, const std::string &hint)
{
    if (value == MPI_SUCCESS)
    {
        return;
    }

    std::string error;
    switch (value)
    {
    case MPI_ERR_COMM:
        error = "MPI_ERR_COMM";
        break;
    case MPI_ERR_INTERN:
        error = "MPI_ERR_INTERN";
        break;
    default:
        error = "MPI_ERR number: " + std::to_string(value);
    }<commit_msg>Use `if` instead of `switch` to check MPI constants<commit_after>/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * adiosCommMPI.cpp
 */

#include "adiosCommMPI.h"

#include <algorithm>
#include <ios> //std::ios_base::failure
#include <iterator>
#include <utility>

#include "adiosComm.h"
#include "adiosCommDummy.h"

#include "adios2/common/ADIOSTypes.h"

#include <mpi.h>

namespace adios2
{
namespace core
{
void RegisterMPIEngines();
}
namespace helper
{

namespace
{
struct InitMPI
{
    InitMPI() { core::RegisterMPIEngines(); }
};

const MPI_Op OpToMPI[] = {
    MPI_OP_NULL, MPI_MAX,    MPI_MIN,    MPI_SUM,     MPI_PROD,
    MPI_LAND,    MPI_BAND,   MPI_LOR,    MPI_BOR,     MPI_LXOR,
    MPI_BXOR,    MPI_MAXLOC, MPI_MINLOC, MPI_REPLACE, MPI_NO_OP,
};

MPI_Op ToMPI(Comm::Op op) { return OpToMPI[int(op)]; }

const int LockTypeToMPI[] = {MPI_LOCK_EXCLUSIVE, MPI_LOCK_SHARED};

int ToMPI(Comm::LockType lock_type) { return LockTypeToMPI[int(lock_type)]; }

const MPI_Datatype DatatypeToMPI[] = {
    MPI_SIGNED_CHAR,
    MPI_CHAR,
    MPI_SHORT,
    MPI_INT,
    MPI_LONG,
    MPI_UNSIGNED_CHAR,
    MPI_UNSIGNED_SHORT,
    MPI_UNSIGNED,
    MPI_UNSIGNED_LONG,
    MPI_UNSIGNED_LONG_LONG,
    MPI_LONG_LONG_INT,
    MPI_DOUBLE,
    MPI_LONG_DOUBLE,
    MPI_2INT,
    MPI_FLOAT_INT,
    MPI_DOUBLE_INT,
    MPI_LONG_DOUBLE_INT,
    MPI_SHORT_INT,
};

MPI_Datatype ToMPI(CommImpl::Datatype dt) { return DatatypeToMPI[int(dt)]; }

void CheckMPIReturn(const int value, const std::string &hint)
{
    if (value == MPI_SUCCESS)
    {
        return;
    }

    std::string error;
    if (value == MPI_ERR_COMM) {
        error = "MPI_ERR_COMM";
    } else if (value == MPI_ERR_INTERN) {
        error = "MPI_ERR_INTERN";
    } else {
        error = "MPI_ERR number: " + std::to_string(value);
    }
{'fraction_non_alphanumeric': 0.1128, 'fraction_numerical': 0.0026666666666666666, 'mean_word_length': 3.596813725490196, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1672629', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1535, 'n_words': 281}