mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
maxLocalNorm2()
This commit is contained in:
parent
69f1f04f74
commit
cd99edcc5f
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
@ -108,6 +107,8 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Reduction
|
// Reduction
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
void GlobalMax(RealD &);
|
||||||
|
void GlobalMax(RealF &);
|
||||||
void GlobalSum(RealF &);
|
void GlobalSum(RealF &);
|
||||||
void GlobalSumVector(RealF *,int N);
|
void GlobalSumVector(RealF *,int N);
|
||||||
void GlobalSum(RealD &);
|
void GlobalSum(RealD &);
|
||||||
|
@ -275,6 +275,16 @@ void CartesianCommunicator::GlobalXOR(uint64_t &u){
|
|||||||
int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT64_T,MPI_BXOR,communicator);
|
int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT64_T,MPI_BXOR,communicator);
|
||||||
assert(ierr==0);
|
assert(ierr==0);
|
||||||
}
|
}
|
||||||
|
void CartesianCommunicator::GlobalMax(float &f)
|
||||||
|
{
|
||||||
|
int ierr=MPI_Allreduce(MPI_IN_PLACE,&f,1,MPI_FLOAT,MPI_MAX,communicator);
|
||||||
|
assert(ierr==0);
|
||||||
|
}
|
||||||
|
void CartesianCommunicator::GlobalMax(double &d)
|
||||||
|
{
|
||||||
|
int ierr = MPI_Allreduce(MPI_IN_PLACE,&d,1,MPI_DOUBLE,MPI_MAX,communicator);
|
||||||
|
assert(ierr==0);
|
||||||
|
}
|
||||||
void CartesianCommunicator::GlobalSum(float &f){
|
void CartesianCommunicator::GlobalSum(float &f){
|
||||||
int ierr=MPI_Allreduce(MPI_IN_PLACE,&f,1,MPI_FLOAT,MPI_SUM,communicator);
|
int ierr=MPI_Allreduce(MPI_IN_PLACE,&f,1,MPI_FLOAT,MPI_SUM,communicator);
|
||||||
assert(ierr==0);
|
assert(ierr==0);
|
||||||
|
@ -67,6 +67,8 @@ CartesianCommunicator::CartesianCommunicator(const Coordinate &processors)
|
|||||||
|
|
||||||
CartesianCommunicator::~CartesianCommunicator(){}
|
CartesianCommunicator::~CartesianCommunicator(){}
|
||||||
|
|
||||||
|
void CartesianCommunicator::GlobalMax(float &){}
|
||||||
|
void CartesianCommunicator::GlobalMax(double &){}
|
||||||
void CartesianCommunicator::GlobalSum(float &){}
|
void CartesianCommunicator::GlobalSum(float &){}
|
||||||
void CartesianCommunicator::GlobalSumVector(float *,int N){}
|
void CartesianCommunicator::GlobalSumVector(float *,int N){}
|
||||||
void CartesianCommunicator::GlobalSum(double &){}
|
void CartesianCommunicator::GlobalSum(double &){}
|
||||||
|
@ -96,8 +96,34 @@ inline typename vobj::scalar_objectD sumD_cpu(const vobj *arg, Integer osites)
|
|||||||
ssobj ret = ssum;
|
ssobj ret = ssum;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
Threaded max, don't use for now
|
||||||
|
template<class Double>
|
||||||
|
inline Double max(const Double *arg, Integer osites)
|
||||||
|
{
|
||||||
|
// const int Nsimd = vobj::Nsimd();
|
||||||
|
const int nthread = GridThread::GetThreads();
|
||||||
|
|
||||||
|
std::vector<Double> maxarray(nthread);
|
||||||
|
|
||||||
|
thread_for(thr,nthread, {
|
||||||
|
int nwork, mywork, myoff;
|
||||||
|
nwork = osites;
|
||||||
|
GridThread::GetWork(nwork,thr,mywork,myoff);
|
||||||
|
Double max=arg[0];
|
||||||
|
for(int ss=myoff;ss<mywork+myoff; ss++){
|
||||||
|
if( arg[ss] > max ) max = arg[ss];
|
||||||
|
}
|
||||||
|
maxarray[thr]=max;
|
||||||
|
});
|
||||||
|
|
||||||
|
Double tmax=maxarray[0];
|
||||||
|
for(int i=0;i<nthread;i++){
|
||||||
|
if (maxarray[i]>tmax) tmax = maxarray[i];
|
||||||
|
}
|
||||||
|
return tmax;
|
||||||
|
}
|
||||||
|
*/
|
||||||
template<class vobj>
|
template<class vobj>
|
||||||
inline typename vobj::scalar_object sum(const vobj *arg, Integer osites)
|
inline typename vobj::scalar_object sum(const vobj *arg, Integer osites)
|
||||||
{
|
{
|
||||||
@ -140,6 +166,31 @@ template<class vobj> inline RealD norm2(const Lattice<vobj> &arg){
|
|||||||
ComplexD nrm = innerProduct(arg,arg);
|
ComplexD nrm = innerProduct(arg,arg);
|
||||||
return real(nrm);
|
return real(nrm);
|
||||||
}
|
}
|
||||||
|
template<class vobj> inline RealD maxLocalNorm2(const Lattice<vobj> &arg)
|
||||||
|
{
|
||||||
|
typedef typename vobj::tensor_reduced vscalar;
|
||||||
|
typedef typename vobj::scalar_object scalar;
|
||||||
|
typedef typename getPrecision<vobj>::real_scalar_type rscalar;
|
||||||
|
|
||||||
|
Lattice<vscalar> inner = localNorm2(arg);
|
||||||
|
|
||||||
|
auto grid = arg.Grid();
|
||||||
|
|
||||||
|
RealD max;
|
||||||
|
for(int l=0;l<grid->lSites();l++){
|
||||||
|
Coordinate coor;
|
||||||
|
scalar val;
|
||||||
|
RealD r;
|
||||||
|
grid->LocalIndexToLocalCoor(l,coor);
|
||||||
|
peekLocalSite(val,inner,coor);
|
||||||
|
r=real(TensorRemove(val));
|
||||||
|
if( (l==0) || (r>max)){
|
||||||
|
max=r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
grid->GlobalMax(max);
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
// Double inner product
|
// Double inner product
|
||||||
template<class vobj>
|
template<class vobj>
|
||||||
|
@ -231,6 +231,19 @@ int main(int argc, char **argv) {
|
|||||||
scalar = localInnerProduct(cVec, cVec);
|
scalar = localInnerProduct(cVec, cVec);
|
||||||
scalar = localNorm2(cVec);
|
scalar = localNorm2(cVec);
|
||||||
|
|
||||||
|
std::cout << "Testing maxLocalNorm2" <<std::endl;
|
||||||
|
for(Integer gsite=0;gsite<Fine.gSites();gsite++){
|
||||||
|
|
||||||
|
TComplex big(10.0);
|
||||||
|
Coordinate coor;
|
||||||
|
|
||||||
|
random(FineRNG, scalar);
|
||||||
|
Fine.GlobalIndexToGlobalCoor(gsite,coor);
|
||||||
|
pokeSite(big,scalar,coor);
|
||||||
|
|
||||||
|
RealD Linfty = maxLocalNorm2(scalar);
|
||||||
|
assert(Linfty == 100.0);
|
||||||
|
}
|
||||||
// -=,+=,*=,()
|
// -=,+=,*=,()
|
||||||
// add,+,sub,-,mult,mac,*
|
// add,+,sub,-,mult,mac,*
|
||||||
// adj,conjugate
|
// adj,conjugate
|
||||||
@ -549,7 +562,8 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::vector<int> shiftcoor = coor;
|
std::vector<int> shiftcoor = coor;
|
||||||
shiftcoor[dir] = (shiftcoor[dir] + shift + latt_size[dir]) %
|
shiftcoor[dir] = (shiftcoor[dir] + shift + latt_size[dir]) %
|
||||||
(latt_size[dir] / mpi_layout[dir]);
|
(latt_size[dir]);
|
||||||
|
// (latt_size[dir] / mpi_layout[dir]);
|
||||||
|
|
||||||
std::vector<int> rl(4);
|
std::vector<int> rl(4);
|
||||||
for (int dd = 0; dd < 4; dd++) {
|
for (int dd = 0; dd < 4; dd++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user