Grid 0.7.0
HMC_GridModules.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/hmc/HMC_GridModules.h
6
7Copyright (C) 2015
8Copyright (C) 2016
9
10Author: Guido Cossu <guido.cossu@ed.ac.uk>
11
12This program is free software; you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation; either version 2 of the License, or
15(at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License along
23with this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26See the full license in the file "LICENSE" in the top level distribution
27directory
28*************************************************************************************/
29 /* END LEGAL */
30#ifndef HMC_GRID_MODULES
31#define HMC_GRID_MODULES
32
34
35// Resources
36// Modules for grids
37
38// Introduce another namespace HMCModules?
39
40class GridModuleParameters: Serializable{
41public:
43 std::string, lattice,
44 std::string, mpi);
45
46 std::vector<int> getLattice() const {return strToVec<int>(lattice);}
47 std::vector<int> getMpi() const {return strToVec<int>(mpi);}
48
49
50 void check() const {
51 if (getLattice().size() != getMpi().size() ) {
52 std::cout << GridLogError
53 << "Error in GridModuleParameters: lattice and mpi dimensions "
54 "do not match"
55 << std::endl;
56 exit(1);
57 }
58 }
59
60 template <class ReaderClass>
61 GridModuleParameters(Reader<ReaderClass>& Reader, std::string n = "LatticeGrid"):name(n) {
62 read(Reader, name, *this);
63 check();
64 }
65
66 // Save on file
67 template< class WriterClass>
68 void save(Writer<WriterClass>& Writer){
69 check();
70 write(Writer, name, *this);
71 }
72private:
73 std::string name;
74};
75
76// Lower level class
78public:
80 std::cout << GridLogDebug << "Getting cartesian in module"<< std::endl;
81 return grid_.get(); }
83 std::cout << GridLogDebug << "Getting rb-cartesian in module"<< std::endl;
84 return rbgrid_.get(); }
85
86 void set_full(GridCartesian* grid) { grid_.reset(grid); }
87 void set_rb(GridRedBlackCartesian* rbgrid) { rbgrid_.reset(rbgrid); }
88 void show_full_decomposition(){ grid_->show_decomposition(); }
89 void show_rb_decomposition(){ rbgrid_->show_decomposition(); }
90
91protected:
92 std::unique_ptr<GridCartesian> grid_;
93 std::unique_ptr<GridRedBlackCartesian> rbgrid_;
94
95};
96
98// Classes for the user
100template <class vector_type>
102{
103public:
112
113 GridFourDimModule(const std::vector<int> tweak_simd)
114 {
115 Coordinate _tweak_simd(tweak_simd);
116 if (tweak_simd.size() != 4)
117 {
118 std::cout << GridLogError
119 << "Error in GridFourDimModule: SIMD size different from 4"
120 << std::endl;
121 exit(1);
122 }
123
124 // Checks that the product agrees with the expectation
125 int simd_sum = 1;
126 for (auto &n : tweak_simd)
127 simd_sum *= n;
128 std::cout << GridLogDebug << "TweakSIMD: " << tweak_simd << " Sum: " << simd_sum << std::endl;
129
130 if (simd_sum == vector_type::Nsimd())
131 {
134 _tweak_simd,
135 GridDefaultMpi()));
137 }
138 else
139 {
140 std::cout << GridLogError
141 << "Error in GridFourDimModule: SIMD lanes must sum to "
142 << vector_type::Nsimd()
143 << std::endl;
144 }
145 }
146
148 {
149 std::vector<int> lattice_v = Params.getLattice();
150 std::vector<int> mpi_v = Params.getMpi();
151 if (lattice_v.size() == 4)
152 {
154 lattice_v,
155 GridDefaultSimd(4, vector_type::Nsimd()),
156 mpi_v));
158 }
159 else
160 {
161 std::cout << GridLogError
162 << "Error in GridFourDimModule: lattice dimension different from 4"
163 << std::endl;
164 exit(1);
165 }
166 }
167};
168
170
171
173
174#endif // HMC_GRID_MODULES
AcceleratorVector< int, MaxDims > Coordinate
Definition Coordinate.h:95
GridFourDimModule< vComplex > GridDefaultFourDimModule
const Coordinate GridDefaultSimd(int dims, int nsimd)
Definition Init.cc:109
const Coordinate & GridDefaultLatt(void)
Definition Init.cc:107
const Coordinate & GridDefaultMpi(void)
Definition Init.cc:108
GridLogger GridLogError(1, "Error", GridLogColours, "RED")
GridLogger GridLogDebug(1, "Debug", GridLogColours, "PURPLE")
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
GridFourDimModule(const std::vector< int > tweak_simd)
GridFourDimModule(const GridModuleParameters Params)
GRID_SERIALIZABLE_CLASS_MEMBERS(GridModuleParameters, std::string, lattice, std::string, mpi)
std::vector< int > getLattice() const
GridModuleParameters(Reader< ReaderClass > &Reader, std::string n="LatticeGrid")
std::vector< int > getMpi() const
void save(Writer< WriterClass > &Writer)
void set_full(GridCartesian *grid)
void show_full_decomposition()
void set_rb(GridRedBlackCartesian *rbgrid)
void show_rb_decomposition()
std::unique_ptr< GridRedBlackCartesian > rbgrid_
GridRedBlackCartesian * get_rb()
GridCartesian * get_full()
std::unique_ptr< GridCartesian > grid_
static GridRedBlackCartesian * makeFourDimRedBlackGrid(const GridCartesian *FourDimGrid)
static GridCartesian * makeFourDimGrid(const Coordinate &latt, const Coordinate &simd, const Coordinate &mpi)