Source
/* -*- mode: c++ -*- */
//# CubePartitionMixin.h: Parallel cube imaging data partitioning
//# Copyright (C) 2016
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
namespace casa {
/**
* Parameter and input data partitioning for parallel cube imaging (in
* ParallelImagerMixin).
*/
template <class T>
class CubePartitionMixin
: public T {
public:
void concat_images(const string &type) {
casacore::LogIO log(casacore::LogOrigin("CubePartitionMixin", "concat_images", WHERE));
if (worker_rank >= 0) {
const std::string image_types[] =
{"image", "psf", "model", "residual", "mask", "pb", "weight"};
string cwd(getcwd(nullptr, 0));
// wait until all ranks have completed file modifications
MPI_Barrier(worker_comm);
// round-robin allocation of image concatenation tasks to worker
// ranks
for (casacore::uInt i = (casacore::uInt)worker_rank;
i < image_parameters.nfields();
i += (casacore::uInt)num_workers) {
std::string imagename =
image_parameters.subRecord(i).asString("imagename");
std::string image_prefix = cwd + "/" + imagename;
std::vector<std::string> images;
for (auto ext : image_types) {
images.clear();
std::string ext_suffix = "." + ext;
std::string concat_imagename =
image_prefix + ext_suffix;
for (casacore::uInt j = 0; j < (casacore::uInt)num_workers; ++j) {
std::string component_imagename =
image_prefix + ".n" + std::to_string(j) + ext_suffix;
if (access(component_imagename.c_str(), F_OK) == 0)
images.push_back(component_imagename);
}
if (!images.empty()) {
std::string cmd = "imageconcat inimages='";
for (auto im : images) cmd += im + " ";
cmd += "' outimage='" + concat_imagename + "' type=";
cmd += type;
int rc = std::system(cmd.c_str());
if (rc == -1 || WEXITSTATUS(rc) != 0)
log << casacore::LogIO::WARN
<< ("concatenation of " + concat_imagename
+ " failed")
<< casacore::LogIO::POST;
}
}
}