/*
Copyright 2019 Equinor AS.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see .
*/
#include
#include "MPIPacker.hpp"
#include
#include
#include
#include
#include
#include
namespace Opm {
namespace Mpi {
namespace detail {
template
std::size_t Packing>::
packSize(const std::bitset& data,
Parallel::MPIComm comm)
{
return Packing::packSize(data.to_ullong(), comm);
}
template
void Packing>::
pack(const std::bitset& data,
std::vector& buffer,
int& position,
Parallel::MPIComm comm)
{
Packing::pack(data.to_ullong(), buffer, position, comm);
}
template
void Packing>::
unpack(std::bitset& data,
std::vector& buffer,
int& position,
Parallel::MPIComm comm)
{
unsigned long long d;
Packing::unpack(d, buffer, position, comm);
data = std::bitset(d);
}
std::size_t Packing::
packSize(const std::string& data, Parallel::MPIComm comm)
{
int size;
MPI_Pack_size(1, Dune::MPITraits::getType(), comm, &size);
int totalSize = size;
MPI_Pack_size(data.size(), MPI_CHAR, comm, &size);
return totalSize + size;
}
void Packing::
pack(const std::string& data,
std::vector& buffer,
int& position,
Parallel::MPIComm comm)
{
std::size_t length = data.size();
MPI_Pack(&length, 1, Dune::MPITraits::getType(), buffer.data(),
buffer.size(), &position, comm);
MPI_Pack(data.data(), length, MPI_CHAR, buffer.data(), buffer.size(),
&position, comm);
}
void Packing::
unpack(std::string& data,
std::vector& buffer,
int& position,
Opm::Parallel::MPIComm comm)
{
std::size_t length = 0;
MPI_Unpack(buffer.data(), buffer.size(), &position, &length, 1,
Dune::MPITraits::getType(), comm);
std::vector cStr(length+1, '\0');
MPI_Unpack(buffer.data(), buffer.size(), &position, cStr.data(), length,
MPI_CHAR, comm);
data.clear();
data.append(cStr.data(), length);
}
std::size_t Packing::
packSize(const time_point&, Opm::Parallel::MPIComm comm)
{
return Packing::packSize(std::time_t(), comm);
}
void Packing::
pack(const time_point& data,
std::vector& buffer,
int& position,
Parallel::MPIComm comm)
{
Packing::pack(TimeService::to_time_t(data),
buffer, position, comm);
}
void Packing::
unpack(time_point& data,
std::vector& buffer,
int& position,
Parallel::MPIComm comm)
{
std::time_t res;
Packing::unpack(res, buffer, position, comm);
data = TimeService::from_time_t(res);
}
template struct Packing>;
template struct Packing>;
template struct Packing>;
} // end namespace detail
} // end namespace Mpi
} // end namespace Opm