LCOV - code coverage report
Current view: top level - synthesis/Parallel - Applicator.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 17 0.0 %
Date: 2024-10-28 15:53:10 Functions: 0 17 0.0 %

          Line data    Source code
       1             : //# Applicator.h: interface to parallelization infrastructure
       2             : //# Copyright (C) 1999,2000
       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: casa-feedback@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             : //#
      27             : //# $Id$
      28             : 
      29             : #ifndef SYNTHESIS_APPLICATOR_H
      30             : #define SYNTHESIS_APPLICATOR_H
      31             : 
      32             : //# Includes
      33             : 
      34             : #include <map>
      35             : #include <casacore/casa/aips.h>
      36             : #include <casacore/casa/Arrays/Vector.h>
      37             : #include <casacore/lattices/Lattices/Lattice.h>
      38             : #include <casacore/casa/Containers/Record.h>
      39             : #include <synthesis/Parallel/PTransport.h>
      40             : 
      41             : namespace casa { //# NAMESPACE CASA - BEGIN
      42             : 
      43             : //# Forward Declarations
      44             : class Algorithm;
      45             : 
      46             : // <summary>
      47             : // Class which provides an interface to the parallelization infrastructure
      48             : // </summary>
      49             : 
      50             : // <use visibility=local>
      51             : 
      52             : // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
      53             : // </reviewed>
      54             : 
      55             : // <prerequisite>
      56             : //   <li> Algorithm
      57             : //   <li> PTransport
      58             : // </prerequisite>
      59             : //
      60             : // <etymology>
      61             : // Applies or controls the execution of parallelized algorithms.
      62             : // </etymology>
      63             : //
      64             : // <synopsis>
      65             : // The Applicator class provides the interface to parallel communication.
      66             : // It holds the parallel transport layer, and controls the execution of
      67             : // parallelized algorithms.
      68             : // </synopsis>
      69             : //
      70             : // <example>
      71             : // </example>
      72             : //
      73             : // <motivation>
      74             : // To provide a simple programming interface to parallelization, and
      75             : // to encapsulate the transport layer and parallel process control.
      76             : // </motivation>
      77             : //
      78             : //# <thrown>
      79             : //#    <li>
      80             : //#    <li>
      81             : //# </thrown>
      82             : //
      83             : //# <todo asof="1999/12/21">
      84             : //#   <li> Document
      85             : //# </todo>
      86             : 
      87             : 
      88             : class Applicator {
      89             :  public:
      90             :   // Enum to define the process status table
      91             :   enum Status {FREE, ASSIGNED};
      92             : 
      93             :   // Recognized signals
      94             :   enum Signals {STOP = 0, DONE = -1};
      95             : 
      96             :   // Default constructor, and destructor
      97             :   Applicator();
      98             :   ~Applicator();
      99             : 
     100             :   // Initialization (includes parallel transport initialization)
     101             :   void init(casacore::Int argc, casacore::Char *argv[]);
     102             :   void initThreads(casacore::Int argc, casacore::Char *argv[]);
     103             :   void initThreads();
     104             :   // release workers from loop
     105             :   void destroyThreads();
     106             :   // tells you if initThreads(argc,  argv) version has been called already
     107             :   // MPI does not like more than 1 call to MPI_Init or MPI_InitThread
     108             :   bool initialized();
     109             :   // define an Algorithm if we need too; takes ownership of the alg pointer
     110             :   void defineAlgorithm(Algorithm *);
     111             : 
     112             :   // Status functions to indicate whether this Applicator is
     113             :   // executing as a controller or worker process
     114             :   casacore::Bool isController();
     115             :   casacore::Bool isWorker();
     116             : 
     117             :   // true if executing serially
     118           0 :   casacore::Bool isSerial() {return serial;};
     119             : 
     120             :   // Return the number of processes
     121           0 :   casacore::Int numProcs() {return nProcs;};
     122             : 
     123             :   // Assign the next free worker process to a specified Algorithm
     124             :   casacore::Bool nextAvailProcess(Algorithm &a, casacore::Int &rank);
     125             : 
     126             :   // Return the rank of the next process to complete the specified Algorithm
     127             :   casacore::Int nextProcessDone(Algorithm &a, casacore::Bool &allDone);
     128             : 
     129             :   // Signal that a worker process is done
     130             :   void done();
     131             : 
     132             :   // Execute an algorithm directly
     133             :   void apply(Algorithm &a);
     134             : 
     135             :   // Put and get methods to be executed on the parallel transport layer
     136           0 :   casacore::Int put(const casacore::Array<casacore::Float> &an) {return comm->put(an);};
     137             :   casacore::Int put(const casacore::Array<casacore::Double> &an) {return comm->put(an);};
     138           0 :   casacore::Int put(const casacore::Array<casacore::Int> &an) {return comm->put(an);};
     139             :   casacore::Int put(const casacore::Array<casacore::Complex> &an) {return comm->put(an);};
     140             :   casacore::Int put(const casacore::Array<casacore::DComplex> &an) {return comm->put(an);};
     141           0 :   casacore::Int put(const casacore::Float &n) {return comm->put(n);};
     142             :   casacore::Int put(const casacore::Complex &n) {return comm->put(n);};
     143             :   casacore::Int put(const casacore::DComplex &n) {return comm->put(n);};
     144             :   casacore::Int put(const casacore::Double &n) {return comm->put(n);};
     145           0 :   casacore::Int put(const casacore::Int &n) {return comm->put(n);};
     146           0 :   casacore::Int put(const casacore::Bool &b) {return comm->put(b);};
     147           0 :   casacore::Int put(const casacore::String &s) {return comm->put(s);};
     148           0 :   casacore::Int put(const casacore::Record &r) {return comm->put(r);};
     149             : 
     150           0 :   casacore::Int get(casacore::Array<casacore::Float> &an) {return comm->get(an);};
     151             :   casacore::Int get(casacore::Array<casacore::Double> &an) {return comm->get(an);};
     152             :   casacore::Int get(casacore::Array<casacore::Complex> &an) {return comm->get(an);};
     153             :   casacore::Int get(casacore::Array<casacore::DComplex> &an) {return comm->get(an);};
     154           0 :   casacore::Int get(casacore::Array<casacore::Int> &an) {return comm->get(an);};
     155           0 :   casacore::Int get(casacore::Float &n) {return comm->get(n);};
     156             :   casacore::Int get(casacore::Double &n) {return comm->get(n);};
     157           0 :   casacore::Int get(casacore::Complex &n) {return comm->get(n);};
     158             :   casacore::Int get(casacore::DComplex &n) {return comm->get(n);};
     159           0 :   casacore::Int get(casacore::Int &n) {return comm->get(n);};
     160           0 :   casacore::Int get(casacore::Bool &b) {return comm->get(b);};
     161           0 :   casacore::Int get(casacore::String &s) {return comm->get(s);};
     162           0 :   casacore::Int get(casacore::Record &r) {return comm->get(r);};
     163             : 
     164             :  private:
     165             :   // Pointer to the parallel transport
     166             :   PTransport *comm;
     167             : 
     168             :   // casacore::Map of known algorithm names and id.'s
     169             :   std::map<casacore::String, casacore::Int> algorithmIds;
     170             :   std::map<casacore::Int, Algorithm*> knownAlgorithms;
     171             : 
     172             :   // ID for the last Algorithm defined.
     173             :   casacore::Int LastID;
     174             : 
     175             :   // true if no more processes are free
     176             :   casacore::Bool usedAllThreads;
     177             : 
     178             :   // true if executing in serial
     179             :   casacore::Bool serial;
     180             : 
     181             :   // Number of processes
     182             :   casacore::Int nProcs;
     183             : 
     184             :   // Process status list
     185             :   casacore::Vector<casacore::Int> procStatus;
     186             : 
     187             :   // Executed by worker process waiting for an assigned task
     188             :   void loop();
     189             : 
     190             :   // Fill algorithm map
     191             :   void defineAlgorithms();
     192             : 
     193             :   // Utility functions for the current list of processes, and their status
     194             :   void setupProcStatus();
     195             :   casacore::Int findFreeProc(casacore::Bool &lastOne);
     196             : 
     197             :   bool debug_p = false;
     198             :   bool initialized_p;
     199             :   casacore::Int donesig_p; //have to keep in context in serial case
     200             : };
     201             : 
     202             : 
     203             : } //# NAMESPACE CASA - END
     204             : 
     205             : #endif
     206             : 
     207             : 
     208             : 
     209             : 

Generated by: LCOV version 1.16