Line data Source code
1 : //# ParallelImagerFactory.cc: Factory for ParallelImager instances
2 : //# Copyright (C) 2016
3 : //# Associated Universities, Inc. Washington DC, USA.
4 : //#
5 : //# This library is free software; you can redistribute it and/or modify it
6 : //# under the terms of the GNU Library General Public License as published by
7 : //# the Free Software Foundation; either version 2 of the License, or (at your
8 : //# option) any later version.
9 : //#
10 : //# This library is distributed in the hope that it will be useful, but WITHOUT
11 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 : //# License for more details.
14 : //#
15 : //# You should have received a copy of the GNU Library General Public License
16 : //# along with this library; if not, write to the Free Software Foundation,
17 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 : //#
19 : //# Correspondence concerning AIPS++ should be addressed as follows:
20 : //# Internet email: aips2-request@nrao.edu.
21 : //# Postal address: AIPS++ Project Office
22 : //# National Radio Astronomy Observatory
23 : //# 520 Edgemont Road
24 : //# Charlottesville, VA 22903-2475 USA
25 : //#
26 : #include <synthesis/ImagerObjects/ParallelImagerFactory.h>
27 : #include <synthesis/ImagerObjects/MPIGlue.h>
28 : #include <synthesis/ImagerObjects/ParallelImagerParams.h>
29 : #include <synthesis/ImagerObjects/ParallelImagerAdaptor.h>
30 : #include <string>
31 :
32 : using namespace casacore;
33 : namespace casa {
34 :
35 : ParallelImager *
36 0 : ParallelImagerFactory::make(MPI_Comm task_comm,
37 : Record clean_params,
38 : Record selection_params,
39 : Record image_params,
40 : Record grid_params,
41 : Record weight_params,
42 : Record normalization_params,
43 : Record deconvolution_params,
44 : Record iteration_params)
45 : {
46 : ParallelImager *result;
47 : ParallelImagerParams params(selection_params, image_params, grid_params,
48 : weight_params, normalization_params,
49 0 : deconvolution_params, iteration_params);
50 0 : int niter = iteration_params.asInt("niter");
51 0 : bool calculate_psf = clean_params.asBool("calcpsf");
52 0 : bool calculate_residual = clean_params.asBool("calcres");
53 0 : const std::string &save_model = clean_params.asString("savemodel");
54 0 : bool interactive = iteration_params.asBool("interactive");
55 : int rank;
56 0 : MPI_Comm_rank(task_comm, &rank);
57 : int size;
58 0 : MPI_Comm_size(task_comm, &size);
59 0 : bool is_worker = !interactive || rank > 0 || size == 1;
60 : MPI_Comm worker_comm;
61 0 : MPI_Comm_split(task_comm, is_worker ? 1 : MPI_UNDEFINED, 0, &worker_comm);
62 0 : bool has_non_worker = interactive && size > 1;
63 0 : int num_workers = size - (has_non_worker ? 1 : 0);
64 0 : if (num_workers == 1) {
65 : // Serial imaging, whether or not MPI is available. The use of
66 : // communicators is the same as that for parallel continuum imaging
67 : // (below).
68 0 : MPI_Comm imcomm = dup_valid_comm(worker_comm);
69 0 : MPI_Comm ncomm = normalization_comm(worker_comm, niter);
70 0 : MPI_Comm dcomm = dup_valid_comm(worker_comm);
71 0 : MPI_Comm itcomm = dup_valid_comm(task_comm);
72 0 : result = new SerialParallelImager(
73 : worker_comm, imcomm, ncomm, dcomm, itcomm,
74 0 : niter, calculate_psf, calculate_residual, save_model, params);
75 : } else {
76 0 : const Record &image_field = image_params.subRecord(0);
77 0 : std::string mode(image_field.isDefined("mode")
78 0 : ? image_field.asString("mode")
79 0 : : "mfs");
80 0 : if (mode == "mfs") {
81 : // Parallel continuum imaging. Imaging, normalization and
82 : // deconvolution components each use a duplicate of 'worker_comm';
83 : // the imaging cycles are coordinated across all worker
84 : // processes. Iteration component uses a duplicate of 'task_comm',
85 : // which additionally coordinates interaction with a possible
86 : // user-facing process.
87 0 : MPI_Comm imcomm = dup_valid_comm(worker_comm);
88 0 : MPI_Comm ncomm = normalization_comm(worker_comm, niter);
89 0 : MPI_Comm dcomm = dup_valid_comm(worker_comm);
90 0 : MPI_Comm itcomm = dup_valid_comm(task_comm);
91 0 : result = new ContinuumParallelImager(
92 : worker_comm, imcomm, ncomm, dcomm, itcomm,
93 0 : niter, calculate_psf, calculate_residual, save_model, params);
94 : } else {
95 : // Parallel cube imaging. Imaging, normalization and deconvolution
96 : // components each use a duplicate of MPI_COMM_SELF; each process
97 : // manages the interaction of its components independently of the
98 : // other processes. Iteration component uses a duplicate of
99 : // 'task_comm', as that coordinates across all worker and
100 : // user-facing processes.
101 0 : MPI_Comm worker_self = (is_worker ? MPI_COMM_SELF : MPI_COMM_NULL);
102 0 : MPI_Comm itcomm = dup_valid_comm(task_comm);
103 0 : result = new CubeParallelImager(
104 : worker_comm,
105 : worker_self,
106 0 : normalization_comm(worker_self, niter),
107 : worker_self,
108 : itcomm,
109 0 : niter, calculate_psf, calculate_residual, save_model, params);
110 : }
111 : }
112 0 : return result;
113 : }
114 :
115 : using namespace casacore;
116 : } // namespace casa
|