2015-04-18 20:44:19 +01:00
|
|
|
#ifndef GRID_LATTICE_PEEK_H
|
|
|
|
#define GRID_LATTICE_PEEK_H
|
|
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
// Peeking and poking around
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace Grid {
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Peek internal indices of a Lattice object
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-05-15 11:38:04 +01:00
|
|
|
template<int Index,class vobj>
|
|
|
|
auto peekIndex(const Lattice<vobj> &lhs) -> Lattice<decltype(peekIndex<Index>(lhs._odata[0]))>
|
2015-04-18 20:44:19 +01:00
|
|
|
{
|
|
|
|
Lattice<decltype(peekIndex<Index>(lhs._odata[0]))> ret(lhs._grid);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-04-18 20:44:19 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
|
|
|
ret._odata[ss] = peekIndex<Index>(lhs._odata[ss]);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
template<int Index,class vobj>
|
2015-05-15 11:38:04 +01:00
|
|
|
auto peekIndex(const Lattice<vobj> &lhs,int i) -> Lattice<decltype(peekIndex<Index>(lhs._odata[0],i))>
|
2015-04-18 20:44:19 +01:00
|
|
|
{
|
|
|
|
Lattice<decltype(peekIndex<Index>(lhs._odata[0],i))> ret(lhs._grid);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-04-18 20:44:19 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
|
|
|
ret._odata[ss] = peekIndex<Index>(lhs._odata[ss],i);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
template<int Index,class vobj>
|
2015-05-15 11:38:04 +01:00
|
|
|
auto peekIndex(const Lattice<vobj> &lhs,int i,int j) -> Lattice<decltype(peekIndex<Index>(lhs._odata[0],i,j))>
|
2015-04-18 20:44:19 +01:00
|
|
|
{
|
|
|
|
Lattice<decltype(peekIndex<Index>(lhs._odata[0],i,j))> ret(lhs._grid);
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-04-18 20:44:19 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
|
|
|
ret._odata[ss] = peekIndex<Index>(lhs._odata[ss],i,j);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
2015-04-22 22:46:48 +01:00
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Poke internal indices of a Lattice object
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-05-15 11:38:04 +01:00
|
|
|
template<int Index,class vobj>
|
2015-04-18 20:44:19 +01:00
|
|
|
void pokeIndex(Lattice<vobj> &lhs,const Lattice<decltype(peekIndex<Index>(lhs._odata[0]))> & rhs)
|
|
|
|
{
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-04-18 20:44:19 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
|
|
|
pokeIndex<Index>(lhs._odata[ss],rhs._odata[ss]);
|
|
|
|
}
|
|
|
|
}
|
2015-05-15 11:38:04 +01:00
|
|
|
template<int Index,class vobj>
|
2015-04-18 20:44:19 +01:00
|
|
|
void pokeIndex(Lattice<vobj> &lhs,const Lattice<decltype(peekIndex<Index>(lhs._odata[0],0))> & rhs,int i)
|
|
|
|
{
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-04-18 20:44:19 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
|
|
|
pokeIndex<Index>(lhs._odata[ss],rhs._odata[ss],i);
|
|
|
|
}
|
|
|
|
}
|
2015-05-15 11:38:04 +01:00
|
|
|
template<int Index,class vobj>
|
|
|
|
void pokeIndex(Lattice<vobj> &lhs,const Lattice<decltype(peekIndex<Index>(lhs._odata[0],0,0))> & rhs,int i,int j)
|
2015-04-18 20:44:19 +01:00
|
|
|
{
|
2015-05-12 07:51:41 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
2015-04-18 20:44:19 +01:00
|
|
|
for(int ss=0;ss<lhs._grid->oSites();ss++){
|
|
|
|
pokeIndex<Index>(lhs._odata[ss],rhs._odata[ss],i,j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// Poke a scalar object into the SIMD array
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
template<class vobj,class sobj>
|
|
|
|
void pokeSite(const sobj &s,Lattice<vobj> &l,std::vector<int> &site){
|
|
|
|
|
|
|
|
GridBase *grid=l._grid;
|
|
|
|
|
|
|
|
typedef typename vobj::scalar_type scalar_type;
|
|
|
|
typedef typename vobj::vector_type vector_type;
|
|
|
|
|
|
|
|
int Nsimd = grid->Nsimd();
|
|
|
|
|
|
|
|
assert( l.checkerboard== l._grid->CheckerBoard(site));
|
|
|
|
assert( sizeof(sobj)*Nsimd == sizeof(vobj));
|
|
|
|
|
|
|
|
int rank,odx,idx;
|
|
|
|
// Optional to broadcast from node 0.
|
2015-04-22 22:46:48 +01:00
|
|
|
grid->GlobalCoorToRankIndex(rank,odx,idx,site);
|
|
|
|
grid->Broadcast(grid->BossRank(),s);
|
2015-04-18 20:44:19 +01:00
|
|
|
|
|
|
|
std::vector<sobj> buf(Nsimd);
|
|
|
|
|
|
|
|
// extract-modify-merge cycle is easiest way and this is not perf critical
|
2015-04-22 22:46:48 +01:00
|
|
|
if ( rank == grid->ThisRank() ) {
|
2015-04-28 08:11:59 +01:00
|
|
|
extract(l._odata[odx],buf);
|
2015-04-22 22:46:48 +01:00
|
|
|
buf[idx] = s;
|
2015-04-28 08:11:59 +01:00
|
|
|
merge(l._odata[odx],buf);
|
2015-04-22 22:46:48 +01:00
|
|
|
}
|
2015-04-18 20:44:19 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2015-04-22 22:46:48 +01:00
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
// Peek a scalar object from the SIMD array
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
template<class vobj,class sobj>
|
2015-05-13 09:24:10 +01:00
|
|
|
void peekSite(sobj &s,const Lattice<vobj> &l,std::vector<int> &site){
|
2015-04-18 20:44:19 +01:00
|
|
|
|
|
|
|
GridBase *grid=l._grid;
|
|
|
|
|
|
|
|
typedef typename vobj::scalar_type scalar_type;
|
|
|
|
typedef typename vobj::vector_type vector_type;
|
|
|
|
|
|
|
|
int Nsimd = grid->Nsimd();
|
|
|
|
|
|
|
|
assert( l.checkerboard== l._grid->CheckerBoard(site));
|
|
|
|
assert( sizeof(sobj)*Nsimd == sizeof(vobj));
|
|
|
|
|
|
|
|
int rank,odx,idx;
|
|
|
|
grid->GlobalCoorToRankIndex(rank,odx,idx,site);
|
2015-04-28 08:11:59 +01:00
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
std::vector<sobj> buf(Nsimd);
|
2015-04-28 08:11:59 +01:00
|
|
|
extract(l._odata[odx],buf);
|
2015-04-18 20:44:19 +01:00
|
|
|
|
|
|
|
s = buf[idx];
|
2015-04-28 08:11:59 +01:00
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
grid->Broadcast(rank,s);
|
|
|
|
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2015-04-22 22:46:48 +01:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
// Peek a scalar object from the SIMD array
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
template<class vobj,class sobj>
|
|
|
|
void peekLocalSite(sobj &s,Lattice<vobj> &l,std::vector<int> &site){
|
|
|
|
|
|
|
|
GridBase *grid=l._grid;
|
|
|
|
|
|
|
|
typedef typename vobj::scalar_type scalar_type;
|
|
|
|
typedef typename vobj::vector_type vector_type;
|
|
|
|
|
|
|
|
int Nsimd = grid->Nsimd();
|
|
|
|
|
|
|
|
assert( l.checkerboard== l._grid->CheckerBoard(site));
|
|
|
|
assert( sizeof(sobj)*Nsimd == sizeof(vobj));
|
|
|
|
|
|
|
|
int odx,idx;
|
|
|
|
idx= grid->iIndex(site);
|
|
|
|
odx= grid->oIndex(site);
|
|
|
|
|
|
|
|
std::vector<sobj> buf(Nsimd);
|
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
extract(l._odata[odx],buf);
|
2015-04-22 22:46:48 +01:00
|
|
|
|
|
|
|
s = buf[idx];
|
|
|
|
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class vobj,class sobj>
|
|
|
|
void pokeLocalSite(const sobj &s,Lattice<vobj> &l,std::vector<int> &site){
|
|
|
|
|
|
|
|
GridBase *grid=l._grid;
|
|
|
|
|
|
|
|
typedef typename vobj::scalar_type scalar_type;
|
|
|
|
typedef typename vobj::vector_type vector_type;
|
|
|
|
|
|
|
|
int Nsimd = grid->Nsimd();
|
|
|
|
|
|
|
|
assert( l.checkerboard== l._grid->CheckerBoard(site));
|
|
|
|
assert( sizeof(sobj)*Nsimd == sizeof(vobj));
|
|
|
|
|
|
|
|
int odx,idx;
|
|
|
|
idx= grid->iIndex(site);
|
|
|
|
odx= grid->oIndex(site);
|
|
|
|
|
|
|
|
std::vector<sobj> buf(Nsimd);
|
|
|
|
|
|
|
|
// extract-modify-merge cycle is easiest way and this is not perf critical
|
2015-04-28 08:11:59 +01:00
|
|
|
extract(l._odata[odx],buf);
|
2015-04-22 22:46:48 +01:00
|
|
|
|
|
|
|
buf[idx] = s;
|
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
merge(l._odata[odx],buf);
|
2015-04-22 22:46:48 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|