10#include <util/mpi/MpiStructBuilder.h>
20 MPI::Datatype MpiTraits<Rational>::type = MPI::BYTE;
21 bool MpiTraits<Rational>::hasType =
false;
26 void Rational::commitMpiType()
28 if (!MpiTraits<Rational>::hasType) {
29 MpiStructBuilder builder;
31 builder.setBase(&
object);
32 builder.addMember(&
object.num_, MPI::INT);
33 builder.addMember(&
object.den_, MPI::INT);
34 builder.commit(MpiTraits<Rational>::type);
35 MpiTraits<Rational>::hasType =
true;
48 out <<
"/" << a.den_ ;
61 int size = word.size();
64 std::size_t slashId = word.find(
'/');
65 bool hasSlash =
false;
66 if (slashId != std::string::npos) {
74 int numSize = slashId;
75 int denSize = size - slashId - 1;
76 std::string numStr = word.substr(0, numSize);
77 std::string denStr = word.substr(slashId + 1, denSize);
78 a.num_ = std::stoi(numStr);
79 a.den_ = std::stoi(denStr);
81 a.num_ = std::stoi(word);
A Rational number (a ratio of integers).
Rational()
Default constructor.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Utility classes for scientific computation.
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.