2019-04-26 07:24:56 +01:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
2019-04-26 08:23:15 +01:00
|
|
|
Source file: Hadrons/Modules/MDistil/Perambulator.hpp
|
2019-04-26 07:24:56 +01:00
|
|
|
|
2019-04-26 07:39:05 +01:00
|
|
|
Copyright (C) 2019
|
2019-04-26 07:24:56 +01:00
|
|
|
|
|
|
|
Author: Felix Erben <ferben@ed.ac.uk>
|
|
|
|
Author: Michael Marshall <Michael.Marshall@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 */
|
|
|
|
|
2019-04-26 08:23:15 +01:00
|
|
|
#ifndef Hadrons_MDistil_Perambulator_hpp_
|
|
|
|
#define Hadrons_MDistil_Perambulator_hpp_
|
2019-01-18 13:14:28 +00:00
|
|
|
|
2019-11-12 17:31:42 +00:00
|
|
|
#include <Hadrons/Modules/MDistil/Distil.hpp>
|
2019-01-18 13:14:28 +00:00
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
2019-11-01 20:10:51 +00:00
|
|
|
BEGIN_MODULE_NAMESPACE(MDistil)
|
2019-01-22 15:06:45 +00:00
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
/******************************************************************************
|
2019-04-26 08:23:15 +01:00
|
|
|
* Perambulator *
|
2019-01-18 13:14:28 +00:00
|
|
|
******************************************************************************/
|
2019-01-31 12:24:32 +00:00
|
|
|
|
2019-04-26 08:23:15 +01:00
|
|
|
class PerambulatorPar: Serializable
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-04-26 08:23:15 +01:00
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(PerambulatorPar,
|
2019-04-30 23:53:57 +01:00
|
|
|
std::string, lapevec,
|
|
|
|
std::string, solver,
|
2019-11-01 15:35:07 +00:00
|
|
|
std::string, noise,
|
|
|
|
std::string, PerambFileName,
|
|
|
|
std::string, UnsmearedSinkFileName,
|
2019-11-12 21:53:09 +00:00
|
|
|
std::string, DistilParams);
|
2019-01-18 13:14:28 +00:00
|
|
|
};
|
|
|
|
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
class TPerambulator: public Module<PerambulatorPar>
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-11-01 15:35:07 +00:00
|
|
|
FERM_TYPE_ALIASES(FImpl,);
|
|
|
|
SOLVER_TYPE_ALIASES(FImpl,);
|
|
|
|
// constructor
|
|
|
|
TPerambulator(const std::string name);
|
|
|
|
// destructor
|
2019-11-12 23:18:37 +00:00
|
|
|
virtual ~TPerambulator(void) {};
|
2019-11-01 15:35:07 +00:00
|
|
|
// dependency relation
|
|
|
|
virtual std::vector<std::string> getInput(void);
|
|
|
|
virtual std::vector<std::string> getOutput(void);
|
|
|
|
// setup
|
|
|
|
virtual void setup(void);
|
|
|
|
// execution
|
|
|
|
virtual void execute(void);
|
2019-01-30 21:16:09 +00:00
|
|
|
protected:
|
2019-11-12 21:53:09 +00:00
|
|
|
std::unique_ptr<GridCartesian> grid3d; // Owned by me, so I must delete it
|
2019-11-01 15:35:07 +00:00
|
|
|
unsigned int Ls_;
|
2019-01-18 13:14:28 +00:00
|
|
|
};
|
|
|
|
|
2019-05-01 13:04:51 +01:00
|
|
|
MODULE_REGISTER_TMP(Perambulator, TPerambulator<FIMPL>, MDistil);
|
2019-01-18 13:14:28 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
2019-04-26 08:23:15 +01:00
|
|
|
* TPerambulator implementation *
|
2019-01-18 13:14:28 +00:00
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-11-12 21:53:09 +00:00
|
|
|
TPerambulator<FImpl>::TPerambulator(const std::string name) : Module<PerambulatorPar>(name) {}
|
2019-01-30 21:16:09 +00:00
|
|
|
|
2019-01-18 13:14:28 +00:00
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
std::vector<std::string> TPerambulator<FImpl>::getInput(void)
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
2019-11-12 21:53:09 +00:00
|
|
|
return {par().lapevec, par().solver, par().noise, par().DistilParams};
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
std::vector<std::string> TPerambulator<FImpl>::getOutput(void)
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
2019-11-01 15:35:07 +00:00
|
|
|
return {getName(), getName() + "_unsmeared_sink"};
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
void TPerambulator<FImpl>::setup(void)
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
2019-11-12 21:53:09 +00:00
|
|
|
grid3d.reset( MakeLowerDimGrid( env().getGrid() ) );
|
|
|
|
const DistilParameters &dp = envGet(DistilParameters, par().DistilParams);
|
2019-11-12 13:59:53 +00:00
|
|
|
const int Nt{env().getDim(Tdir)};
|
|
|
|
const bool full_tdil{ dp.TI == Nt };
|
|
|
|
const int Nt_inv{ full_tdil ? 1 : dp.TI };
|
|
|
|
|
|
|
|
envCreate(PerambTensor, getName(), 1, Nt, dp.nvec, dp.LI, dp.nnoise, Nt_inv, dp.SI);
|
2019-11-01 15:35:07 +00:00
|
|
|
envCreate(std::vector<FermionField>, getName() + "_unsmeared_sink", 1,
|
2019-11-12 13:59:53 +00:00
|
|
|
dp.nnoise*dp.LI*Ns*Nt_inv, envGetGrid(FermionField));
|
2019-11-01 15:35:07 +00:00
|
|
|
|
2019-11-11 17:29:55 +00:00
|
|
|
envTmpLat(LatticeSpinColourVector, "dist_source");
|
|
|
|
envTmpLat(LatticeSpinColourVector, "source4d");
|
2019-11-12 21:53:09 +00:00
|
|
|
envTmp(LatticeSpinColourVector, "source3d",1,LatticeSpinColourVector(grid3d.get()));
|
|
|
|
envTmp(LatticeColourVector, "source3d_nospin",1,LatticeColourVector(grid3d.get()));
|
2019-11-11 17:29:55 +00:00
|
|
|
envTmpLat(LatticeSpinColourVector, "result4d");
|
|
|
|
envTmpLat(LatticeColourVector, "result4d_nospin");
|
2019-11-12 21:53:09 +00:00
|
|
|
envTmp(LatticeColourVector, "result3d_nospin",1,LatticeColourVector(grid3d.get()));
|
|
|
|
envTmp(LatticeColourVector, "evec3d",1,LatticeColourVector(grid3d.get()));
|
2019-11-01 15:35:07 +00:00
|
|
|
|
|
|
|
Ls_ = env().getObjectLs(par().solver);
|
|
|
|
envTmpLat(FermionField, "v4dtmp");
|
|
|
|
envTmpLat(FermionField, "v5dtmp", Ls_);
|
|
|
|
envTmpLat(FermionField, "v5dtmp_sol", Ls_);
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
2019-02-01 13:23:42 +00:00
|
|
|
template <typename FImpl>
|
2019-04-26 08:23:15 +01:00
|
|
|
void TPerambulator<FImpl>::execute(void)
|
2019-01-18 13:14:28 +00:00
|
|
|
{
|
2019-11-13 11:21:08 +00:00
|
|
|
const DistilParameters &dp{ envGet(DistilParameters, par().DistilParams) };
|
2019-11-12 13:59:53 +00:00
|
|
|
const int Nt{env().getDim(Tdir)};
|
2019-11-13 11:21:08 +00:00
|
|
|
const int nvec{dp.nvec};
|
|
|
|
const int nnoise{dp.nnoise};
|
|
|
|
const int tsrc{dp.tsrc};
|
|
|
|
const int TI{dp.TI};
|
|
|
|
const int LI{dp.LI};
|
|
|
|
const int SI{dp.SI};
|
2019-11-11 17:29:55 +00:00
|
|
|
const bool full_tdil{ TI == Nt };
|
|
|
|
const int Nt_inv{ full_tdil ? 1 : TI };
|
|
|
|
|
2019-03-08 16:28:21 +00:00
|
|
|
auto &solver=envGet(Solver, par().solver);
|
|
|
|
auto &mat = solver.getFMat();
|
|
|
|
envGetTmp(FermionField, v4dtmp);
|
|
|
|
envGetTmp(FermionField, v5dtmp);
|
|
|
|
envGetTmp(FermionField, v5dtmp_sol);
|
2019-11-12 13:59:53 +00:00
|
|
|
auto &noise = envGet(NoiseTensor, par().noise);
|
2019-05-01 13:04:51 +01:00
|
|
|
auto &perambulator = envGet(PerambTensor, getName());
|
2019-11-12 13:59:53 +00:00
|
|
|
auto &epack = envGet(LapEvecs, par().lapevec);
|
2019-04-19 13:54:25 +01:00
|
|
|
auto &unsmeared_sink = envGet(std::vector<FermionField>, getName() + "_unsmeared_sink");
|
2019-11-01 15:35:07 +00:00
|
|
|
envGetTmp(LatticeSpinColourVector, dist_source);
|
2019-11-11 17:29:55 +00:00
|
|
|
envGetTmp(LatticeSpinColourVector, source4d);
|
|
|
|
envGetTmp(LatticeSpinColourVector, source3d);
|
|
|
|
envGetTmp(LatticeColourVector, source3d_nospin);
|
|
|
|
envGetTmp(LatticeSpinColourVector, result4d);
|
|
|
|
envGetTmp(LatticeColourVector, result4d_nospin);
|
|
|
|
envGetTmp(LatticeColourVector, result3d_nospin);
|
2019-11-01 15:35:07 +00:00
|
|
|
envGetTmp(LatticeColourVector, evec3d);
|
2019-11-12 21:53:09 +00:00
|
|
|
GridCartesian * const grid4d{ env().getGrid() }; // Owned by environment (so I won't delete it)
|
2019-01-31 12:24:32 +00:00
|
|
|
const int Ntlocal{grid4d->LocalDimensions()[3]};
|
|
|
|
const int Ntfirst{grid4d->LocalStarts()[3]};
|
2019-11-01 15:35:07 +00:00
|
|
|
const std::string UnsmearedSinkFileName{ par().UnsmearedSinkFileName };
|
2019-11-02 16:15:48 +00:00
|
|
|
|
|
|
|
for (int inoise = 0; inoise < nnoise; inoise++)
|
2019-01-31 12:24:32 +00:00
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
for (int dk = 0; dk < LI; dk++)
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
for (int dt = 0; dt < Nt_inv; dt++)
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
for (int ds = 0; ds < SI; ds++)
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
LOG(Message) << "LapH source vector from noise " << inoise << " and dilution component (d_k,d_t,d_alpha) : (" << dk << ","<< dt << "," << ds << ")" << std::endl;
|
|
|
|
dist_source = 0;
|
2019-11-11 17:29:55 +00:00
|
|
|
source3d_nospin = 0;
|
2019-11-02 16:15:48 +00:00
|
|
|
evec3d = 0;
|
|
|
|
for (int it = dt; it < Nt; it += TI)
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
const int t_inv{full_tdil ? tsrc : it};
|
|
|
|
if( t_inv >= Ntfirst && t_inv < Ntfirst + Ntlocal )
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
for (int ik = dk; ik < nvec; ik += LI)
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
for (int is = ds; is < Ns; is += SI)
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
ExtractSliceLocal(evec3d,epack.evec[ik],0,t_inv-Ntfirst,Tdir);
|
2019-11-11 17:29:55 +00:00
|
|
|
source3d_nospin = evec3d * noise.tensor(inoise, t_inv, ik, is);
|
|
|
|
source3d=0;
|
|
|
|
pokeSpin(source3d,source3d_nospin,is);
|
|
|
|
source4d=0;
|
|
|
|
InsertSliceLocal(source3d,source4d,0,t_inv-Ntfirst,Tdir);
|
|
|
|
dist_source += source4d;
|
2019-11-01 15:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-02 16:15:48 +00:00
|
|
|
}
|
2019-11-11 17:29:55 +00:00
|
|
|
result4d=0;
|
2019-11-02 16:15:48 +00:00
|
|
|
v4dtmp = dist_source;
|
|
|
|
if (Ls_ == 1)
|
2019-11-11 17:29:55 +00:00
|
|
|
solver(result4d, v4dtmp);
|
2019-11-02 16:15:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mat.ImportPhysicalFermionSource(v4dtmp, v5dtmp);
|
|
|
|
solver(v5dtmp_sol, v5dtmp);
|
|
|
|
mat.ExportPhysicalFermionSolution(v5dtmp_sol, v4dtmp);
|
2019-11-11 17:29:55 +00:00
|
|
|
result4d = v4dtmp;
|
2019-11-02 16:15:48 +00:00
|
|
|
}
|
|
|
|
if (!UnsmearedSinkFileName.empty())
|
2019-11-11 17:29:55 +00:00
|
|
|
unsmeared_sink[inoise+nnoise*(dk+LI*(dt+Nt_inv*ds))] = result4d;
|
2019-11-02 16:15:48 +00:00
|
|
|
for (int is = 0; is < Ns; is++)
|
|
|
|
{
|
2019-11-11 17:29:55 +00:00
|
|
|
result4d_nospin = peekSpin(result4d,is);
|
2019-11-02 16:15:48 +00:00
|
|
|
for (int t = Ntfirst; t < Ntfirst + Ntlocal; t++)
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
2019-11-11 17:29:55 +00:00
|
|
|
ExtractSliceLocal(result3d_nospin,result4d_nospin,0,t-Ntfirst,Tdir);
|
|
|
|
for (int ivec = 0; ivec < nvec; ivec++)
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
ExtractSliceLocal(evec3d,epack.evec[ivec],0,t-Ntfirst,Tdir);
|
2019-11-11 17:29:55 +00:00
|
|
|
pokeSpin(perambulator.tensor(t, ivec, dk, inoise,dt,ds),static_cast<Complex>(innerProduct(evec3d, result3d_nospin)),is);
|
2019-11-01 15:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-18 17:47:41 +00:00
|
|
|
}
|
2019-04-28 23:24:57 +01:00
|
|
|
}
|
2019-01-18 17:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-01 20:10:51 +00:00
|
|
|
// Now share my timeslice data with other members of the grid
|
|
|
|
const int NumSlices{grid4d->_processors[Tdir] / grid3d->_processors[Tdir]};
|
|
|
|
if (NumSlices > 1)
|
|
|
|
{
|
|
|
|
LOG(Debug) << "Sharing perambulator data with other nodes" << std::endl;
|
|
|
|
const int MySlice {grid4d->_processor_coor[Tdir]};
|
|
|
|
const int SliceCount {static_cast<int>(perambulator.tensor.size()/NumSlices)};
|
|
|
|
PerambTensor::Scalar * const MyData {perambulator.tensor.data()+MySlice*SliceCount};
|
|
|
|
Coordinate coor(Nd);
|
|
|
|
for (int i = 0 ; i < Tdir ; i++) coor[i] = grid4d->_processor_coor[i];
|
|
|
|
std::vector<CommsRequest_t> reqs(0);
|
|
|
|
for (int i = 1; i < NumSlices ; i++)
|
|
|
|
{
|
|
|
|
coor[Tdir] = (MySlice+i)%NumSlices;
|
|
|
|
const int SendRank { grid4d->RankFromProcessorCoor(coor) };
|
|
|
|
const int RecvSlice { ( MySlice - i + NumSlices ) % NumSlices };
|
|
|
|
coor[Tdir] = RecvSlice;
|
|
|
|
const auto RecvRank = grid4d->RankFromProcessorCoor(coor);
|
|
|
|
grid4d->SendToRecvFromBegin(reqs,MyData,SendRank, perambulator.tensor.data()
|
|
|
|
+ RecvSlice*SliceCount,RecvRank,SliceCount*sizeof(PerambTensor::Scalar));
|
|
|
|
}
|
|
|
|
grid4d->SendToRecvFromComplete(reqs);
|
|
|
|
}
|
2019-11-01 15:35:07 +00:00
|
|
|
|
2019-11-01 20:10:51 +00:00
|
|
|
// Save the perambulator to disk from the boss node
|
|
|
|
if (grid4d->IsBoss())
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
2019-11-01 20:10:51 +00:00
|
|
|
std::string sPerambName {par().PerambFileName};
|
|
|
|
sPerambName.append(".");
|
|
|
|
sPerambName.append(std::to_string(vm().getTrajectory()));
|
2019-11-01 15:35:07 +00:00
|
|
|
perambulator.write(sPerambName.c_str());
|
|
|
|
}
|
|
|
|
|
2019-11-01 20:10:51 +00:00
|
|
|
//Save the unsmeared sinks if filename specified
|
|
|
|
if (!UnsmearedSinkFileName.empty())
|
2019-11-01 15:35:07 +00:00
|
|
|
{
|
|
|
|
LOG(Message) << "Writing unsmeared sink to " << UnsmearedSinkFileName << std::endl;
|
2019-11-12 21:53:09 +00:00
|
|
|
A2AVectorsIo::write(UnsmearedSinkFileName, unsmeared_sink, false, vm().getTrajectory());
|
2019-11-01 15:35:07 +00:00
|
|
|
}
|
2019-01-18 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
2019-04-26 08:23:15 +01:00
|
|
|
#endif // Hadrons_MDistil_Perambulator_hpp_
|