mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Merge branch 'develop' of https://github.com/paboyle/Grid into develop
This commit is contained in:
commit
a0ccbb3bd6
@ -350,7 +350,6 @@ GridUnopClass(UnaryTimesI, timesI(a));
|
|||||||
GridUnopClass(UnaryTimesMinusI, timesMinusI(a));
|
GridUnopClass(UnaryTimesMinusI, timesMinusI(a));
|
||||||
GridUnopClass(UnaryAbs, abs(a));
|
GridUnopClass(UnaryAbs, abs(a));
|
||||||
GridUnopClass(UnarySqrt, sqrt(a));
|
GridUnopClass(UnarySqrt, sqrt(a));
|
||||||
GridUnopClass(UnaryRsqrt, rsqrt(a));
|
|
||||||
GridUnopClass(UnarySin, sin(a));
|
GridUnopClass(UnarySin, sin(a));
|
||||||
GridUnopClass(UnaryCos, cos(a));
|
GridUnopClass(UnaryCos, cos(a));
|
||||||
GridUnopClass(UnaryAsin, asin(a));
|
GridUnopClass(UnaryAsin, asin(a));
|
||||||
@ -463,7 +462,6 @@ GRID_DEF_UNOP(timesMinusI, UnaryTimesMinusI);
|
|||||||
GRID_DEF_UNOP(abs, UnaryAbs); // abs overloaded in cmath C++98; DON'T do the
|
GRID_DEF_UNOP(abs, UnaryAbs); // abs overloaded in cmath C++98; DON'T do the
|
||||||
// abs-fabs-dabs-labs thing
|
// abs-fabs-dabs-labs thing
|
||||||
GRID_DEF_UNOP(sqrt, UnarySqrt);
|
GRID_DEF_UNOP(sqrt, UnarySqrt);
|
||||||
GRID_DEF_UNOP(rsqrt, UnaryRsqrt);
|
|
||||||
GRID_DEF_UNOP(sin, UnarySin);
|
GRID_DEF_UNOP(sin, UnarySin);
|
||||||
GRID_DEF_UNOP(cos, UnaryCos);
|
GRID_DEF_UNOP(cos, UnaryCos);
|
||||||
GRID_DEF_UNOP(asin, UnaryAsin);
|
GRID_DEF_UNOP(asin, UnaryAsin);
|
||||||
|
@ -125,14 +125,6 @@ accelerator_inline Grid_simd<S, V> sqrt(const Grid_simd<S, V> &r) {
|
|||||||
return SimdApply(SqrtRealFunctor<S>(), r);
|
return SimdApply(SqrtRealFunctor<S>(), r);
|
||||||
}
|
}
|
||||||
template <class S, class V>
|
template <class S, class V>
|
||||||
accelerator_inline Grid_simd<S, V> rsqrt(const Grid_simd<S, V> &r) {
|
|
||||||
return SimdApply(RSqrtRealFunctor<S>(), r);
|
|
||||||
}
|
|
||||||
template <class Scalar>
|
|
||||||
accelerator_inline Scalar rsqrt(const Scalar &r) {
|
|
||||||
return (RSqrtRealFunctor<Scalar>(), r);
|
|
||||||
}
|
|
||||||
template <class S, class V>
|
|
||||||
accelerator_inline Grid_simd<S, V> cos(const Grid_simd<S, V> &r) {
|
accelerator_inline Grid_simd<S, V> cos(const Grid_simd<S, V> &r) {
|
||||||
return SimdApply(CosRealFunctor<S>(), r);
|
return SimdApply(CosRealFunctor<S>(), r);
|
||||||
}
|
}
|
||||||
|
@ -92,17 +92,22 @@ accelerator_inline iMatrix<vtype,N> ProjectOnGroup(const iMatrix<vtype,N> &arg)
|
|||||||
{
|
{
|
||||||
// need a check for the group type?
|
// need a check for the group type?
|
||||||
iMatrix<vtype,N> ret(arg);
|
iMatrix<vtype,N> ret(arg);
|
||||||
|
vtype rnrm;
|
||||||
vtype nrm;
|
vtype nrm;
|
||||||
vtype inner;
|
vtype inner;
|
||||||
for(int c1=0;c1<N;c1++){
|
for(int c1=0;c1<N;c1++){
|
||||||
|
|
||||||
|
// Normalises row c1
|
||||||
zeroit(inner);
|
zeroit(inner);
|
||||||
for(int c2=0;c2<N;c2++)
|
for(int c2=0;c2<N;c2++)
|
||||||
inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
|
inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
|
||||||
|
|
||||||
nrm = rsqrt(inner);
|
nrm = sqrt(inner);
|
||||||
|
nrm = 1.0/nrm;
|
||||||
for(int c2=0;c2<N;c2++)
|
for(int c2=0;c2<N;c2++)
|
||||||
ret._internal[c1][c2]*= nrm;
|
ret._internal[c1][c2]*= nrm;
|
||||||
|
|
||||||
|
// Remove c1 from rows c1+1...N-1
|
||||||
for (int b=c1+1; b<N; ++b){
|
for (int b=c1+1; b<N; ++b){
|
||||||
decltype(ret._internal[b][b]*ret._internal[b][b]) pr;
|
decltype(ret._internal[b][b]*ret._internal[b][b]) pr;
|
||||||
zeroit(pr);
|
zeroit(pr);
|
||||||
|
@ -84,7 +84,6 @@ NAMESPACE_BEGIN(Grid);
|
|||||||
}
|
}
|
||||||
|
|
||||||
UNARY(sqrt);
|
UNARY(sqrt);
|
||||||
UNARY(rsqrt);
|
|
||||||
UNARY(sin);
|
UNARY(sin);
|
||||||
UNARY(cos);
|
UNARY(cos);
|
||||||
UNARY(asin);
|
UNARY(asin);
|
||||||
|
@ -328,7 +328,7 @@ inline void *acceleratorAllocDevice(size_t bytes)
|
|||||||
return ptr;
|
return ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void acceleratorFreeShared(void *ptr){ free(ptr);};
|
inline void acceleratorFreeShared(void *ptr){ hipFree(ptr);};
|
||||||
inline void acceleratorFreeDevice(void *ptr){ hipFree(ptr);};
|
inline void acceleratorFreeDevice(void *ptr){ hipFree(ptr);};
|
||||||
inline void acceleratorCopyToDevice(void *from,void *to,size_t bytes) { hipMemcpy(to,from,bytes, hipMemcpyHostToDevice);}
|
inline void acceleratorCopyToDevice(void *from,void *to,size_t bytes) { hipMemcpy(to,from,bytes, hipMemcpyHostToDevice);}
|
||||||
inline void acceleratorCopyFromDevice(void *from,void *to,size_t bytes){ hipMemcpy(to,from,bytes, hipMemcpyDeviceToHost);}
|
inline void acceleratorCopyFromDevice(void *from,void *to,size_t bytes){ hipMemcpy(to,from,bytes, hipMemcpyDeviceToHost);}
|
||||||
|
106
tests/core/Test_unary.cc
Normal file
106
tests/core/Test_unary.cc
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
|
Source file: ./tests/Test_quenched_update.cc
|
||||||
|
|
||||||
|
Copyright (C) 2015
|
||||||
|
|
||||||
|
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
||||||
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
|
*************************************************************************************/
|
||||||
|
/* END LEGAL */
|
||||||
|
#include <Grid/Grid.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
;
|
||||||
|
|
||||||
|
int main (int argc, char ** argv)
|
||||||
|
{
|
||||||
|
Grid_init(&argc,&argv);
|
||||||
|
|
||||||
|
std::vector<int> latt({8,8,8,8});
|
||||||
|
GridCartesian * grid = SpaceTimeGrid::makeFourDimGrid(latt,
|
||||||
|
GridDefaultSimd(Nd,vComplexD::Nsimd()),
|
||||||
|
GridDefaultMpi());
|
||||||
|
|
||||||
|
GridCartesian * gridF = SpaceTimeGrid::makeFourDimGrid(latt,
|
||||||
|
GridDefaultSimd(Nd,vComplexF::Nsimd()),
|
||||||
|
GridDefaultMpi());
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
// Configuration of known size
|
||||||
|
///////////////////////////////
|
||||||
|
LatticeColourMatrixD ident(grid);
|
||||||
|
LatticeColourMatrixD U(grid);
|
||||||
|
LatticeColourMatrixD tmp(grid);
|
||||||
|
LatticeColourMatrixD org(grid);
|
||||||
|
LatticeColourMatrixF UF(gridF);
|
||||||
|
|
||||||
|
LatticeGaugeField Umu(grid);
|
||||||
|
|
||||||
|
ident =1.0;
|
||||||
|
|
||||||
|
// RNG set up for test
|
||||||
|
std::vector<int> pseeds({1,2,3,4,5}); // once I caught a fish alive
|
||||||
|
std::vector<int> sseeds({6,7,8,9,10});// then i let it go again
|
||||||
|
GridParallelRNG pRNG(grid); pRNG.SeedFixedIntegers(pseeds);
|
||||||
|
GridSerialRNG sRNG; sRNG.SeedFixedIntegers(sseeds);
|
||||||
|
|
||||||
|
SU<Nc>::HotConfiguration(pRNG,Umu);
|
||||||
|
|
||||||
|
U = PeekIndex<LorentzIndex>(Umu,0);
|
||||||
|
org=U;
|
||||||
|
|
||||||
|
|
||||||
|
tmp= U*adj(U) - ident ;
|
||||||
|
RealD Def1 = norm2( tmp );
|
||||||
|
std::cout << " Defect1 "<<Def1<<std::endl;
|
||||||
|
|
||||||
|
tmp = U - org;
|
||||||
|
std::cout << "Diff1 "<<norm2(tmp)<<std::endl;
|
||||||
|
precisionChange(UF,U);
|
||||||
|
precisionChange(U,UF);
|
||||||
|
|
||||||
|
tmp= U*adj(U) - ident ;
|
||||||
|
RealD Def2 = norm2( tmp );
|
||||||
|
std::cout << " Defect2 "<<Def2<<std::endl;
|
||||||
|
|
||||||
|
tmp = U - org;
|
||||||
|
std::cout << "Diff2 "<<norm2(tmp)<<std::endl;
|
||||||
|
|
||||||
|
U = ProjectOnGroup(U);
|
||||||
|
|
||||||
|
tmp= U*adj(U) - ident ;
|
||||||
|
RealD Def3 = norm2( tmp);
|
||||||
|
std::cout << " Defect3 "<<Def3<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
tmp = U - org;
|
||||||
|
std::cout << "Diff3 "<<norm2(tmp)<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
Grid_finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user