QUDA v0.4.0
A library for QCD on GPUs
quda/lib/lattice_field.cpp
Go to the documentation of this file.
00001 #include <quda_internal.h>
00002 #include <lattice_field.h>
00003 
00004 LatticeField::LatticeField(const LatticeFieldParam &param, const QudaFieldLocation &location)
00005   : volume(1), pad(param.pad), total_bytes(0), nDim(param.nDim),
00006     precision(param.precision), location(location), verbosity(param.verbosity) 
00007 {
00008   if (location == QUDA_CPU_FIELD_LOCATION) {
00009     if (precision == QUDA_HALF_PRECISION) errorQuda("CPU fields do not support half precision");
00010     if (pad != 0) errorQuda("CPU fields do not support non-zero padding");
00011   }
00012   
00013   for (int i=0; i<nDim; i++) {
00014     x[i] = param.x[i];
00015     volume *= param.x[i];
00016     surface[i] = 1;
00017     for (int j=0; j<nDim; j++) {
00018       if (i==j) continue;
00019       surface[i] *= param.x[j];
00020     }
00021   }
00022   volumeCB = volume / 2;
00023   stride = volumeCB + pad;
00024   
00025   for (int i=0; i<nDim; i++) surfaceCB[i] = surface[i] / 2;
00026 }
00027 
00028 void LatticeField::checkField(const LatticeField &a) {
00029   if (a.volume != volume) errorQuda("Volume does not match %d %d", volume, a.volume);
00030   if (a.volumeCB != volumeCB) errorQuda("VolumeCB does not match %d %d", volumeCB, a.volumeCB);
00031   if (a.nDim != nDim) errorQuda("nDim does not match %d %d", nDim, a.nDim);
00032   for (int i=0; i<nDim; i++) {
00033     if (a.x[i] != x[i]) errorQuda("x[%d] does not match %d %d", i, x[i], a.x[i]);
00034     if (a.surface[i] != surface[i]) errorQuda("surface[%d] does not match %d %d", i, surface[i], a.surface[i]);
00035     if (a.surfaceCB[i] != surfaceCB[i]) errorQuda("surfaceCB[%d] does not match %d %d", i, surfaceCB[i], a.surfaceCB[i]);  
00036   }
00037 }
00038 
00039 // This doesn't really live here, but is fine for the moment
00040 std::ostream& operator<<(std::ostream& output, const LatticeFieldParam& param)
00041 {
00042   output << "nDim = " << param.nDim << std::endl;
00043   for (int i=0; i<param.nDim; i++) {
00044     output << "x[" << i << "] = " << param.x[i] << std::endl;    
00045   }
00046   output << "pad = " << param.pad << std::endl;
00047   output << "precision = " << param.precision << std::endl;
00048 
00049   return output;  // for multiple << operators.
00050 }
00051 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines