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 "rop_types.cc.h"
#include "rop_types.cc.h"
#include "rrange.cc.h"
#include "raindex.cc.h"
#include "rarray.cc.h"

View file

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

View file

@ -14,6 +14,7 @@
#include "rarray.h"
#include "raindex.h"
#include "rop_types.h"
namespace CNORXZ
{
@ -136,17 +137,27 @@ namespace CNORXZ
template <class... Indices>
inline decltype(auto) RCArray<T>::operator()(const SPack<Indices...>& pack) const
{
CXZ_ERROR("not implemented");
//return COpRoot<T,Index>();
return 0;
typedef typename std::remove_reference<decltype(*pack[CSizeT<0>{}])>::type I0;
if constexpr(is_rank_index<I0>::value){
// 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>
inline decltype(auto) RCArray<T>::operator()(const DPack& pack) const
{
CXZ_ERROR("not implemented");
//return COpRoot<T,Index>();
return 0;
// TODO: assert that none of the indices is rank index
return (*mA)(pack);
}
template <typename T>

View file

@ -10,54 +10,92 @@ namespace CNORXZ
| 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>
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>
constexpr decltype(auto) CROpRoot<T,IndexT>::operator()() const
template <typename T, class RIndexT, class IndexT>
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>
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 |
+===============*/
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>
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>
constexpr decltype(auto) ROpRoot<T,IndexT>::operator()() const
template <typename T, class RIndexT, class IndexT>
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>
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 |
+====================*/
/*
template <class CXpr>
constexpr RContraction<CXpr>::RContraction(CXpr&& cxpr) :
mCXpr(std::forward<CXpr>(cxpr))
@ -82,6 +120,6 @@ namespace CNORXZ
{
}
*/
} // namespace mpi
} // namespace CNORXZ

View file

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