Templatize Slice

This commit is contained in:
Alejandro Gallo 2022-01-27 20:40:37 +01:00
parent 8c39827061
commit 61662e2717

View File

@ -32,9 +32,9 @@ namespace mpi {
} }
template <typename F=double>
struct Slice { struct Slice {
using F = double;
#+end_src #+end_src
A slice is the concept of a subset of values of a given tensor. A slice is the concept of a subset of values of a given tensor.
@ -124,8 +124,8 @@ As an example, for the doubles amplitudes \( T^{ab}_{ij} \), one need two kinds
// DATABASE ==========================================================={{{1 // DATABASE ==========================================================={{{1
struct LocalDatabaseElement { struct LocalDatabaseElement {
Slice::Name name; Slice<F>::Name name;
Slice::Info info; Slice<F>::Info info;
}; };
using LocalDatabase = std::vector<LocalDatabaseElement>; using LocalDatabase = std::vector<LocalDatabaseElement>;
using Database = LocalDatabase; using Database = LocalDatabase;
@ -148,7 +148,7 @@ As an example, for the doubles amplitudes \( T^{ab}_{ij} \), one need two kinds
constexpr int n = 2; constexpr int n = 2;
// create a sliceLocation to measure in the current architecture // create a sliceLocation to measure in the current architecture
// the packing of the struct // the packing of the struct
Slice::Location measure; Slice<F>::Location measure;
MPI_Datatype dt; MPI_Datatype dt;
const std::vector<int> lengths(n, 1); const std::vector<int> lengths(n, 1);
const MPI_Datatype types[n] = {usizeDt(), usizeDt()}; const MPI_Datatype types[n] = {usizeDt(), usizeDt()};
@ -172,7 +172,7 @@ As an example, for the doubles amplitudes \( T^{ab}_{ij} \), one need two kinds
static MPI_Datatype sliceInfo () { static MPI_Datatype sliceInfo () {
constexpr int n = 5; constexpr int n = 5;
MPI_Datatype dt; MPI_Datatype dt;
Slice::Info measure; Slice<F>::Info measure;
const std::vector<int> lengths(n, 1); const std::vector<int> lengths(n, 1);
const MPI_Datatype types[n] const MPI_Datatype types[n]
= { vector(2, usizeDt()) = { vector(2, usizeDt())
@ -244,10 +244,10 @@ As an example, for the doubles amplitudes \( T^{ab}_{ij} \), one need two kinds
,* It is important here to return a reference to a Slice ,* It is important here to return a reference to a Slice
,* not to accidentally copy the associated buffer of the slice. ,* not to accidentally copy the associated buffer of the slice.
,*/ ,*/
static Slice& findOneByType(std::vector<Slice> &slices, Slice::Type type) { static Slice<F>& findOneByType(std::vector<Slice<F>> &slices, Slice<F>::Type type) {
const auto sliceIt const auto sliceIt
= std::find_if(slices.begin(), slices.end(), = std::find_if(slices.begin(), slices.end(),
[&type](Slice const& s) { [&type](Slice<F> const& s) {
return type == s.info.type; return type == s.info.type;
}); });
WITH_CRAZY_DEBUG WITH_CRAZY_DEBUG
@ -262,11 +262,11 @@ As an example, for the doubles amplitudes \( T^{ab}_{ij} \), one need two kinds
,* Check if an info has ,* Check if an info has
,* ,*
,*/ ,*/
static std::vector<Slice*> hasRecycledReferencingToIt static std::vector<Slice<F>*> hasRecycledReferencingToIt
( std::vector<Slice> &slices ( std::vector<Slice<F>> &slices
, Info const& info , Info const& info
) { ) {
std::vector<Slice*> result; std::vector<Slice<F>*> result;
for (auto& s: slices) for (auto& s: slices)
if ( s.info.recycling == info.type if ( s.info.recycling == info.type
@ -277,11 +277,11 @@ As an example, for the doubles amplitudes \( T^{ab}_{ij} \), one need two kinds
return result; return result;
} }
static Slice& static Slice<F>&
findRecycledSource (std::vector<Slice> &slices, Slice::Info info) { findRecycledSource (std::vector<Slice<F>> &slices, Slice<F>::Info info) {
const auto sliceIt const auto sliceIt
= std::find_if(slices.begin(), slices.end(), = std::find_if(slices.begin(), slices.end(),
[&info](Slice const& s) { [&info](Slice<F> const& s) {
return info.recycling == s.info.type return info.recycling == s.info.type
&& info.tuple == s.info.tuple && info.tuple == s.info.tuple
&& State::Recycled != s.info.state && State::Recycled != s.info.state
@ -301,15 +301,15 @@ As an example, for the doubles amplitudes \( T^{ab}_{ij} \), one need two kinds
return *sliceIt; return *sliceIt;
} }
static Slice& findByTypeAbc static Slice<F>& findByTypeAbc
( std::vector<Slice> &slices ( std::vector<Slice<F>> &slices
, Slice::Type type , Slice<F>::Type type
, ABCTuple const& abc , ABCTuple const& abc
) { ) {
const auto tuple = Slice::subtupleBySlice(abc, type); const auto tuple = Slice<F>::subtupleBySlice(abc, type);
const auto sliceIt const auto sliceIt
= std::find_if(slices.begin(), slices.end(), = std::find_if(slices.begin(), slices.end(),
[&type, &tuple](Slice const& s) { [&type, &tuple](Slice<F> const& s) {
return type == s.info.type return type == s.info.type
&& tuple == s.info.tuple && tuple == s.info.tuple
; ;
@ -329,11 +329,11 @@ As an example, for the doubles amplitudes \( T^{ab}_{ij} \), one need two kinds
return *sliceIt; return *sliceIt;
} }
static Slice& findByInfo(std::vector<Slice> &slices, static Slice<F>& findByInfo(std::vector<Slice<F>> &slices,
Slice::Info const& info) { Slice<F>::Info const& info) {
const auto sliceIt const auto sliceIt
= std::find_if(slices.begin(), slices.end(), = std::find_if(slices.begin(), slices.end(),
[&info](Slice const& s) { [&info](Slice<F> const& s) {
// TODO: maybe implement comparison in Info struct // TODO: maybe implement comparison in Info struct
return info.type == s.info.type return info.type == s.info.type
&& info.state == s.info.state && info.state == s.info.state
@ -479,13 +479,15 @@ As an example, for the doubles amplitudes \( T^{ab}_{ij} \), one need two kinds
}; // struct Slice }; // struct Slice
std::ostream& operator<<(std::ostream& out, Slice::Location const& v) { template <typename F=double>
std::ostream& operator<<(std::ostream& out, typename Slice<F>::Location const& v) {
// TODO: remove me // TODO: remove me
out << "{.r(" << v.rank << "), .s(" << v.source << ")};"; out << "{.r(" << v.rank << "), .s(" << v.source << ")};";
return out; return out;
} }
std::ostream& operator<<(std::ostream& out, Slice::Info const& i) { template <typename F=double>
std::ostream& operator<<(std::ostream& out, typename Slice<F>::Info const& i) {
out << "«t" << i.type << ", s" << i.state << "»" out << "«t" << i.type << ", s" << i.state << "»"
<< " ⊙ {" << i.from.rank << ", " << i.from.source << "}" << " ⊙ {" << i.from.rank << ", " << i.from.source << "}"
<< " ∴ {" << i.tuple[0] << ", " << i.tuple[1] << "}" << " ∴ {" << i.tuple[0] << ", " << i.tuple[1] << "}"