2016-07-06 15:31:00 +01:00
|
|
|
/*************************************************************************************
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-06 15:31:00 +01:00
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-06 15:31:00 +01:00
|
|
|
Source file: ./lib/lattice/Lattice_base.h
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-06 15:31:00 +01:00
|
|
|
Copyright (C) 2015
|
2016-01-02 14:51:32 +00:00
|
|
|
|
|
|
|
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
|
|
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|
|
|
Author: paboyle <paboyle@ph.ed.ac.uk>
|
|
|
|
|
2016-07-06 15:31:00 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-06 15:31:00 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-06 15:31:00 +01:00
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-06 15:31:00 +01:00
|
|
|
See the full license in the file "LICENSE" in the top level distribution
|
|
|
|
directory
|
|
|
|
*************************************************************************************/
|
2018-01-15 00:03:49 +00:00
|
|
|
/* END LEGAL */
|
2018-01-24 13:35:13 +00:00
|
|
|
#pragma once
|
2015-05-11 19:09:49 +01:00
|
|
|
|
2015-05-21 06:47:05 +01:00
|
|
|
#define STREAMING_STORES
|
|
|
|
|
2018-01-15 00:03:49 +00:00
|
|
|
NAMESPACE_BEGIN(Grid);
|
2015-05-11 19:09:49 +01:00
|
|
|
|
|
|
|
extern int GridCshiftPermuteMap[4][16];
|
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Base class which can be used by traits to pick up behaviour
|
|
|
|
///////////////////////////////////////////////////////////////////
|
2018-01-25 23:35:04 +00:00
|
|
|
class LatticeBase {};
|
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Conformable checks; same instance of Grid required
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void accelerator_inline conformable(GridBase *lhs,GridBase *rhs)
|
|
|
|
{
|
|
|
|
assert(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Minimal base class containing only data valid to access from accelerator
|
|
|
|
// _odata will be a managed pointer in CUDA
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Force access to lattice through a view object.
|
|
|
|
// prevents writing of code that will not offload to GPU, but perhaps annoyingly
|
|
|
|
// strict since host could could in principle direct access through the lattice object
|
|
|
|
// Need to decide programming model.
|
|
|
|
#define LATTICE_VIEW_STRICT
|
2018-01-25 23:35:04 +00:00
|
|
|
template<class vobj> class LatticeAccelerator : public LatticeBase
|
2016-05-04 20:15:31 +01:00
|
|
|
{
|
2018-01-26 22:27:47 +00:00
|
|
|
protected:
|
2018-03-04 16:02:02 +00:00
|
|
|
GridBase *_grid;
|
2018-01-25 23:35:04 +00:00
|
|
|
int checkerboard;
|
|
|
|
vobj *_odata; // A managed pointer
|
|
|
|
uint64_t _odata_size;
|
2018-01-26 22:27:47 +00:00
|
|
|
public:
|
2018-03-04 16:02:02 +00:00
|
|
|
accelerator_inline LatticeAccelerator() : checkerboard(0), _odata(nullptr), _odata_size(0), _grid(nullptr) { };
|
2018-03-08 21:00:25 +00:00
|
|
|
accelerator_inline uint64_t oSites(void) const { return _odata_size; };
|
2018-03-04 16:02:02 +00:00
|
|
|
accelerator_inline int Checkerboard(void) const { return checkerboard; };
|
|
|
|
accelerator_inline int &Checkerboard(void) { return this->checkerboard; }; // can assign checkerboard on a container, not a view
|
|
|
|
accelerator_inline void Conformable(GridBase * &grid) const
|
|
|
|
{
|
|
|
|
if (grid) conformable(grid, _grid);
|
|
|
|
else grid = _grid;
|
|
|
|
};
|
|
|
|
#ifndef LATTICE_VIEW_STRICT
|
|
|
|
accelerator_inline vobj & operator[](size_t i) { return this->_odata[i]; };
|
|
|
|
accelerator_inline const vobj & operator[](size_t i) const { return this->_odata[i]; };
|
|
|
|
#endif
|
2016-05-04 20:15:31 +01:00
|
|
|
};
|
2015-05-11 19:09:49 +01:00
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// A View class which provides accessor to the data.
|
|
|
|
// This will be safe to call from accelerator_loops and is trivially copy constructible
|
|
|
|
// The copy constructor for this will need to be used by device lambda functions
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
template<class vobj>
|
|
|
|
class LatticeView : public LatticeAccelerator<vobj>
|
|
|
|
{
|
2018-01-15 00:03:49 +00:00
|
|
|
public:
|
2018-03-04 16:02:02 +00:00
|
|
|
#ifdef LATTICE_VIEW_STRICT
|
|
|
|
accelerator_inline vobj & operator[](size_t i) { return this->_odata[i]; };
|
|
|
|
accelerator_inline const vobj & operator[](size_t i) const { return this->_odata[i]; };
|
|
|
|
#endif
|
|
|
|
accelerator_inline uint64_t begin(void) const { return 0;};
|
|
|
|
accelerator_inline uint64_t end(void) const { return this->_odata_size; };
|
|
|
|
accelerator_inline uint64_t size(void) const { return this->_odata_size; };
|
|
|
|
|
|
|
|
LatticeView(const LatticeAccelerator<vobj> &refer_to_me) : LatticeAccelerator<vobj> (refer_to_me)
|
|
|
|
{
|
|
|
|
}
|
2015-05-11 19:09:49 +01:00
|
|
|
};
|
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Lattice expression types used by ET to assemble the AST
|
|
|
|
//
|
|
|
|
// Need to be able to detect code paths according to the whether a lattice object or not
|
|
|
|
// so introduce some trait type things
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class LatticeExpressionBase {};
|
|
|
|
|
|
|
|
template <typename T> using is_lattice = std::is_base_of<LatticeBase, T>;
|
|
|
|
template <typename T> using is_lattice_expr = std::is_base_of<LatticeExpressionBase,T >;
|
|
|
|
|
|
|
|
template<class T, bool isLattice> struct ViewMapBase { typedef T Type; };
|
|
|
|
template<class T> struct ViewMapBase<T,true> { typedef LatticeView<typename T::vector_object> Type; };
|
|
|
|
template<class T> using ViewMap = ViewMapBase<T,std::is_base_of<LatticeBase, T>::value >;
|
|
|
|
|
|
|
|
template <typename Op, typename _T1>
|
|
|
|
class LatticeUnaryExpression : public LatticeExpressionBase
|
|
|
|
{
|
2018-01-15 00:03:49 +00:00
|
|
|
public:
|
2018-03-04 16:02:02 +00:00
|
|
|
typedef typename ViewMap<_T1>::Type T1;
|
|
|
|
Op op;
|
|
|
|
T1 arg1;
|
|
|
|
LatticeUnaryExpression(Op _op,const _T1 &_arg1) : op(_op), arg1(_arg1) {};
|
2015-05-11 19:09:49 +01:00
|
|
|
};
|
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
template <typename Op, typename _T1, typename _T2>
|
|
|
|
class LatticeBinaryExpression : public LatticeExpressionBase
|
|
|
|
{
|
2018-01-15 00:03:49 +00:00
|
|
|
public:
|
2018-03-04 16:02:02 +00:00
|
|
|
typedef typename ViewMap<_T1>::Type T1;
|
|
|
|
typedef typename ViewMap<_T2>::Type T2;
|
|
|
|
Op op;
|
|
|
|
T1 arg1;
|
|
|
|
T2 arg2;
|
|
|
|
LatticeBinaryExpression(Op _op,const _T1 &_arg1,const _T2 &_arg2) : op(_op), arg1(_arg1), arg2(_arg2) {};
|
2015-05-11 19:09:49 +01:00
|
|
|
};
|
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
template <typename Op, typename _T1, typename _T2, typename _T3>
|
|
|
|
class LatticeTrinaryExpression : public LatticeExpressionBase
|
2015-05-26 19:54:03 +01:00
|
|
|
{
|
2018-03-04 16:02:02 +00:00
|
|
|
public:
|
|
|
|
typedef typename ViewMap<_T1>::Type T1;
|
|
|
|
typedef typename ViewMap<_T2>::Type T2;
|
|
|
|
typedef typename ViewMap<_T3>::Type T3;
|
|
|
|
Op op;
|
|
|
|
T1 arg1;
|
|
|
|
T2 arg2;
|
|
|
|
T3 arg3;
|
|
|
|
LatticeTrinaryExpression(Op _op,const _T1 &_arg1,const _T2 &_arg2,const _T3 &_arg3) : op(_op), arg1(_arg1), arg2(_arg2), arg3(_arg3) {};
|
|
|
|
};
|
2015-05-26 19:54:03 +01:00
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// The real lattice class, with normal copy and assignment semantics.
|
|
|
|
// This contains extra (host resident) grid pointer data that may be accessed by host code
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
2015-05-11 19:09:49 +01:00
|
|
|
template<class vobj>
|
2018-01-25 23:35:04 +00:00
|
|
|
class Lattice : public LatticeAccelerator<vobj>
|
2015-05-11 19:09:49 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-03-04 16:02:02 +00:00
|
|
|
GridBase *Grid(void) const { return this->_grid; }
|
2018-01-25 23:35:04 +00:00
|
|
|
///////////////////////////////////////////////////
|
|
|
|
// Member types
|
|
|
|
///////////////////////////////////////////////////
|
2018-01-15 00:03:49 +00:00
|
|
|
typedef typename vobj::scalar_type scalar_type;
|
|
|
|
typedef typename vobj::vector_type vector_type;
|
|
|
|
typedef vobj vector_object;
|
2018-01-24 13:35:13 +00:00
|
|
|
|
2018-01-25 23:35:04 +00:00
|
|
|
private:
|
|
|
|
void dealloc(void)
|
|
|
|
{
|
|
|
|
alignedAllocator<vobj> alloc;
|
|
|
|
if( this->_odata_size ) {
|
|
|
|
alloc.deallocate(this->_odata,this->_odata_size);
|
|
|
|
this->_odata=nullptr;
|
|
|
|
this->_odata_size=0;
|
|
|
|
}
|
|
|
|
}
|
2018-01-24 13:35:13 +00:00
|
|
|
void resize(uint64_t size)
|
|
|
|
{
|
2018-01-25 23:35:04 +00:00
|
|
|
alignedAllocator<vobj> alloc;
|
|
|
|
if ( this->_odata_size != size ) {
|
|
|
|
dealloc();
|
|
|
|
}
|
|
|
|
this->_odata_size = size;
|
|
|
|
if ( size )
|
|
|
|
this->_odata = alloc.allocate(this->_odata_size);
|
|
|
|
else
|
|
|
|
this->_odata = nullptr;
|
|
|
|
}
|
2018-03-04 16:02:02 +00:00
|
|
|
#if 0
|
2018-01-25 23:35:04 +00:00
|
|
|
void copy_vec(vobj *ptr,uint64_t count)
|
|
|
|
{
|
|
|
|
dealloc();
|
|
|
|
this->_odata = ptr;
|
|
|
|
assert(this->_odata_size == count);
|
|
|
|
}
|
2018-03-04 16:02:02 +00:00
|
|
|
#endif
|
2018-01-25 23:35:04 +00:00
|
|
|
public:
|
2018-03-04 16:02:02 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Return a view object that may be dereferenced in site loops.
|
|
|
|
// The view is trivially copy constructible and may be copied to an accelerator device
|
|
|
|
// in device lambdas
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
LatticeView<vobj> View (void) const
|
|
|
|
{
|
|
|
|
LatticeView<vobj> accessor(*( (LatticeAccelerator<vobj> *) this));
|
|
|
|
return accessor;
|
|
|
|
}
|
|
|
|
|
2018-01-25 23:35:04 +00:00
|
|
|
~Lattice() {
|
|
|
|
if ( this->_odata_size ) {
|
|
|
|
dealloc();
|
|
|
|
}
|
|
|
|
}
|
2015-05-11 19:09:49 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Expression Template closure support
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-03-04 16:02:02 +00:00
|
|
|
template <typename Op, typename T1> inline Lattice<vobj> & operator=(const LatticeUnaryExpression<Op,T1> &expr)
|
2015-05-11 19:09:49 +01:00
|
|
|
{
|
2015-05-25 13:45:08 +01:00
|
|
|
GridBase *egrid(nullptr);
|
|
|
|
GridFromExpression(egrid,expr);
|
|
|
|
assert(egrid!=nullptr);
|
2018-03-04 16:02:02 +00:00
|
|
|
conformable(this->_grid,egrid);
|
2015-05-25 13:45:08 +01:00
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
2018-01-25 23:35:04 +00:00
|
|
|
this->checkerboard=cb;
|
2015-05-25 13:45:08 +01:00
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
auto me = View();
|
2015-05-21 06:47:05 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2018-03-04 16:02:02 +00:00
|
|
|
accelerator_loop(ss,me,{
|
2015-05-21 06:47:05 +01:00
|
|
|
vobj tmp = eval(ss,expr);
|
2018-03-04 16:02:02 +00:00
|
|
|
vstream(me[ss] ,tmp);
|
2018-01-24 13:35:13 +00:00
|
|
|
});
|
2015-05-21 06:47:05 +01:00
|
|
|
#else
|
2018-03-04 16:02:02 +00:00
|
|
|
accelerator_loop(ss,me,{
|
|
|
|
me[ss]=eval(ss,expr);
|
2018-01-24 13:35:13 +00:00
|
|
|
});
|
2015-05-21 06:47:05 +01:00
|
|
|
#endif
|
2015-05-11 19:09:49 +01:00
|
|
|
return *this;
|
|
|
|
}
|
2018-01-24 13:35:13 +00:00
|
|
|
template <typename Op, typename T1,typename T2> inline Lattice<vobj> & operator=(const LatticeBinaryExpression<Op,T1,T2> &expr)
|
2015-05-11 19:09:49 +01:00
|
|
|
{
|
2015-05-25 13:45:08 +01:00
|
|
|
GridBase *egrid(nullptr);
|
|
|
|
GridFromExpression(egrid,expr);
|
|
|
|
assert(egrid!=nullptr);
|
2018-03-04 16:02:02 +00:00
|
|
|
conformable(this->_grid,egrid);
|
2015-05-25 13:45:08 +01:00
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
2018-01-25 23:35:04 +00:00
|
|
|
this->checkerboard=cb;
|
2015-05-25 13:45:08 +01:00
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
auto me = View();
|
2015-05-21 06:47:05 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2018-03-04 16:02:02 +00:00
|
|
|
accelerator_loop(ss,me,{
|
2015-05-21 06:47:05 +01:00
|
|
|
vobj tmp = eval(ss,expr);
|
2018-03-04 16:02:02 +00:00
|
|
|
vstream(me[ss] ,tmp);
|
2018-01-24 13:35:13 +00:00
|
|
|
});
|
2015-05-21 06:47:05 +01:00
|
|
|
#else
|
2018-03-04 16:02:02 +00:00
|
|
|
accelerator_loop(ss,me,{
|
|
|
|
me[ss]=eval(ss,expr);
|
2018-01-24 13:35:13 +00:00
|
|
|
});
|
2015-05-21 06:47:05 +01:00
|
|
|
#endif
|
2015-05-11 19:09:49 +01:00
|
|
|
return *this;
|
|
|
|
}
|
2018-01-24 13:35:13 +00:00
|
|
|
template <typename Op, typename T1,typename T2,typename T3> inline Lattice<vobj> & operator=(const LatticeTrinaryExpression<Op,T1,T2,T3> &expr)
|
2015-05-11 19:09:49 +01:00
|
|
|
{
|
2015-05-25 13:45:08 +01:00
|
|
|
GridBase *egrid(nullptr);
|
|
|
|
GridFromExpression(egrid,expr);
|
|
|
|
assert(egrid!=nullptr);
|
2018-03-04 16:02:02 +00:00
|
|
|
conformable(this->_grid,egrid);
|
2015-05-25 13:45:08 +01:00
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
2018-01-25 23:35:04 +00:00
|
|
|
this->checkerboard=cb;
|
2018-03-04 16:02:02 +00:00
|
|
|
auto me = View();
|
2015-05-21 06:47:05 +01:00
|
|
|
#ifdef STREAMING_STORES
|
2018-03-04 16:02:02 +00:00
|
|
|
accelerator_loop(ss,me,{
|
2018-01-25 23:35:04 +00:00
|
|
|
vobj tmp = eval(ss,expr);
|
2018-03-04 16:02:02 +00:00
|
|
|
vstream(me[ss] ,tmp);
|
2018-01-24 13:35:13 +00:00
|
|
|
});
|
2015-05-21 06:47:05 +01:00
|
|
|
#else
|
2018-03-04 16:02:02 +00:00
|
|
|
accelerator_loop(ss,me,{
|
|
|
|
me[ss] = eval(ss,expr);
|
2018-01-24 13:35:13 +00:00
|
|
|
});
|
2015-05-21 06:47:05 +01:00
|
|
|
#endif
|
2015-05-11 19:09:49 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
//GridFromExpression is tricky to do
|
|
|
|
template<class Op,class T1>
|
2018-01-15 00:03:49 +00:00
|
|
|
Lattice(const LatticeUnaryExpression<Op,T1> & expr) {
|
2018-03-04 16:02:02 +00:00
|
|
|
this->_grid = nullptr;
|
|
|
|
GridFromExpression(this->_grid,expr);
|
|
|
|
assert(this->_grid!=nullptr);
|
2015-05-25 13:45:08 +01:00
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
2018-01-25 23:35:04 +00:00
|
|
|
this->checkerboard=cb;
|
2015-05-25 13:45:08 +01:00
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
resize(this->_grid->oSites());
|
2018-02-02 11:27:35 +00:00
|
|
|
|
|
|
|
*this = expr;
|
2018-01-24 13:35:13 +00:00
|
|
|
}
|
2015-05-11 19:09:49 +01:00
|
|
|
template<class Op,class T1, class T2>
|
2016-05-04 20:15:31 +01:00
|
|
|
Lattice(const LatticeBinaryExpression<Op,T1,T2> & expr) {
|
2018-03-04 16:02:02 +00:00
|
|
|
this->_grid = nullptr;
|
|
|
|
GridFromExpression(this->_grid,expr);
|
|
|
|
assert(this->_grid!=nullptr);
|
2015-05-25 13:45:08 +01:00
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
2018-01-25 23:35:04 +00:00
|
|
|
this->checkerboard=cb;
|
2018-02-02 11:27:35 +00:00
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
resize(this->_grid->oSites());
|
2018-02-02 11:27:35 +00:00
|
|
|
|
|
|
|
*this = expr;
|
2018-01-24 13:35:13 +00:00
|
|
|
}
|
2015-05-11 19:09:49 +01:00
|
|
|
template<class Op,class T1, class T2, class T3>
|
2016-05-04 20:15:31 +01:00
|
|
|
Lattice(const LatticeTrinaryExpression<Op,T1,T2,T3> & expr) {
|
2018-03-04 16:02:02 +00:00
|
|
|
this->_grid = nullptr;
|
|
|
|
GridFromExpression(this->_grid,expr);
|
|
|
|
assert(this->_grid!=nullptr);
|
2015-05-25 13:45:08 +01:00
|
|
|
|
|
|
|
int cb=-1;
|
|
|
|
CBFromExpression(cb,expr);
|
|
|
|
assert( (cb==Odd) || (cb==Even));
|
2018-01-25 23:35:04 +00:00
|
|
|
this->checkerboard=cb;
|
2015-05-25 13:45:08 +01:00
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
resize(this->_grid->oSites());
|
2015-05-11 19:09:49 +01:00
|
|
|
|
2018-02-02 11:27:35 +00:00
|
|
|
*this = expr;
|
2017-04-05 14:41:04 +01:00
|
|
|
}
|
2015-05-11 19:09:49 +01:00
|
|
|
|
2018-01-24 13:35:13 +00:00
|
|
|
template<class sobj> inline Lattice<vobj> & operator = (const sobj & r){
|
2018-03-04 16:02:02 +00:00
|
|
|
auto me = View();
|
|
|
|
accelerator_loop(ss,me,{
|
|
|
|
me[ss]=r;
|
2018-01-24 13:35:13 +00:00
|
|
|
});
|
2017-04-05 14:41:04 +01:00
|
|
|
return *this;
|
|
|
|
}
|
2018-01-25 23:35:04 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Follow rule of five, with Constructor requires "grid" passed
|
|
|
|
// to user defined constructor
|
2018-03-04 16:02:02 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// user defined constructor
|
|
|
|
///////////////////////////////////////////
|
|
|
|
Lattice(GridBase *grid) {
|
|
|
|
this->_grid = grid;
|
|
|
|
resize(this->_grid->oSites());
|
2018-01-25 23:35:04 +00:00
|
|
|
assert((((uint64_t)&this->_odata[0])&0xF) ==0);
|
|
|
|
this->checkerboard=0;
|
|
|
|
}
|
2018-03-04 16:02:02 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// copy constructor
|
|
|
|
///////////////////////////////////////////
|
|
|
|
Lattice(const Lattice& r){
|
2018-01-25 23:35:04 +00:00
|
|
|
// std::cout << "Lattice constructor(const Lattice &) "<<this<<std::endl;
|
2018-03-04 16:02:02 +00:00
|
|
|
this->_grid = r.Grid();
|
|
|
|
resize(this->_grid->oSites());
|
2018-02-02 11:27:35 +00:00
|
|
|
*this = r;
|
2018-01-25 23:35:04 +00:00
|
|
|
}
|
2018-03-04 16:02:02 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// move constructor
|
|
|
|
///////////////////////////////////////////
|
|
|
|
Lattice(Lattice && r){
|
|
|
|
this->_grid = r.Grid();
|
2018-01-25 23:35:04 +00:00
|
|
|
this->_odata = r._odata;
|
|
|
|
this->_odata_size = r._odata_size;
|
2018-01-26 23:06:03 +00:00
|
|
|
this->checkerboard= r.Checkerboard();
|
2018-01-25 23:35:04 +00:00
|
|
|
r._odata = nullptr;
|
|
|
|
r._odata_size = 0;
|
|
|
|
}
|
2018-03-04 16:02:02 +00:00
|
|
|
///////////////////////////////////////////
|
2018-01-25 23:35:04 +00:00
|
|
|
// assignment template
|
2018-03-04 16:02:02 +00:00
|
|
|
///////////////////////////////////////////
|
2018-01-24 13:35:13 +00:00
|
|
|
template<class robj> inline Lattice<vobj> & operator = (const Lattice<robj> & r){
|
2018-01-25 23:35:04 +00:00
|
|
|
typename std::enable_if<!std::is_same<robj,vobj>::value,int>::type i=0;
|
|
|
|
conformable(*this,r);
|
2018-03-04 16:02:02 +00:00
|
|
|
this->checkerboard = r.Checkerboard();
|
|
|
|
auto me = View();
|
|
|
|
auto him= r.View();
|
|
|
|
accelerator_loop(ss,me,{
|
|
|
|
me[ss]=him[ss];
|
2018-01-25 23:35:04 +00:00
|
|
|
});
|
|
|
|
return *this;
|
|
|
|
}
|
2018-03-04 16:02:02 +00:00
|
|
|
///////////////////////////////////////////
|
2018-01-25 23:35:04 +00:00
|
|
|
// Copy assignment
|
2018-03-04 16:02:02 +00:00
|
|
|
///////////////////////////////////////////
|
2018-01-25 23:35:04 +00:00
|
|
|
inline Lattice<vobj> & operator = (const Lattice<vobj> & r){
|
2018-01-26 23:06:03 +00:00
|
|
|
this->checkerboard = r.Checkerboard();
|
2017-04-05 14:41:04 +01:00
|
|
|
conformable(*this,r);
|
2018-03-04 16:02:02 +00:00
|
|
|
auto me = View();
|
|
|
|
auto him= r.View();
|
|
|
|
accelerator_loop(ss,me,{
|
|
|
|
me[ss]=him[ss];
|
2018-01-24 13:35:13 +00:00
|
|
|
});
|
2017-04-05 14:41:04 +01:00
|
|
|
return *this;
|
|
|
|
}
|
2018-03-04 16:02:02 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// Move assignment possible if same type
|
|
|
|
///////////////////////////////////////////
|
2018-01-25 23:35:04 +00:00
|
|
|
inline Lattice<vobj> & operator = (Lattice<vobj> && r){
|
|
|
|
|
2018-03-04 16:02:02 +00:00
|
|
|
resize(0); // deletes if appropriate
|
|
|
|
this->_grid = r.Grid();
|
2018-01-25 23:35:04 +00:00
|
|
|
this->_odata = r._odata;
|
|
|
|
this->_odata_size = r._odata_size;
|
2018-01-26 23:06:03 +00:00
|
|
|
this->checkerboard= r.Checkerboard();
|
2018-01-25 23:35:04 +00:00
|
|
|
|
|
|
|
r._odata = nullptr;
|
|
|
|
r._odata_size = 0;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2018-03-04 16:02:02 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2017-04-05 14:41:04 +01:00
|
|
|
// *=,+=,-= operators inherit behvour from correspond */+/- operation
|
2018-03-04 16:02:02 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2018-01-24 13:35:13 +00:00
|
|
|
template<class T> inline Lattice<vobj> &operator *=(const T &r) {
|
2017-04-05 14:41:04 +01:00
|
|
|
*this = (*this)*r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:35:13 +00:00
|
|
|
template<class T> inline Lattice<vobj> &operator -=(const T &r) {
|
2017-04-05 14:41:04 +01:00
|
|
|
*this = (*this)-r;
|
|
|
|
return *this;
|
|
|
|
}
|
2018-01-24 13:35:13 +00:00
|
|
|
template<class T> inline Lattice<vobj> &operator +=(const T &r) {
|
2017-04-05 14:41:04 +01:00
|
|
|
*this = (*this)+r;
|
|
|
|
return *this;
|
|
|
|
}
|
2018-01-27 23:50:17 +00:00
|
|
|
|
|
|
|
friend inline void swap(Lattice &l, Lattice &r) {
|
|
|
|
conformable(l,r);
|
|
|
|
LatticeAccelerator<vobj> tmp;
|
|
|
|
LatticeAccelerator<vobj> *lp = (LatticeAccelerator<vobj> *)&l;
|
|
|
|
LatticeAccelerator<vobj> *rp = (LatticeAccelerator<vobj> *)&r;
|
|
|
|
tmp = *lp; *lp=*rp; *rp=tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-05 14:41:04 +01:00
|
|
|
}; // class Lattice
|
2018-01-25 23:35:04 +00:00
|
|
|
|
2018-01-15 00:03:49 +00:00
|
|
|
template<class vobj> std::ostream& operator<< (std::ostream& stream, const Lattice<vobj> &o){
|
|
|
|
typedef typename vobj::scalar_object sobj;
|
2018-01-27 00:04:12 +00:00
|
|
|
for(int g=0;g<o.Grid()->_gsites;g++){
|
2018-02-24 22:26:10 +00:00
|
|
|
|
|
|
|
Coordinate gcoor;
|
2018-01-27 00:04:12 +00:00
|
|
|
o.Grid()->GlobalIndexToGlobalCoor(g,gcoor);
|
2018-02-24 22:26:10 +00:00
|
|
|
|
|
|
|
sobj ss;
|
2018-01-15 00:03:49 +00:00
|
|
|
peekSite(ss,o,gcoor);
|
|
|
|
stream<<"[";
|
|
|
|
for(int d=0;d<gcoor.size();d++){
|
|
|
|
stream<<gcoor[d];
|
|
|
|
if(d!=gcoor.size()-1) stream<<",";
|
2015-05-13 09:24:10 +01:00
|
|
|
}
|
2018-01-15 00:03:49 +00:00
|
|
|
stream<<"]\t";
|
|
|
|
stream<<ss<<std::endl;
|
2015-05-13 09:24:10 +01:00
|
|
|
}
|
2018-01-15 00:03:49 +00:00
|
|
|
return stream;
|
2015-05-11 19:09:49 +01:00
|
|
|
}
|
2018-01-15 00:03:49 +00:00
|
|
|
|
|
|
|
NAMESPACE_END(Grid);
|
2015-05-11 19:09:49 +01:00
|
|
|
|