SynthesisDeconvolverMixin.h

Go to the documentation of this file.
00001 /* -*- mode: c++ -*- */
00002 //# SynthesisDeconvolverMixin.h: Mixin for using SynthesisDeconvolver class in
00003 //#                              parallel imaging framework
00004 //#                              (ParallelImagerMixin)
00005 //# Copyright (C) 2016
00006 //# Associated Universities, Inc. Washington DC, USA.
00007 //#
00008 //# This library is free software; you can redistribute it and/or modify it
00009 //# under the terms of the GNU Library General Public License as published by
00010 //# the Free Software Foundation; either version 2 of the License, or (at your
00011 //# option) any later version.
00012 //#
00013 //# This library is distributed in the hope that it will be useful, but WITHOUT
00014 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00016 //# License for more details.
00017 //#
00018 //# You should have received a copy of the GNU Library General Public License
00019 //# along with this library; if not, write to the Free Software Foundation,
00020 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00021 //#
00022 //# Correspondence concerning AIPS++ should be addressed as follows:
00023 //#        Internet email: aips2-request@nrao.edu.
00024 //#        Postal address: AIPS++ Project Office
00025 //#                        National Radio Astronomy Observatory
00026 //#                        520 Edgemont Road
00027 //#                        Charlottesville, VA 22903-2475 USA
00028 //#
00029 #ifndef SYNTHESIS_DECONVOLVER_MIXIN_H_
00030 #define SYNTHESIS_DECONVOLVER_MIXIN_H_
00031 
00032 #include <casa/Containers/Record.h>
00033 #include <synthesis/ImagerObjects/MPIGlue.h>
00034 #include <synthesis/ImagerObjects/SynthesisDeconvolver.h>
00035 #include <memory>
00036 #include <algorithm>
00037 #include <vector>
00038 
00039 namespace casa {
00040 
00045 template<class T>
00046 class SynthesisDeconvolverMixin
00047         : public T {
00048 
00049 private:
00050         std::vector< std::shared_ptr<SynthesisDeconvolver> > deconvolvers;
00051 
00052         Record controls;
00053 
00054 protected:
00055         void
00056         setup_deconvolver(MPI_Comm comm,
00057                           std::vector<SynthesisParamsDeconv> &deconv_pars) {
00058                 // Create all deconvolver components on rank 0 of comm. TODO: Could we
00059                 // distribute deconvolvers in a round-robin fashion across processes in
00060                 // comm?
00061 
00062                 teardown_deconvolver();
00063                 if (T::effective_rank(comm) == 0) {
00064                         size_t num_fields = deconv_pars.size();
00065                         for (size_t i = 0; i < num_fields; ++i) {
00066                                 SynthesisDeconvolver *sd = new SynthesisDeconvolver();
00067                                 sd->setupDeconvolution(deconv_pars[i]);
00068                                 deconvolvers.push_back(
00069                                         std::shared_ptr<SynthesisDeconvolver>(sd));
00070                         }
00071                 }
00072         };
00073 
00074         void
00075         teardown_deconvolver() {
00076                 deconvolvers.clear();
00077         };
00078 
00079 public:
00080         void
00081         initialize_minor_cycle() {
00082                 std::vector<Record> init_records;
00083                 for (auto sd : deconvolvers)
00084                         init_records.push_back(sd->initMinorCycle());
00085                 T::merge_initialization_records(init_records);
00086                 controls = T::get_minor_cycle_controls();
00087         };
00088 
00089         void
00090         execute_minor_cycle() {
00091                 std::vector<Record> exec_records;
00092                 for (auto sd : deconvolvers)
00093                         exec_records.push_back(sd->executeMinorCycle(controls));
00094                 T::merge_execution_records(exec_records);
00095         };
00096 
00097         void
00098         restore_images() {
00099                 for (auto sd : deconvolvers)
00100                         sd->restore();
00101         };
00102 };
00103 
00104 } // namespace casa
00105 
00106 #endif // SYNTHESIS_DECONVOLVER_MIXIN_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1