casa
$Rev:20696$
|
00001 // -*- C++ -*- 00002 //# MultiThreadedVisResampler.h: Definition of the MultiThreadedVisibilityResampler class 00003 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003 00004 //# Associated Universities, Inc. Washington DC, USA. 00005 //# 00006 //# This library is free software; you can redistribute it and/or modify it 00007 //# under the terms of the GNU Library General Public License as published by 00008 //# the Free Software Foundation; either version 2 of the License, or (at your 00009 //# option) any later version. 00010 //# 00011 //# This library is distributed in the hope that it will be useful, but WITHOUT 00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 //# License for more details. 00015 //# 00016 //# You should have received a copy of the GNU Library General Public License 00017 //# along with this library; if not, write to the Free Software Foundation, 00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00019 //# 00020 //# Correspondence concerning AIPS++ should be addressed as follows: 00021 //# Internet email: aips2-request@nrao.edu. 00022 //# Postal address: AIPS++ Project Office 00023 //# National Radio Astronomy Observatory 00024 //# 520 Edgemont Road 00025 //# Charlottesville, VA 22903-2475 USA 00026 //# 00027 //# $Id$ 00028 00029 #ifndef SYNTHESIS_MULTITHREADEDVISIBILITYRESAMPLER_H 00030 #define SYNTHESIS_MULTITHREADEDVISIBILITYRESAMPLER_H 00031 00032 #include <synthesis/TransformMachines/VisibilityResamplerBase.h> 00033 #include <synthesis/MeasurementComponents/ResamplerWorklet.h> 00034 #include <synthesis/TransformMachines/CFStore.h> 00035 #include <synthesis/TransformMachines/VBStore.h> 00036 #include <synthesis/MeasurementComponents/MThWorkIDEnum.h> 00037 #include <synthesis/MSVis/UtilJ.h> 00038 #include <synthesis/MSVis/VisBuffer.h> 00039 #include <casa/Arrays/Array.h> 00040 #include <casa/Arrays/Vector.h> 00041 00042 #include <casa/Logging/LogIO.h> 00043 #include <casa/Logging/LogSink.h> 00044 #include <casa/Logging/LogMessage.h> 00045 #define DEFAULTNOOFCORES -1 00046 #define FTMachineNumThreadsEnvVar "ftmachine_num_threads" 00047 namespace casa { //# NAMESPACE CASA - BEGIN 00048 class MultiThreadedVisibilityResampler: public VisibilityResamplerBase 00049 { 00050 public: 00051 // enum VBLoader {NOONE=-1, DATATOGRID=0, GRIDTODATA, RESIDUALCALC}; 00052 MultiThreadedVisibilityResampler(): 00053 resamplers_p(), doubleGriddedData_p(), singleGriddedData_p(), 00054 sumwt_p(), gridderWorklets_p(), vbsVec_p(), visResamplerCtor_p(), 00055 whoLoadedVB_p(MThWorkID::NOONE), currentVBS_p(0) 00056 { 00057 nelements_p = SynthesisUtils::getenv(FTMachineNumThreadsEnvVar, 1); 00058 if (nelements_p < 0) nelements_p = 1; 00059 // nelements_p=DEFAULTNOOFCORES; 00060 }; 00061 00062 MultiThreadedVisibilityResampler(const Bool& doublePrecision, 00063 const Int& n=DEFAULTNOOFCORES); 00064 00065 MultiThreadedVisibilityResampler(const Bool& doublePrecision, 00066 CountedPtr<VisibilityResamplerBase>& visResampler, 00067 const Int& n=DEFAULTNOOFCORES); 00068 virtual ~MultiThreadedVisibilityResampler() 00069 { 00070 cleanup(); 00071 nelements_p=0; 00072 currentVBS_p=0; 00073 } 00074 00075 MultiThreadedVisibilityResampler(const MultiThreadedVisibilityResampler& other){copy(other);}; 00076 00077 // This version will make a clone with shared data buffers (the 00078 // complex grids and the sum-of-weights arrays). 00079 MultiThreadedVisibilityResampler* clone() 00080 { 00081 //Allocate a new instance, and copy the internals. 00082 MultiThreadedVisibilityResampler *clonedCopy; 00083 clonedCopy = new MultiThreadedVisibilityResampler(*this); 00084 // Now reset the data buffers with independent buffers (arrays of size 0) 00085 clonedCopy->allocateDataBuffers(); 00086 return clonedCopy; 00087 }; 00088 00089 MultiThreadedVisibilityResampler& operator=(const MultiThreadedVisibilityResampler& other); 00090 00091 void cleanup(); 00092 void releaseBuffers(); 00093 00094 void copy(const MultiThreadedVisibilityResampler& other); 00095 00096 virtual Int nelements() {return nelements_p;}; 00097 virtual void setParams(const Vector<Double>& uvwScale, const Vector<Double>& offset, 00098 const Vector<Double>& dphase); 00099 00100 virtual void setMaps(const Vector<Int>& chanMap, const Vector<Int>& polMap); 00101 virtual void setCFMaps(const Vector<Int>& cfMap, const Vector<Int>& conjCFMap); 00102 virtual void setFreqMaps(const Matrix<Double>& spwChanFreqs, const Matrix<Double>& spwChanConjFreqs); 00103 00104 virtual void setConvFunc(const CFStore& cfs); 00105 void init(const Bool& doublePrecision); 00106 // 00107 //------------------------------------------------------------------------------ 00108 // 00109 // Re-sample the griddedData on the VisBuffer (a.k.a gridding). 00110 // 00111 // In this class, these just call the private templated version. 00112 // The first variant grids onto a double precision grid while the 00113 // second one does it on a single precision grid. 00114 // 00115 virtual void DataToGrid(Array<DComplex>& griddedData, 00116 VBStore& vbs, 00117 Matrix<Double>& sumwt, 00118 const Bool& dopsf,Bool /*useConjFreqCF*/=False) 00119 {DataToGridImpl_p(griddedData, vbs, sumwt,dopsf);} 00120 00121 virtual void DataToGrid(Array<Complex>& griddedData, 00122 VBStore& vbs, 00123 Matrix<Double>& sumwt, 00124 const Bool& dopsf,Bool /*useConjFreqCF*/=False) 00125 { 00126 DataToGridImpl_p(griddedData, vbs, sumwt,dopsf); 00127 } 00128 00129 // 00130 // This is the gather operation on griddedData for nelements > 1 00131 // 00132 void GatherGrids(Array<DComplex>& griddedData, Matrix<Double>& sumwt); 00133 void GatherGrids(Array<Complex>& griddedData, Matrix<Double>& sumwt); 00134 void initializePutBuffers(const Array<DComplex>& griddedData, 00135 const Matrix<Double>& sumwt); 00136 void initializePutBuffers(const Array<Complex>& griddedData, 00137 const Matrix<Double>& sumwt); 00138 00139 // 00140 //------------------------------------------------------------------------------ 00141 // 00142 // Re-sample VisBuffer to a regular grid (griddedData) (a.k.a. de-gridding) 00143 // 00144 virtual void GridToData(VBStore& vbs, const Array<Complex>& griddedData); 00145 // virtual void GridToData(VBStore& vbs, Array<Complex>& griddedData); 00146 00147 virtual void ComputeResiduals(VBStore& vbs); 00148 // 00149 //------------------------------------------------------------------------------ 00150 //----------------------------Private parts------------------------------------- 00151 //------------------------------------------------------------------------------ 00152 // 00153 private: 00154 template <class T> 00155 void DataToGridImpl_p(Array<T>& griddedData, VBStore& vb, 00156 Matrix<Double>& sumwt,const Bool& dopsf,Bool useConjFreqCF=False); 00157 // template <class T> 00158 // void GatherGrids_p(const Array<T>& griddedData, 00159 // const Matrix<Double>& sumwt); 00160 00161 // template <class T> 00162 // void initializeBuffers(const Array<T>& griddedData, 00163 // const Matrix<Double>& sumwt); 00164 00165 void allocateBuffers(Bool newDataBuffers=True); 00166 void makeInfrastructureContainers(); 00167 Double allocateDataBuffers(); 00168 void startThreads(); 00169 void scatter(Matrix<VBStore>& vbsStores,const VBStore& vbs); 00170 00171 Int nelements_p; 00172 Bool doublePrecision_p; 00173 Vector<CountedPtr<VisibilityResamplerBase> > resamplers_p; 00174 Vector<CountedPtr<Array<DComplex> > > doubleGriddedData_p; 00175 Vector<CountedPtr<Array<Complex> > > singleGriddedData_p; 00176 Vector<CountedPtr<Matrix<Double> > > sumwt_p; 00177 Vector<CountedPtr<ResamplerWorklet> > gridderWorklets_p; 00178 // Vector<VBStore> vbsVec_p; 00179 Matrix<VBStore> vbsVec_p; 00180 00181 CountedPtr<ThreadCoordinator<Int> > threadClerk_p; 00182 Bool threadStarted_p; 00183 casa::utilj::DeltaThreadTimes tSetupG, tSendDataG, tWaitForWorkG, tOutsideG; 00184 casa::utilj::DeltaThreadTimes tSetupDG, tSendDataDG, tWaitForWorkDG, tOutsideDG; 00185 casa::utilj::ThreadTimes t4G_p,t4DG_p; 00186 // async::Mutex *mutexForResamplers_p; 00187 CountedPtr<VisibilityResamplerBase> visResamplerCtor_p; 00188 Int whoLoadedVB_p; 00189 Int currentVBS_p; 00190 }; 00191 }; //# NAMESPACE CASA - END 00192 00193 #endif //