QUDA v0.3.2
A library for QCD on GPUs

quda/lib/color_spinor_field.cpp

Go to the documentation of this file.
00001 #include <color_spinor_field.h>
00002 #include <string.h>
00003 #include <iostream>
00004 
00005 /*ColorSpinorField::ColorSpinorField() : init(false) {
00006 
00007 }*/
00008 
00009 ColorSpinorField::ColorSpinorField(const ColorSpinorParam &param) : init(false), even(0), odd(0) {
00010   create(param.nDim, param.x, param.nColor, param.nSpin, param.twistFlavor, param.precision, param.pad, 
00011          param.fieldLocation, param.siteSubset, param.siteOrder, param.fieldOrder, 
00012          param.gammaBasis);
00013 }
00014 
00015 ColorSpinorField::ColorSpinorField(const ColorSpinorField &field) : init(false), even(0), odd(0) {
00016   create(field.nDim, field.x, field.nColor, field.nSpin, field.twistFlavor, field.precision, field.pad,
00017          field.fieldLocation, field.siteSubset, field.siteOrder, field.fieldOrder, 
00018          field.gammaBasis);
00019 }
00020 
00021 ColorSpinorField::~ColorSpinorField() {
00022   destroy();
00023 }
00024 
00025 void ColorSpinorField::create(int Ndim, const int *X, int Nc, int Ns, QudaTwistFlavorType Twistflavor, 
00026                               QudaPrecision Prec, int Pad, QudaFieldLocation fieldLocation, 
00027                               QudaSiteSubset siteSubset, QudaSiteOrder siteOrder, 
00028                               QudaFieldOrder fieldOrder, QudaGammaBasis gammaBasis) {
00029   if (Ndim > QUDA_MAX_DIM){
00030     errorQuda("Number of dimensions nDim = %d too great", Ndim);
00031   }
00032   nDim = Ndim;
00033   nColor = Nc;
00034   nSpin = Ns;
00035   twistFlavor = Twistflavor;
00036 
00037   precision = Prec;
00038   volume = 1;
00039   for (int d=0; d<nDim; d++) {
00040     x[d] = X[d];
00041     volume *= x[d];
00042   }
00043   pad = Pad;
00044   
00045   if (siteSubset == QUDA_FULL_SITE_SUBSET) {
00046     stride = volume/2 + pad; // padding is based on half volume
00047     length = 2*stride*nColor*nSpin*2;    
00048   } else {
00049     stride = volume + pad;
00050     length = stride*nColor*nSpin*2;
00051   }
00052 
00053   real_length = volume*nColor*nSpin*2;
00054 
00055   bytes = length * precision;
00056 
00057   this->fieldLocation = fieldLocation;
00058   this->siteSubset = siteSubset;
00059   this->siteOrder = siteOrder;
00060   this->fieldOrder = fieldOrder;
00061   this->gammaBasis = gammaBasis;
00062 
00063   init = true;
00064 }
00065 
00066 void ColorSpinorField::destroy() {
00067   init = false;
00068 }
00069 
00070 ColorSpinorField& ColorSpinorField::operator=(const ColorSpinorField &src) {
00071   if (&src != this) {
00072     create(src.nDim, src.x, src.nColor, src.nSpin, src.twistFlavor, 
00073            src.precision, src.pad, src.fieldLocation, src.siteSubset, 
00074            src.siteOrder, src.fieldOrder, src.gammaBasis);    
00075   }
00076   return *this;
00077 }
00078 
00079 // Resets the attributes of this field if param disagrees (and is defined)
00080 void ColorSpinorField::reset(const ColorSpinorParam &param) {
00081 
00082   if (param.nColor != 0) nColor = param.nColor;
00083   if (param.nSpin != 0) nSpin = param.nSpin;
00084   if (param.twistFlavor != QUDA_TWIST_INVALID) twistFlavor = param.twistFlavor;
00085 
00086   if (param.precision != QUDA_INVALID_PRECISION)  precision = param.precision;
00087   if (param.nDim != 0) nDim = param.nDim;
00088 
00089   volume = 1;
00090   for (int d=0; d<nDim; d++) {
00091     if (param.x[0] != 0) x[d] = param.x[d];
00092     volume *= x[d];
00093   }
00094   
00095   if (param.pad != 0) pad = param.pad;
00096 
00097   if (param.siteSubset == QUDA_FULL_SITE_SUBSET){
00098     stride = volume/2 + pad;
00099     length = 2*stride*nColor*nSpin*2;
00100   } else if (param.siteSubset == QUDA_PARITY_SITE_SUBSET){
00101     stride = volume + pad;
00102     length = stride*nColor*nSpin*2;  
00103   } else {
00104     //errorQuda("SiteSubset not defined %d", param.siteSubset);
00105     //do nothing, not an error
00106   }
00107 
00108   real_length = volume*nColor*nSpin*2;
00109 
00110   bytes = length * precision;
00111 
00112   if (param.fieldLocation != QUDA_INVALID_FIELD_LOCATION) fieldLocation = param.fieldLocation;
00113   if (param.siteSubset != QUDA_INVALID_SITE_SUBSET) siteSubset = param.siteSubset;
00114   if (param.siteOrder != QUDA_INVALID_SITE_ORDER) siteOrder = param.siteOrder;
00115   if (param.fieldOrder != QUDA_INVALID_FIELD_ORDER) fieldOrder = param.fieldOrder;
00116   if (param.gammaBasis != QUDA_INVALID_GAMMA_BASIS) gammaBasis = param.gammaBasis;
00117 
00118   if (!init) errorQuda("Shouldn't be resetting a non-inited field\n");
00119 }
00120 
00121 // Fills the param with the contents of this field
00122 void ColorSpinorField::fill(ColorSpinorParam &param) {
00123   param.nColor = nColor;
00124   param.nSpin = nSpin;
00125   param.twistFlavor = twistFlavor;
00126   param.precision = precision;
00127   param.nDim = nDim;
00128   memcpy(param.x, x, QUDA_MAX_DIM*sizeof(int));
00129   param.pad = pad;
00130   param.fieldLocation = fieldLocation;
00131   param.siteSubset = siteSubset;
00132   param.siteOrder = siteOrder;
00133   param.fieldOrder = fieldOrder;
00134   param.gammaBasis = gammaBasis;
00135   param.create = QUDA_INVALID_FIELD_CREATE;
00136 }
00137 
00138 // For kernels with precision conversion built in
00139 void ColorSpinorField::checkField(const ColorSpinorField &a, const ColorSpinorField &b) {
00140   if (a.Length() != b.Length()) {
00141     errorQuda("checkSpinor: lengths do not match: %d %d", a.Length(), b.Length());
00142   }
00143 
00144   if (a.Ncolor() != b.Ncolor()) {
00145     errorQuda("checkSpinor: colors do not match: %d %d", a.Ncolor(), b.Ncolor());
00146   }
00147 
00148   if (a.Nspin() != b.Nspin()) {
00149     errorQuda("checkSpinor: spins do not match: %d %d", a.Nspin(), b.Nspin());
00150   }
00151 
00152   if (a.TwistFlavor() != b.TwistFlavor()) {
00153     errorQuda("checkSpinor: twist flavors do not match: %d %d", a.TwistFlavor(), b.TwistFlavor());
00154   }
00155 }
00156 
00157 double norm2(const ColorSpinorField &a) {
00158 
00159   if (a.FieldLocation() == QUDA_CUDA_FIELD_LOCATION) {
00160     return normCuda(dynamic_cast<const cudaColorSpinorField&>(a));
00161   } else if (a.FieldLocation() == QUDA_CPU_FIELD_LOCATION) {
00162     return normCpu(dynamic_cast<const cpuColorSpinorField&>(a));
00163   } else {
00164     errorQuda("Field type %d not supported", a.FieldLocation());
00165   }
00166 
00167 }
00168 
00169 std::ostream& operator<<(std::ostream &out, const ColorSpinorField &a) {
00170   out << "fieldLocation = " << a.fieldLocation << std::endl;
00171   out << "nColor = " << a.nColor << std::endl;
00172   out << "nSpin = " << a.nSpin << std::endl;
00173   out << "twistFlavor = " << a.twistFlavor << std::endl;
00174   out << "nDim = " << a.nDim << std::endl;
00175   for (int d=0; d<a.nDim; d++) out << "x[" << d << "] = " << a.x[d] << std::endl;
00176   out << "precision = " << a.precision << std::endl;
00177   out << "pad = " << a.pad << std::endl;
00178   out << "siteSubset = " << a.siteSubset << std::endl;
00179   out << "siteOrder = " << a.siteOrder << std::endl;
00180   out << "fieldOrder = " << a.fieldOrder << std::endl;
00181   out << "gammaBasis = " << a.gammaBasis << std::endl;
00182   return out;
00183 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines