rop_types

This commit is contained in:
Christian Zimmermann 2024-04-14 16:45:29 +02:00
parent fae345f455
commit 6980bb5fdf
5 changed files with 105 additions and 40 deletions

View file

@ -10,7 +10,7 @@
**/ **/
#include "mpi_wrappers.cc.h" #include "mpi_wrappers.cc.h"
//#include "rop_types.cc.h" #include "rop_types.cc.h"
#include "rrange.cc.h" #include "rrange.cc.h"
#include "raindex.cc.h" #include "raindex.cc.h"
#include "rarray.cc.h" #include "rarray.cc.h"

View file

@ -14,7 +14,7 @@
#include "rrange.h" #include "rrange.h"
#include "raindex.h" #include "raindex.h"
#include "rarray.h" #include "rarray.h"
//#include "rop_types.h" #include "rop_types.h"
#include "typemap.h" #include "typemap.h"
#include "cnorxz_mpi.cc.h" #include "cnorxz_mpi.cc.h"

View file

@ -14,6 +14,7 @@
#include "rarray.h" #include "rarray.h"
#include "raindex.h" #include "raindex.h"
#include "rop_types.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -136,17 +137,27 @@ namespace CNORXZ
template <class... Indices> template <class... Indices>
inline decltype(auto) RCArray<T>::operator()(const SPack<Indices...>& pack) const inline decltype(auto) RCArray<T>::operator()(const SPack<Indices...>& pack) const
{ {
CXZ_ERROR("not implemented"); typedef typename std::remove_reference<decltype(*pack[CSizeT<0>{}])>::type I0;
//return COpRoot<T,Index>(); if constexpr(is_rank_index<I0>::value){
return 0; // preliminary:
CXZ_ASSERT(this->formatIsTrivial(),
"array has non-trivial format, rank operations require trivial format");
auto ri = pack[CSizeT<0>{}];
auto li = iter<1,sizeof...(Indices)>
( [&](auto i) { return pack[CSizeT<i>{}]; },
[](const auto&... x) { return mindexPtr( (x * ...) ); } );
return roproot(*this, ri, li);
}
else {
return (*mA)(pack);
}
} }
template <typename T> template <typename T>
inline decltype(auto) RCArray<T>::operator()(const DPack& pack) const inline decltype(auto) RCArray<T>::operator()(const DPack& pack) const
{ {
CXZ_ERROR("not implemented"); // TODO: assert that none of the indices is rank index
//return COpRoot<T,Index>(); return (*mA)(pack);
return 0;
} }
template <typename T> template <typename T>

View file

@ -10,54 +10,92 @@ namespace CNORXZ
| CROpRoot | | CROpRoot |
+================*/ +================*/
template <typename T, class IndexT> template <typename T, class RIndexT, class IndexT>
constexpr CROpRoot<T,RIndexT,IndexT>::CROpRoot(const RArray<T>& a, const Sptr<RIndexT>& ri,
const Sptr<IndexT>& li) :
mData(a.map()),
mRIndex(ri),
mIndex(li)
{
CXZ_ASSERT(a.map().size() == ri->lmax().val(),
"data map not properly initialized: map size = " << a.map.size()
<< ", rank index range size = " << ri->lmax().val());
}
template <typename T, class RIndexT, class IndexT>
template <class PosT> template <class PosT>
constexpr decltype(auto) CROpRoot<T,IndexT>::operator()(const PosT& pos) const constexpr decltype(auto) CROpRoot<T,RIndexT,IndexT>::operator()(const PosT& pos) const
{ {
return (mData+mPos[pos.val()])[pos.next().val()]; return (mData[pos.val()])[pos.next().val()];
} }
template <typename T, class IndexT> template <typename T, class RIndexT, class IndexT>
constexpr decltype(auto) CROpRoot<T,IndexT>::operator()() const constexpr decltype(auto) CROpRoot<T,RIndexT,IndexT>::operator()() const
{ {
return (mData+mPos[0])[0]; return (mData[0])[0];
} }
template <typename T, class IndexT> template <typename T, class RIndexT, class IndexT>
template <SizeT I> template <SizeT I>
constexpr decltype(auto) CROpRoot<T,IndexT>::rootSteps(const IndexId<I>& id) const constexpr decltype(auto) CROpRoot<T,RIndexT,IndexT>::rootSteps(const IndexId<I>& id) const
{ {
return mRIndex->stepSize(id) << mIndex->stepSize(id);
}
template <typename T, class RIndexT, class IndexT>
constexpr decltype(auto) croproot(const RArray<T>& a, const Sptr<RIndexT>& ri,
const Sptr<IndexT>& li)
{
return CROpRoot<T,RIndexT,IndexT>(a,ri,li);
} }
/*===============+ /*===============+
| ROpRoot | | ROpRoot |
+===============*/ +===============*/
template <typename T, class IndexT> template <typename T, class RIndexT, class IndexT>
constexpr ROpRoot<T,RIndexT,IndexT>::ROpRoot(RArray<T>& a, const Sptr<RIndexT>& ri,
const Sptr<IndexT>& li) :
mData(a.map()),
mRIndex(ri),
mIndex(li)
{
CXZ_ASSERT(a.map().size() == ri->lmax().val(),
"data map not properly initialized: map size = " << a.map.size()
<< ", rank index range size = " << ri->lmax().val());
}
template <typename T, class RIndexT, class IndexT>
template <class PosT> template <class PosT>
constexpr decltype(auto) ROpRoot<T,IndexT>::operator()(const PosT& pos) const constexpr decltype(auto) ROpRoot<T,RIndexT,IndexT>::operator()(const PosT& pos) const
{ {
return (mData[pos.val()])[pos.next().val()];
} }
template <typename T, class IndexT> template <typename T, class RIndexT, class IndexT>
constexpr decltype(auto) ROpRoot<T,IndexT>::operator()() const constexpr decltype(auto) ROpRoot<T,RIndexT,IndexT>::operator()() const
{ {
return (mData[0])[0];
} }
template <typename T, class IndexT> template <typename T, class RIndexT, class IndexT>
template <SizeT I> template <SizeT I>
constexpr decltype(auto) ROpRoot<T,IndexT>::rootSteps(const IndexId<I>& id) const constexpr decltype(auto) ROpRoot<T,RIndexT,IndexT>::rootSteps(const IndexId<I>& id) const
{ {
return mRIndex->stepSize(id) << mIndex->stepSize(id);
}
template <typename T, class RIndexT, class IndexT>
constexpr decltype(auto) roproot(RArray<T>& a, const Sptr<RIndexT>& ri,
const Sptr<IndexT>& li)
{
return ROpRoot<T,RIndexT,IndexT>(a,ri,li);
} }
/*====================+ /*====================+
| RContraction | | RContraction |
+====================*/ +====================*/
/*
template <class CXpr> template <class CXpr>
constexpr RContraction<CXpr>::RContraction(CXpr&& cxpr) : constexpr RContraction<CXpr>::RContraction(CXpr&& cxpr) :
mCXpr(std::forward<CXpr>(cxpr)) mCXpr(std::forward<CXpr>(cxpr))
@ -82,6 +120,6 @@ namespace CNORXZ
{ {
} }
*/
} // namespace mpi } // namespace mpi
} // namespace CNORXZ } // namespace CNORXZ

View file

@ -16,13 +16,15 @@ namespace CNORXZ
{ {
namespace mpi namespace mpi
{ {
template <typename T, class IndexT> template <typename T, class RIndexT, class IndexT>
class CROpRoot : public COpInterface<CROpRoot<T,IndexT>> class CROpRoot : public COpInterface<CROpRoot<T,RIndexT,IndexT>>
{ {
public: public:
typedef COpInterface<CROpRoot<T,IndexT >> OI; typedef COpInterface<CROpRoot<T,RIndexT,IndexT>> OI;
constexpr CROpRoot() = default; constexpr CROpRoot() = default;
constexpr CROpRoot(const RArray<T>& a, const Sptr<RIndexT>& ri,
const Sptr<IndexT>& li);
template <class PosT> template <class PosT>
constexpr decltype(auto) operator()(const PosT& pos) const; constexpr decltype(auto) operator()(const PosT& pos) const;
@ -33,20 +35,25 @@ namespace CNORXZ
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const; constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
private: private:
//
const T* mData; // must include all needed data, also that of other ranks (to be transmitted before!) const T** mData;
// maps the global (!) position to mData!! Sptr<RIndexT> mRIndex;
const SizeT* mPos; // position map (needed to indicate position to data transmitted from other ranks)
Sptr<IndexT> mIndex; Sptr<IndexT> mIndex;
}; };
template <typename T, class IndexT> template <typename T, class RIndexT, class IndexT>
class ROpRoot : public OpInterface<ROpRoot<T,IndexT>> constexpr decltype(auto) croproot(const RArray<T>& a, const Sptr<RIndexT>& ri,
const Sptr<IndexT>& li);
template <typename T, class RIndexT, class IndexT>
class ROpRoot : public OpInterface<ROpRoot<T,RIndexT,IndexT>>
{ {
public: public:
typedef OpInterface<ROpRoot<T,IndexT>> OI; typedef OpInterface<ROpRoot<T,RIndexT,IndexT>> OI;
constexpr ROpRoot() = default; constexpr ROpRoot() = default;
constexpr ROpRoot(RArray<T>& a, const Sptr<RIndexT>& ri,
const Sptr<IndexT>& li);
template <class PosT> template <class PosT>
constexpr decltype(auto) operator()(const PosT& pos) const; constexpr decltype(auto) operator()(const PosT& pos) const;
@ -58,8 +65,16 @@ namespace CNORXZ
private: private:
T** mData;
Sptr<RIndexT> mRIndex;
Sptr<IndexT> mIndex;
}; };
template <typename T, class RIndexT, class IndexT>
constexpr decltype(auto) roproot(RArray<T>& a, const Sptr<RIndexT>& ri,
const Sptr<IndexT>& li);
/*
template <class CXpr> template <class CXpr>
class RContraction : public OpInterfacte<RContraction<CXpr>> class RContraction : public OpInterfacte<RContraction<CXpr>>
{ {
@ -80,6 +95,7 @@ namespace CNORXZ
private: private:
CXpr mCXpr; CXpr mCXpr;
}; };
*/
} // namespace mpi } // namespace mpi
} // namespace CNORXZ } // namespace CNORXZ