Templatize Slice
This commit is contained in:
parent
8c39827061
commit
61662e2717
48
atrip.org
48
atrip.org
@ -32,9 +32,9 @@ namespace mpi {
|
||||
}
|
||||
|
||||
|
||||
template <typename F=double>
|
||||
struct Slice {
|
||||
|
||||
using F = double;
|
||||
#+end_src
|
||||
|
||||
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
|
||||
struct LocalDatabaseElement {
|
||||
Slice::Name name;
|
||||
Slice::Info info;
|
||||
Slice<F>::Name name;
|
||||
Slice<F>::Info info;
|
||||
};
|
||||
using LocalDatabase = std::vector<LocalDatabaseElement>;
|
||||
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;
|
||||
// create a sliceLocation to measure in the current architecture
|
||||
// the packing of the struct
|
||||
Slice::Location measure;
|
||||
Slice<F>::Location measure;
|
||||
MPI_Datatype dt;
|
||||
const std::vector<int> lengths(n, 1);
|
||||
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 () {
|
||||
constexpr int n = 5;
|
||||
MPI_Datatype dt;
|
||||
Slice::Info measure;
|
||||
Slice<F>::Info measure;
|
||||
const std::vector<int> lengths(n, 1);
|
||||
const MPI_Datatype types[n]
|
||||
= { 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
|
||||
,* 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
|
||||
= std::find_if(slices.begin(), slices.end(),
|
||||
[&type](Slice const& s) {
|
||||
[&type](Slice<F> const& s) {
|
||||
return type == s.info.type;
|
||||
});
|
||||
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
|
||||
,*
|
||||
,*/
|
||||
static std::vector<Slice*> hasRecycledReferencingToIt
|
||||
( std::vector<Slice> &slices
|
||||
static std::vector<Slice<F>*> hasRecycledReferencingToIt
|
||||
( std::vector<Slice<F>> &slices
|
||||
, Info const& info
|
||||
) {
|
||||
std::vector<Slice*> result;
|
||||
std::vector<Slice<F>*> result;
|
||||
|
||||
for (auto& s: slices)
|
||||
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;
|
||||
}
|
||||
|
||||
static Slice&
|
||||
findRecycledSource (std::vector<Slice> &slices, Slice::Info info) {
|
||||
static Slice<F>&
|
||||
findRecycledSource (std::vector<Slice<F>> &slices, Slice<F>::Info info) {
|
||||
const auto sliceIt
|
||||
= std::find_if(slices.begin(), slices.end(),
|
||||
[&info](Slice const& s) {
|
||||
[&info](Slice<F> const& s) {
|
||||
return info.recycling == s.info.type
|
||||
&& info.tuple == s.info.tuple
|
||||
&& 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;
|
||||
}
|
||||
|
||||
static Slice& findByTypeAbc
|
||||
( std::vector<Slice> &slices
|
||||
, Slice::Type type
|
||||
static Slice<F>& findByTypeAbc
|
||||
( std::vector<Slice<F>> &slices
|
||||
, Slice<F>::Type type
|
||||
, ABCTuple const& abc
|
||||
) {
|
||||
const auto tuple = Slice::subtupleBySlice(abc, type);
|
||||
const auto tuple = Slice<F>::subtupleBySlice(abc, type);
|
||||
const auto sliceIt
|
||||
= std::find_if(slices.begin(), slices.end(),
|
||||
[&type, &tuple](Slice const& s) {
|
||||
[&type, &tuple](Slice<F> const& s) {
|
||||
return type == s.info.type
|
||||
&& tuple == s.info.tuple
|
||||
;
|
||||
@ -329,11 +329,11 @@ As an example, for the doubles amplitudes \( T^{ab}_{ij} \), one need two kinds
|
||||
return *sliceIt;
|
||||
}
|
||||
|
||||
static Slice& findByInfo(std::vector<Slice> &slices,
|
||||
Slice::Info const& info) {
|
||||
static Slice<F>& findByInfo(std::vector<Slice<F>> &slices,
|
||||
Slice<F>::Info const& info) {
|
||||
const auto sliceIt
|
||||
= std::find_if(slices.begin(), slices.end(),
|
||||
[&info](Slice const& s) {
|
||||
[&info](Slice<F> const& s) {
|
||||
// TODO: maybe implement comparison in Info struct
|
||||
return info.type == s.info.type
|
||||
&& 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
|
||||
|
||||
|
||||
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
|
||||
out << "{.r(" << v.rank << "), .s(" << v.source << ")};";
|
||||
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 << "»"
|
||||
<< " ⊙ {" << i.from.rank << ", " << i.from.source << "}"
|
||||
<< " ∴ {" << i.tuple[0] << ", " << i.tuple[1] << "}"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user