LCOV - code coverage report
Current view: top level - synthesis/MeasurementComponents - MultiThreadedVisResampler.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 205 0.0 %
Date: 2024-12-11 20:54:31 Functions: 0 25 0.0 %

          Line data    Source code
       1             : // -*- C++ -*-
       2             : //# MultiThreadedVisResample.cc: Implementation of the MultiThreadedVisibilityResampler class
       3             : //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
       4             : //# Associated Universities, Inc. Washington DC, USA.
       5             : //#
       6             : //# This library is free software; you can redistribute it and/or modify it
       7             : //# under the terms of the GNU Library General Public License as published by
       8             : //# the Free Software Foundation; either version 2 of the License, or (at your
       9             : //# option) any later version.
      10             : //#
      11             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      12             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      14             : //# License for more details.
      15             : //#
      16             : //# You should have received a copy of the GNU Library General Public License
      17             : //# along with this library; if not, write to the Free Software Foundation,
      18             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      19             : //#
      20             : //# Correspondence concerning AIPS++ should be addressed as follows:
      21             : //#        Internet email: casa-feedback@nrao.edu.
      22             : //#        Postal address: AIPS++ Project Office
      23             : //#                        National Radio Astronomy Observatory
      24             : //#                        520 Edgemont Road
      25             : //#                        Charlottesville, VA 22903-2475 USA
      26             : //#
      27             : //# $Id$
      28             : 
      29             : #include <synthesis/TransformMachines/SynthesisError.h>
      30             : #include <synthesis/Utilities/ThreadCoordinator.h>
      31             : //#include <msvis/MSVis/UtilJ.h>
      32             : #include <synthesis/TransformMachines/Utils.h>
      33             : #include <synthesis/TransformMachines/VisibilityResampler.h>
      34             : #include <synthesis/MeasurementComponents/MultiThreadedVisResampler.h>
      35             : #include <synthesis/MeasurementComponents/ResamplerWorklet.h>
      36             : #include <synthesis/TransformMachines/AWVisResampler.h>
      37             : #include <synthesis/MeasurementComponents/MThWorkIDEnum.h>
      38             : #include <fstream>
      39             : 
      40             : using namespace casacore;
      41             : namespace casa{
      42             :   template 
      43             :   void MultiThreadedVisibilityResampler::DataToGridImpl_p(Array<Complex>& griddedData,  
      44             :                                                           VBStore& vbs, 
      45             :                                                           Matrix<Double>& sumwt,
      46             :                                                           const Bool& dopsf,
      47             :                                                           Bool useConjFreqCF);
      48             :   template 
      49             :   void MultiThreadedVisibilityResampler::DataToGridImpl_p(Array<DComplex>& griddedData,  
      50             :                                                           VBStore& vbs, 
      51             :                                                           Matrix<Double>& sumwt,
      52             :                                                           const Bool& dopsf,
      53             :                                                           Bool useConjFreqCF);
      54             :   //
      55             :   //---------------------------------------------------------------------------------------
      56             :   //
      57           0 :   MultiThreadedVisibilityResampler::MultiThreadedVisibilityResampler(const Bool& doublePrecision,
      58             :                                                                      CountedPtr<VisibilityResamplerBase>& visResampler, 
      59           0 :                                                                      const Int& n):
      60           0 :     resamplers_p(), doubleGriddedData_p(), singleGriddedData_p(), sumwt_p(), gridderWorklets_p(), 
      61           0 :     vbsVec_p(), threadClerk_p(),threadStarted_p(false), visResamplerCtor_p(visResampler), 
      62           0 :     whoLoadedVB_p(MThWorkID::NOONE), currentVBS_p(0)
      63             :     {
      64           0 :       if (n < 0) nelements_p = SynthesisUtils::getenv(FTMachineNumThreadsEnvVar, n);
      65           0 :       if (nelements_p < 0) nelements_p = 1;
      66           0 :       init(doublePrecision);
      67             :       // t4G_p=Timers::getTime();
      68             :       // t4DG_p=Timers::getTime();
      69           0 :     }
      70             :   //
      71             :   //---------------------------------------------------------------------------------------
      72             :   //
      73           0 :   MultiThreadedVisibilityResampler::MultiThreadedVisibilityResampler(const Bool& doublePrecision,
      74           0 :                                                                      const Int& n):
      75           0 :     resamplers_p(), doubleGriddedData_p(), singleGriddedData_p(), sumwt_p(), gridderWorklets_p(), 
      76           0 :     vbsVec_p(), threadClerk_p(),threadStarted_p(false), visResamplerCtor_p(), 
      77           0 :     whoLoadedVB_p(MThWorkID::NOONE),currentVBS_p(0)
      78             :     {
      79           0 :       if (n < 0) nelements_p = SynthesisUtils::getenv(FTMachineNumThreadsEnvVar, n);
      80           0 :       if (nelements_p < 0) nelements_p = 1;
      81           0 :       init(doublePrecision);
      82             :       // t4G_p=Timers::getTime();
      83             :       // t4DG_p=Timers::getTime();
      84           0 :     }
      85             :   //
      86             :   //---------------------------------------------------------------------------------------
      87             :   //
      88           0 :   void MultiThreadedVisibilityResampler::copy(const MultiThreadedVisibilityResampler& other)
      89             :   {
      90           0 :     resamplers_p.assign(other.resamplers_p);
      91           0 :     gridderWorklets_p.assign(other.gridderWorklets_p);
      92           0 :     vbsVec_p.assign(other.vbsVec_p);
      93             : 
      94           0 :     doubleGriddedData_p.assign(other.doubleGriddedData_p);
      95           0 :     singleGriddedData_p.assign(other.singleGriddedData_p);
      96           0 :     sumwt_p.assign(other.sumwt_p);
      97             :     // doubleGriddedData_p.reference(other.doubleGriddedData_p);
      98             :     // singleGriddedData_p.reference(other.singleGriddedData_p);
      99             :     // sumwt_p.reference(other.sumwt_p);
     100             : 
     101           0 :     nelements_p       = other.nelements_p;
     102           0 :     doublePrecision_p = other.doublePrecision_p;
     103           0 :     threadClerk_p     = other.threadClerk_p;
     104           0 :     threadStarted_p   = other.threadStarted_p;
     105           0 :     whoLoadedVB_p     = other.whoLoadedVB_p;
     106           0 :     currentVBS_p      = other.currentVBS_p;
     107             :     // t4G_p=other.t4G_p;
     108             :     // t4DG_p=other.t4DG_p;
     109           0 :   }
     110             :   //
     111             :   //---------------------------------------------------------------------------------------
     112             :   //
     113             :   MultiThreadedVisibilityResampler& 
     114           0 :   MultiThreadedVisibilityResampler::operator=(const MultiThreadedVisibilityResampler& other)
     115           0 :   { copy(other); return *this;}
     116             :   //
     117             :   //---------------------------------------------------------------------------------------
     118             :   //
     119           0 :   void MultiThreadedVisibilityResampler::init(const Bool& doublePrecision)
     120             :   {
     121           0 :     LogIO log_p(LogOrigin("MultiThreadedVisibilityResampler","init"));
     122           0 :     doublePrecision_p=doublePrecision;
     123           0 :     allocateBuffers();
     124           0 :   }
     125             :   //
     126             :   //---------------------------------------------------------------------------------------
     127             :   //
     128           0 :   void MultiThreadedVisibilityResampler::cleanup()
     129             :   {
     130             :     //    if ((nelements() > 1)  && (threadClerk_p->nThreads() > 0))
     131           0 :     if (threadClerk_p->nThreads() > 0)
     132             :       {
     133             :         //      threadClerk_p->getToWork(NULL); // Signal the threads to quit
     134           0 :         threadClerk_p->giveWorkToWorkers(NULL); // Signal the threads to quit
     135           0 :         threadClerk_p->setNThreads(0);
     136             :         //      if (!threadClerk_p.null()) {delete &(*threadClerk_p);}
     137           0 :         vbsVec_p.resize(0,0);
     138           0 :         resamplers_p.resize(0);
     139             :         //    for(Int i=0; i<gridderWorklets_p.nelements(); i++) delete &(*gridderWorklets_p[i]);
     140           0 :         gridderWorklets_p.resize(0);
     141           0 :         sumwt_p.resize(0);
     142           0 :         doubleGriddedData_p.resize(0);
     143           0 :         singleGriddedData_p.resize(0);
     144           0 :         nelements_p=0;
     145           0 :         whoLoadedVB_p = MThWorkID::NOONE;
     146           0 :         currentVBS_p=0;
     147             :         //    delete mutexForResamplers_p;
     148             :       }
     149           0 :   }
     150             :   //
     151             :   //---------------------------------------------------------------------------------------
     152             :   //
     153           0 :   void MultiThreadedVisibilityResampler::releaseBuffers()
     154             :   {
     155             :     // for (Int i=0;i<nelements();i++)
     156             :     //   {
     157             :     //  //      if (!resamplers_p[i].null()) delete &(*resamplers_p[i]);
     158             :     //  //      if (!gridderWorklets_p[i].null()) delete &(*gridderWorklets_p[i]);
     159             :     //  if (doublePrecision_p)
     160             :     //    if (!doubleGriddedData_p[i].null()) delete &(*doubleGriddedData_p[i]);
     161             :     //    else if (!singleGriddedData_p[i].null()) delete &(*singleGriddedData_p[i]);
     162             :     //  if (!sumwt_p[i].null()) delete &(*sumwt_p[i]);
     163             :     //   }
     164             :     // resamplers_p.resize(0);
     165             :     // gridderWorklets_p.resize(0);
     166           0 :     doubleGriddedData_p.resize(0);
     167           0 :     singleGriddedData_p.resize(0);
     168           0 :     sumwt_p.resize(0);
     169           0 :   }
     170             :   //
     171             :   //---------------------------------------------------------------------------------------
     172             :   //
     173           0 :   void MultiThreadedVisibilityResampler::makeInfrastructureContainers()
     174             :   {
     175             :     //
     176             :     // Fill the various containers (allocate buffers)
     177             :     //----------------------------------------------------------------
     178           0 :     if (threadClerk_p.null()) threadClerk_p = new ThreadCoordinator<Int>(nelements());
     179           0 :     for (Int i=0;i<nelements();i++)
     180             :       {
     181           0 :         resamplers_p[i] = visResamplerCtor_p->clone();
     182           0 :         gridderWorklets_p[i] = new ResamplerWorklet();
     183             :       }
     184           0 :   }
     185             :   //
     186             :   //---------------------------------------------------------------------------------------
     187             :   //
     188           0 :   Double MultiThreadedVisibilityResampler::allocateDataBuffers()
     189             :   {
     190           0 :     Int totalMem=0;
     191           0 :     for (Int i=0;i<nelements();i++)
     192             :       {
     193             :         //
     194             :         // *GriddedData and sumwt are the target complex grids
     195             :         // *(for gridding) and accumulating sum-of-weights (also
     196             :         // *during gridding).  These may or may not be shared.
     197             :         //
     198           0 :         if (doublePrecision_p) doubleGriddedData_p[i] = new Array<DComplex>;
     199           0 :         else                   singleGriddedData_p[i] = new Array<Complex>;
     200           0 :         sumwt_p[i] = new Matrix<Double>;
     201           0 :         if (!threadStarted_p)
     202             :           {
     203           0 :             if (doublePrecision_p) totalMem += (*doubleGriddedData_p[i]).size()*sizeof(DComplex);
     204           0 :             else totalMem += (*singleGriddedData_p[i]).size()*sizeof(Complex);
     205           0 :             totalMem += (*sumwt_p[i]).size()*sizeof(Double);
     206             :             // (*gridderWorklets_p[i]).initThread(i, threadClerk_p, 
     207             :             //                                 &(*resamplers_p[i]));
     208             :             // (*gridderWorklets_p[i]).startThread();
     209             :           }
     210             :       }
     211           0 :     return totalMem;
     212             :   }
     213             :   //
     214             :   //---------------------------------------------------------------------------------------
     215             :   //
     216           0 :   void MultiThreadedVisibilityResampler::startThreads()
     217             :   {
     218           0 :     if (!threadStarted_p)
     219           0 :       for (Int i=0;i<nelements();i++)
     220             :         {
     221           0 :           (*gridderWorklets_p[i]).initThread(i, threadClerk_p, 
     222           0 :                                              &(*resamplers_p[i]));
     223           0 :           (*gridderWorklets_p[i]).startThread();
     224             :         }
     225           0 :     threadStarted_p=true;
     226           0 :   }
     227             :   //
     228             :   //---------------------------------------------------------------------------------------
     229             :   //
     230           0 :   void MultiThreadedVisibilityResampler::allocateBuffers(Bool /*newDataBuffers*/)
     231             :   {
     232           0 :     LogIO log_p(LogOrigin("MultiThreadedVisibilityResampler","allocateBuffers"));
     233           0 :     Double totalMem=0;
     234             :     //    if (nelements() > 1)
     235             :       {
     236           0 :         if (visResamplerCtor_p.null())
     237           0 :           log_p << "Internal Error: VisResampler Ctor not initialized" << LogIO::EXCEPTION;
     238             : 
     239           0 :         log_p << "Allocating buffers per thread.  No. of threads = " << nelements() << endl;
     240             :         //      mutexForResamplers_p = new async::Mutex;
     241             : 
     242             :         //
     243             :         // Resize the containers
     244             :         //----------------------------------------------------------------
     245           0 :         if (doublePrecision_p)  doubleGriddedData_p.resize(nelements());
     246           0 :         else                    singleGriddedData_p.resize(nelements());
     247             : 
     248           0 :         resamplers_p.resize(nelements());
     249           0 :         sumwt_p.resize(nelements());
     250           0 :         gridderWorklets_p.resize(nelements());
     251           0 :         vbsVec_p.resize(nelements(),1);
     252             :         //----------------------------------------------------------------
     253             : 
     254           0 :         makeInfrastructureContainers();
     255           0 :         totalMem=allocateDataBuffers();
     256           0 :         startThreads();
     257             :         //----------------------------------------------------------------
     258             :       }
     259             :     // else
     260             :     //   {
     261             :     //  resamplers_p.resize(1);
     262             :     //  //      resamplers_p[0] = new VisibilityResampler();
     263             :     //  //      resamplers_p[0] = visResamplerCtor_p;
     264             :     //  resamplers_p[0] = visResamplerCtor_p->clone();
     265             :     //  vbsVec_p.resize(1,1);
     266             :     //  cerr << "#@%@%@%#$@#$"<< endl;
     267             :     //          gridderWorklets_p.resize(1);
     268             :     //      gridderWorklets_p[0] = new ResamplerWorklet();
     269             :     //         singleGriddedData_p.resize(1);
     270             :     //      sumwt_p.resize(1);
     271             :     //      if (doublePrecision_p) doubleGriddedData_p[0] = new Array<DComplex>;
     272             :     //      else                   singleGriddedData_p[0] = new Array<Complex>;
     273             :     //      sumwt_p[0] = new Matrix<Double>;
     274             :     //   }
     275           0 :     if (totalMem > 0)
     276           0 :       log_p << "Total memory used in buffers for multi-threading: " << totalMem/(1024*1024) << " MB" << LogIO::POST;
     277           0 :   }
     278             :   //
     279             :   //---------------------------------------------------------------------------------------
     280             :   //
     281           0 :   void MultiThreadedVisibilityResampler::setParams(const Vector<Double>& uvwScale, 
     282             :                                                    const Vector<Double>& offset,
     283             :                                                    const Vector<Double>& dphase)
     284           0 :   {for (Int i=0;i < nelements(); i++) resamplers_p[i]->setParams(uvwScale, offset, dphase);}
     285             :   //
     286             :   //---------------------------------------------------------------------------------------
     287             :   //
     288           0 :   void MultiThreadedVisibilityResampler::setMaps(const Vector<Int>& chanMap, 
     289             :                                                  const Vector<Int>& polMap)
     290           0 :   {for (Int i=0;i < nelements(); i++) resamplers_p[i]->setMaps(chanMap, polMap);};
     291             :   //
     292             :   //---------------------------------------------------------------------------------------
     293             :   //
     294           0 :   void MultiThreadedVisibilityResampler::setCFMaps(const Vector<Int>& cfMap, 
     295             :                                                    const Vector<Int>& conjCFMap)
     296           0 :   {for (Int i=0;i < nelements(); i++) resamplers_p[i]->setCFMaps(cfMap, conjCFMap);};
     297             :   //
     298             :   //---------------------------------------------------------------------------------------
     299             :   //
     300           0 :   void MultiThreadedVisibilityResampler::setConvFunc(const CFStore& cfs)
     301           0 :   {for (Int i=0;i < nelements(); i++) resamplers_p[i]->setConvFunc(cfs);};
     302             :   //
     303             :   //---------------------------------------------------------------------------------------
     304             :   //
     305           0 :   void MultiThreadedVisibilityResampler::setFreqMaps(const Matrix<Double>& spwChanFreqs, const Matrix<Double>& spwChanConjFreqs)
     306           0 :   {for (Int i=0;i < nelements(); i++) resamplers_p[i]->setFreqMaps(spwChanFreqs,spwChanConjFreqs);}
     307             :   //
     308             :   //---------------------------------------------------------------------------------------
     309             :   //
     310           0 :   void MultiThreadedVisibilityResampler::scatter(Matrix<VBStore>& vbStores,const VBStore& vbs)
     311             :   {
     312           0 :     Int nRows=vbs.nRow_p, nr,br=0;
     313           0 :     nr=(Int)(nRows/nelements())+1;
     314             : 
     315           0 :     for(Int i=0; i < nelements(); i++)
     316             :       {
     317           0 :         vbStores(i,currentVBS_p).reference(vbs);
     318           0 :         vbStores(i,currentVBS_p).beginRow_p = min(br,nRows); 
     319           0 :         vbStores(i,currentVBS_p).endRow_p   = min(br+nr,nRows);
     320           0 :         br = vbStores(i,currentVBS_p).endRow_p;
     321             :       }
     322           0 :   }
     323             :   //
     324             :   //---------------------------------------------------------------------------------------
     325             :   //
     326           0 :   void MultiThreadedVisibilityResampler::GatherGrids(Array<DComplex>& griddedData,
     327             :                                                      Matrix<Double>& sumwt)
     328             :   {
     329           0 :     LogIO log_p(LogOrigin("MultiThreadedVisibilityResampler(Double)","GatherGrids"));
     330             :     //    if (nelements() > 1)
     331             :       {
     332             :         //      log_p << "Deleting thread clerk" << LogIO::POST;
     333             :         //      delete threadClerk_p; threadClerk_p=NULL;
     334           0 :         log_p << "Gathering grids..." << LogIO::POST;
     335             :         // cerr << "Gridded data shape = " << griddedData.shape() << " " << sumwt.shape() << endl;
     336             :         // for (Int i=0;i<nelements();i++)
     337             :         //   cerr << "Gridded buffer shape = " 
     338             :         //        << (*doubleGriddedData_p[i]).shape() << " " 
     339             :         //        << (*sumwt_p[i]).shape() << endl;
     340           0 :         for(Int i=0;i<nelements(); i++)
     341             :           {
     342           0 :             griddedData += *(doubleGriddedData_p[i]);
     343           0 :             sumwt += *(sumwt_p[i]);
     344             :           }
     345             :       }
     346             :     log_p << "Gridder timing: " 
     347           0 :           << "Setup = " << tSetupG.formatAverage().c_str() << " " 
     348           0 :           << "SendData = " << tSendDataG.formatAverage().c_str() << " " 
     349           0 :           << "WaitForWork = " << tWaitForWorkG.formatAverage().c_str() 
     350           0 :           << "Outside = " << tOutsideG.formatAverage().c_str() 
     351           0 :           << LogIO::POST;
     352             :     //  log_p << "DGridder timing: "
     353             :     //            << "Setup = " << tSetupDG.formatAverage().c_str() << " " 
     354             :     //            << "SendData = " << tSendDataDG.formatAverage().c_str() << " " 
     355             :     //            << "WaitForWork = " << tWaitForWorkDG.formatAverage().c_str() 
     356             :     //            << "Outside = " << tOutsideDG.formatAverage().c_str() 
     357             :     //            << LogIO::POST;
     358           0 :   }
     359             :   //
     360             :   //---------------------------------------------------------------------------------------
     361             :   //
     362           0 :   void MultiThreadedVisibilityResampler::GatherGrids(Array<Complex>& griddedData,
     363             :                                                      Matrix<Double>& sumwt)
     364             :   {
     365           0 :     LogIO log_p(LogOrigin("MultiThreadedVisibilityResampler(Single)","GatherGrids"));
     366             :     //    if (nelements() > 1)
     367             :       {
     368           0 :         log_p << "Gathering grids..." << LogIO::POST;
     369           0 :         for(Int i=0;i<nelements(); i++)
     370             :           {
     371           0 :             griddedData += *(singleGriddedData_p[i]);
     372           0 :             sumwt += *(sumwt_p[i]);
     373             :           }
     374             :       }
     375             :     log_p << "Gridder timing: " 
     376           0 :           << "Setup = " << tSetupG.formatAverage().c_str() << " " 
     377           0 :           << "SendData = " << tSendDataG.formatAverage().c_str() << " " 
     378           0 :           << "WaitForWork = " << tWaitForWorkG.formatAverage().c_str() 
     379           0 :           << "Outside = " << tOutsideG.formatAverage().c_str() 
     380           0 :           << LogIO::POST;
     381           0 :   }
     382             :   //
     383             :   //---------------------------------------------------------------------------------------
     384             :   //
     385           0 :   void MultiThreadedVisibilityResampler::initializePutBuffers(const Array<DComplex>& griddedData,
     386             :                                                               const Matrix<Double>& sumwt)
     387             :   {
     388           0 :     LogIO log_p(LogOrigin("MultiThreadedVisibilityResampler","initializeBuffers"));
     389             :     //    if ((nelements() > 1))
     390             :       {
     391             :         //      if (threadClerk_p) {delete threadClerk_p; threadClerk_p=NULL;}
     392           0 :         Double totalMem=0;
     393             :         // if (!threadClerk_p) threadClerk_p = new ThreadCoordinator<Int>(nelements());
     394           0 :         for(Int i=0; i<nelements(); i++)
     395             :           {
     396             :             // Resize and copy The following commented code attempts
     397             :             // to defeat the problem of false sharing, should it be
     398             :             // the bottlenec.
     399             :             // {
     400             :             //   Vector<Array<DComplex>* > tmp(5);
     401             :             //   for (Int j=0;j<5;j++) 
     402             :             //  {
     403             :             //    (tmp[j]) = new Array<DComplex>;
     404             :             //    (tmp[j])->assign(griddedData);
     405             :             //  }
     406             :             //   (*doubleGriddedData_p[i]).assign(griddedData);
     407             :             //   for (Int j=0;j<5;j++) delete tmp[j];
     408             :             // }
     409             : 
     410             :             // The following code relies on system memalloc
     411           0 :             (*doubleGriddedData_p[i]).assign(griddedData);
     412           0 :             (*sumwt_p[i]).assign(sumwt);
     413           0 :             if (!threadStarted_p)
     414             :               {
     415           0 :                 totalMem += (*doubleGriddedData_p[i]).size()*sizeof(DComplex);
     416           0 :                 totalMem += (*sumwt_p[i]).size()*sizeof(Double);
     417             :               }
     418             :           }
     419           0 :         if (!threadStarted_p) 
     420           0 :           log_p << "Total memory used in buffers:" << totalMem/(1024*1024) << " MB" << LogIO::POST;
     421             :         // for (Int i=0;i<nelements(); i++)
     422             :         //   log_p << "Activating worklet " 
     423             :         //      << "# "     << (*gridderWorklets_p[i]).getID()  << ". " 
     424             :         //      << "PID = " << (*gridderWorklets_p[i]).getPID() << " "
     425             :         //      << "TID = " << (*gridderWorklets_p[i]).getTID() 
     426             :         //      << LogIO::POST;
     427             :         //      threadStarted_p = true;
     428             :       }
     429           0 :   }
     430             :   //
     431             :   //---------------------------------------------------------------------------------------
     432             :   //
     433           0 :   void MultiThreadedVisibilityResampler::initializePutBuffers(const Array<Complex>& griddedData,
     434             :                                                               const Matrix<Double>& sumwt)
     435             :   {
     436           0 :     LogIO log_p(LogOrigin("MultiThreadedVisibilityResampler", "initializePutBuffers(Single)"));
     437             :     //    if (nelements() > 1)
     438             :       {
     439           0 :         for(Int i=0; i<nelements(); i++)
     440             :           {
     441           0 :             (*singleGriddedData_p[i]).assign(griddedData);
     442           0 :             (*sumwt_p[i]).assign(sumwt);
     443             :           }
     444             :       }
     445           0 :   }
     446             :   //
     447             :   //------------------------------------------------------------------------------
     448             :   //
     449             :   // Re-sample the griddedData on the VisBuffer (a.k.a gridding).
     450             :   //
     451             :   // Make the following four methods via templated implementation.
     452             :   template <class T>
     453           0 :   void MultiThreadedVisibilityResampler::DataToGridImpl_p(Array<T>& /*griddedData*/,  
     454             :                                                           VBStore& vbs, 
     455             :                                                           Matrix<Double>& /*sumwt*/,
     456             :                                                           const Bool& dopsf,
     457             :                                                           Bool /*useConjFreqCF*/)
     458             :   {
     459             :     //    LogIO log_p(LogOrigin("MultiThreadedVisibilityResampler", "DataToGridImpl_p"));
     460           0 :     if (whoLoadedVB_p == MThWorkID::DATATOGRID)  {/*scatter(vbsVec_p,vbs); */whoLoadedVB_p = MThWorkID::DATATOGRID;}
     461           0 :     scatter(vbsVec_p,vbs); 
     462             : 
     463             :     // if (nelements() == 1)
     464             :     //   resamplers_p[0]->DataToGrid(griddedData, vbsVec_p(0,currentVBS_p), sumwt, dopsf);
     465             :     //   //      resamplers_p[0]->DataToGrid(*singleGriddedData_p[0], vbsVec_p(0,currentVBS_p),*sumwt_p[0] , dopsf);
     466             :     // else
     467             :       {
     468             :         //      Int workRequestDataToGrid=1;
     469           0 :         Int workRequestDataToGrid=MThWorkID::DATATOGRID;
     470           0 :         casa::utilj::ThreadTimes t1=casa::utilj::ThreadTimes::getTime();
     471           0 :         for(Int i=0; i < nelements(); i++) 
     472             :           {
     473           0 :             vbsVec_p(i,currentVBS_p).dopsf_p = dopsf;
     474           0 :             if (doublePrecision_p) 
     475           0 :               (*gridderWorklets_p[i]).initToSky(&vbsVec_p(i,currentVBS_p), 
     476           0 :                                                 &(*doubleGriddedData_p[i]),
     477           0 :                                                 &(*sumwt_p[i]));
     478             :             else                    
     479             :               {
     480             :                 // cerr << &(*gridderWorklets_p[i]) << " "
     481             :                 //      << &(*singleGriddedData_p[i]) << " " 
     482             :                 //      << &(*sumwt_p[i]) << " " << i << endl;
     483             :                 // if(gridderWorklets_p[i].null()) cerr << "worklet null" << endl;
     484             :                 // if (singleGriddedData_p[i].null()) cerr << "data null" << endl;
     485             :                 // if (sumwt_p[i].null()) cerr << "wt null" << endl;
     486           0 :                 (*gridderWorklets_p[i]).initToSky(&vbsVec_p(i,currentVBS_p), 
     487           0 :                                                   &(*singleGriddedData_p[i]),
     488           0 :                                                   &(*sumwt_p[i]));
     489             :               }
     490             :           }
     491             : 
     492           0 :         casa::utilj::ThreadTimes t2=casa::utilj::ThreadTimes::getTime();
     493             :         //      threadClerk_p->getToWork(&workRequestDataToGrid);
     494           0 :         threadClerk_p->giveWorkToWorkers(&workRequestDataToGrid);
     495           0 :         casa::utilj::ThreadTimes t3=casa::utilj::ThreadTimes::getTime();
     496           0 :         threadClerk_p->waitForWorkersToFinishTask();
     497           0 :         casa::utilj::ThreadTimes t4=casa::utilj::ThreadTimes::getTime();
     498             :         
     499           0 :          tSetupG       += t2-t1;
     500           0 :          tSendDataG    += t3-t2;
     501           0 :          tWaitForWorkG += t4-t3;
     502           0 :          tOutsideG     += t1-t4G_p;
     503             :       }
     504           0 :       t4G_p = casa::utilj::ThreadTimes::getTime();
     505           0 :   }
     506             :   //
     507             :   //------------------------------------------------------------------------------
     508             :   //
     509             :   // Re-sample VisBuffer to a regular grid (griddedData) (a.k.a. de-gridding)
     510             :   // Still single threaded...
     511           0 :   void MultiThreadedVisibilityResampler::GridToData(VBStore& vbs, const Array<Complex>& griddedData) 
     512             :   {
     513             :     //    LogIO log_p(LogOrigin("MultiThreadedVisibilityResampler", "GridToData"));
     514           0 :     if (whoLoadedVB_p == MThWorkID::GRIDTODATA) {/*scatter(vbsVec_p,vbs);*/ whoLoadedVB_p = MThWorkID::GRIDTODATA;}
     515           0 :     scatter(vbsVec_p,vbs); 
     516             : 
     517             :     // if (nelements() == 1)
     518             :     //   resamplers_p[0]->GridToData(vbsVec_p(0,currentVBS_p),griddedData);
     519             :     // else
     520             :       {
     521             :         //      Int workRequestDataToGrid=0;
     522           0 :         Int workRequestDataToGrid=MThWorkID::GRIDTODATA;
     523             :         //      Timers t1=Timers::getTime();
     524           0 :         for(Int i=0; i < nelements(); i++) 
     525             :           {
     526           0 :             (*gridderWorklets_p[i]).initToVis(&vbsVec_p(i,currentVBS_p),&griddedData);
     527             :           }
     528             :         //      Timers t2=Timers::getTime();
     529             :         //      threadClerk_p->getToWork(&workRequestDataToGrid);
     530           0 :         threadClerk_p->giveWorkToWorkers(&workRequestDataToGrid);
     531             :         //      Timers t3=Timers::getTime();
     532           0 :         threadClerk_p->waitForWorkersToFinishTask();
     533             :         //      Timers t4=Timers::getTime();
     534             :         // tSetupDG += t2-t1;
     535             :         // tSendDataDG += t3-t2;
     536             :         // tWaitForWorkDG += t4-t3;
     537             :         // tOutsideDG += t1-t4DG_p;
     538             :       }
     539             :       //      t4DG_p = Timers::getTime();
     540           0 :   }
     541             :   //
     542             :   //------------------------------------------------------------------------------
     543             :   //
     544           0 :   void MultiThreadedVisibilityResampler::ComputeResiduals(VBStore& vbs)
     545             :   {
     546           0 :     if (whoLoadedVB_p == MThWorkID::RESIDUALCALC) {/*scatter(vbsVec_p,vbs);*/ whoLoadedVB_p = MThWorkID::RESIDUALCALC;}
     547           0 :     scatter(vbsVec_p,vbs); 
     548             : 
     549             :     // if (nelements() == 1)
     550             :     //   resamplers_p[0]->ComputeResiduals(vbsVec_p(0,currentVBS_p));
     551             :     // else
     552             :       {
     553             :         //      Int workRequested=2;
     554           0 :         Int workRequested=MThWorkID::RESIDUALCALC;
     555           0 :         for (Int i=0; i<nelements(); i++)
     556           0 :           (*gridderWorklets_p[i]).initToVis(&vbsVec_p(i,currentVBS_p),NULL);
     557           0 :         threadClerk_p->giveWorkToWorkers(&workRequested);
     558           0 :         threadClerk_p->waitForWorkersToFinishTask();
     559             :       }
     560           0 :   }
     561             : 
     562             : };

Generated by: LCOV version 1.16