FV3 Bundle
LocalizationBase.h
Go to the documentation of this file.
1 /*
2 * Copyright 2011 ECMWF
3 *
4 * This software was developed at ECMWF for evaluation
5 * and may be used for academic and research purposes only.
6 * The software is provided as is without any warranty.
7 *
8 * This software can be used, copied and modified but not
9 * redistributed or sold. This notice must be reproduced
10 * on each copy made.
11 */
12 
13 #ifndef OOPS_INTERFACE_LOCALIZATIONBASE_H_
14 #define OOPS_INTERFACE_LOCALIZATIONBASE_H_
15 
16 #include <mpi.h>
17 #include <map>
18 #include <string>
19 #include <boost/noncopyable.hpp>
20 
21 #include "eckit/config/Configuration.h"
24 #include "oops/util/abor1_cpp.h"
25 #include "oops/util/Printable.h"
26 
27 namespace oops {
28 
29 // -----------------------------------------------------------------------------
30 /// Base class for localizations
31 
32 template<typename MODEL>
33 class LocalizationBase : public util::Printable,
34  private boost::noncopyable {
36 
37  public:
39  virtual ~LocalizationBase() {}
40 
41  void multiply(Increment_ &) const;
42 
43  private:
44  virtual void multiply(typename MODEL::Increment &) const = 0;
45  virtual void print(std::ostream &) const = 0;
46 };
47 
48 // =============================================================================
49 
50 /// LocalizationFactory Factory
51 template <typename MODEL>
54  public:
55  static LocalizationBase<MODEL> * create(const Geometry_ &, const eckit::Configuration &);
56  virtual ~LocalizationFactory() { getMakers().clear(); }
57  protected:
58  explicit LocalizationFactory(const std::string &);
59  private:
60  virtual LocalizationBase<MODEL> * make(const Geometry_ &, const eckit::Configuration &) = 0;
61  static std::map < std::string, LocalizationFactory<MODEL> * > & getMakers() {
62  static std::map < std::string, LocalizationFactory<MODEL> * > makers_;
63  return makers_;
64  }
65 };
66 
67 // -----------------------------------------------------------------------------
68 
69 template<class MODEL, class T>
70 class LocalizationMaker : public LocalizationFactory<MODEL> {
72  virtual LocalizationBase<MODEL> * make(const Geometry_ & resol, const eckit::Configuration & conf)
73  { return new T(resol.geometry(), conf); }
74  public:
75  explicit LocalizationMaker(const std::string & name) : LocalizationFactory<MODEL>(name) {}
76 };
77 
78 // -----------------------------------------------------------------------------
79 
80 template <typename MODEL>
82  if (getMakers().find(name) != getMakers().end()) {
83  Log::error() << name << " already registered in localization factory." << std::endl;
84  ABORT("Element already registered in LocalizationFactory.");
85  }
86  getMakers()[name] = this;
87 }
88 
89 // -----------------------------------------------------------------------------
90 
91 template <typename MODEL>
93  const eckit::Configuration & conf) {
94  Log::trace() << "LocalizationBase<MODEL>::create starting" << std::endl;
95  const std::string id = conf.getString("localization");
96  typename std::map<std::string, LocalizationFactory<MODEL>*>::iterator
97  jloc = getMakers().find(id);
98  if (jloc == getMakers().end()) {
99  Log::trace() << id << " does not exist in localization factory." << std::endl;
100  ABORT("Element does not exist in LocalizationFactory.");
101  }
102  LocalizationBase<MODEL> * ptr = jloc->second->make(resol, conf);
103  Log::trace() << "LocalizationBase<MODEL>::create done" << std::endl;
104  return ptr;
105 }
106 
107 // -----------------------------------------------------------------------------
108 
109 template <typename MODEL>
111  Log::trace() << "LocalizationBase<MODEL>::multiply starting" << std::endl;
112  this->multiply(dx.increment());
113  Log::trace() << "LocalizationBase<MODEL>::multiply done" << std::endl;
114 }
115 
116 // -----------------------------------------------------------------------------
117 
118 } // namespace oops
119 
120 #endif // OOPS_INTERFACE_LOCALIZATIONBASE_H_
virtual LocalizationBase< MODEL > * make(const Geometry_ &resol, const eckit::Configuration &conf)
************************************************************************GNU Lesser General Public License **This file is part of the GFDL Flexible Modeling System(FMS). ! *! *FMS is free software without even the implied warranty of MERCHANTABILITY or *FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License *for more details **You should have received a copy of the GNU Lesser General Public *License along with FMS If see< http:! ***********************************************************************!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! MPP_TRANSMIT !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine MPP_TRANSMIT_(put_data, put_len, to_pe, get_data, get_len, from_pe, block, tag, recv_request, send_request)!a message-passing routine intended to be reminiscent equally of both MPI and SHMEM!put_data and get_data are contiguous MPP_TYPE_ arrays!at each call, your put_data array is put to to_pe 's get_data! your get_data array is got from from_pe 's put_data!i.e we assume that typically(e.g updating halo regions) each PE performs a put _and_ a get!special PE designations:! NULL_PE:to disable a put or a get(e.g at boundaries)! ANY_PE:if remote PE for the put or get is to be unspecific! ALL_PES:broadcast and collect operations(collect not yet implemented)!ideally we would not pass length, but this f77-style call performs better(arrays passed by address, not descriptor)!further, this permits< length > contiguous words from an array of any rank to be passed(avoiding f90 rank conformance check)!caller is responsible for completion checks(mpp_sync_self) before and after integer, intent(in) ::put_len, to_pe, get_len, from_pe MPP_TYPE_, intent(in) ::put_data(*) MPP_TYPE_, intent(out) ::get_data(*) logical, intent(in), optional ::block integer, intent(in), optional ::tag integer, intent(out), optional ::recv_request, send_request logical ::block_comm integer ::i MPP_TYPE_, allocatable, save ::local_data(:) !local copy used by non-parallel code(no SHMEM or MPI) integer ::comm_tag integer ::rsize if(.NOT.module_is_initialized) call mpp_error(FATAL, 'MPP_TRANSMIT:You must first call mpp_init.') if(to_pe.EQ.NULL_PE .AND. from_pe.EQ.NULL_PE) return block_comm=.true. if(PRESENT(block)) block_comm=block if(debug) then call SYSTEM_CLOCK(tick) write(stdout_unit,'(a, i18, a, i6, a, 2i6, 2i8)')&'T=', tick, ' PE=', pe, ' MPP_TRANSMIT begin:to_pe, from_pe, put_len, get_len=', to_pe, from_pe, put_len, get_len end if comm_tag=DEFAULT_TAG if(present(tag)) comm_tag=tag!do put first and then get if(to_pe.GE.0 .AND. to_pe.LT.npes) then!use non-blocking sends if(debug .and.(current_clock.NE.0)) call SYSTEM_CLOCK(start_tick)!z1l:truly non-blocking send.! if(request(to_pe).NE.MPI_REQUEST_NULL) then !only one message from pe-> to_pe in queue *PE waiting for to_pe ! call error else get_len so only do gets but you cannot have a pure get with MPI call a get means do a wait to ensure put on remote PE is complete error call increase mpp_nml request_multiply call MPP_TRANSMIT end
Definition: conf.py:1
character(len=32) name
The namespace for the main oops code.
LocalizationFactory Factory.
subroutine, public multiply(self, geom, xctl, xmod)
************************************************************************GNU Lesser General Public License **This file is part of the GFDL Flexible Modeling System(FMS). ! *! *FMS is free software without even the implied warranty of MERCHANTABILITY or *FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License *for more details **You should have received a copy of the GNU Lesser General Public *License along with FMS If see< http:! ***********************************************************************!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! MPP_TRANSMIT !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine MPP_TRANSMIT_(put_data, put_len, to_pe, get_data, get_len, from_pe, block, tag, recv_request, send_request)!a message-passing routine intended to be reminiscent equally of both MPI and SHMEM!put_data and get_data are contiguous MPP_TYPE_ arrays!at each call, your put_data array is put to to_pe 's get_data! your get_data array is got from from_pe 's put_data!i.e we assume that typically(e.g updating halo regions) each PE performs a put _and_ a get!special PE designations:! NULL_PE:to disable a put or a get(e.g at boundaries)! ANY_PE:if remote PE for the put or get is to be unspecific! ALL_PES:broadcast and collect operations(collect not yet implemented)!ideally we would not pass length, but this f77-style call performs better(arrays passed by address, not descriptor)!further, this permits< length > contiguous words from an array of any rank to be passed(avoiding f90 rank conformance check)!caller is responsible for completion checks(mpp_sync_self) before and after integer, intent(in) ::put_len, to_pe, get_len, from_pe MPP_TYPE_, intent(in) ::put_data(*) MPP_TYPE_, intent(out) ::get_data(*) logical, intent(in), optional ::block integer, intent(in), optional ::tag integer, intent(out), optional ::recv_request, send_request logical ::block_comm integer ::i MPP_TYPE_, allocatable, save ::local_data(:) !local copy used by non-parallel code(no SHMEM or MPI) integer ::comm_tag integer ::rsize if(.NOT.module_is_initialized) call mpp_error(FATAL, 'MPP_TRANSMIT:You must first call mpp_init.') if(to_pe.EQ.NULL_PE .AND. from_pe.EQ.NULL_PE) return block_comm=.true. if(PRESENT(block)) block_comm=block if(debug) then call SYSTEM_CLOCK(tick) write(stdout_unit,'(a, i18, a, i6, a, 2i6, 2i8)')&'T=', tick, ' PE=', pe, ' MPP_TRANSMIT begin:to_pe, from_pe, put_len, get_len=', to_pe, from_pe, put_len, get_len end if comm_tag=DEFAULT_TAG if(present(tag)) comm_tag=tag!do put first and then get if(to_pe.GE.0 .AND. to_pe.LT.npes) then!use non-blocking sends if(debug .and.(current_clock.NE.0)) call SYSTEM_CLOCK(start_tick)!z1l:truly non-blocking send.! if(request(to_pe).NE.MPI_REQUEST_NULL) then !only one message from pe-> to_pe in queue *PE waiting for to_pe ! call error else get_len so only do gets but you cannot have a pure get with MPI call a get means do a wait to ensure put on remote PE is complete error call increase mpp_nml request_multiply call MPP_TRANSMIT get_len end if return end subroutine MPP_TRANSMIT_ ! MPP_BROADCAST ! subroutine but that doesn t allow !broadcast to a subset of PEs This version and mpp_transmit will remain !backward compatible intent(inout) & T
integer error
Definition: mpp.F90:1310
Geometry< MODEL > Geometry_
Increment< MODEL > Increment_
Increment_ & increment()
Interfacing.
LocalizationMaker(const std::string &name)
static std::map< std::string, LocalizationFactory< MODEL > *> & getMakers()
void multiply(Increment_ &) const
LocalizationFactory(const std::string &)
const Geometry_ & geometry() const
Interfacing.
virtual LocalizationBase< MODEL > * make(const Geometry_ &, const eckit::Configuration &)=0
Base class for localizations.
Increment Class: Difference between two states.
Geometry< MODEL > Geometry_
virtual void print(std::ostream &) const =0
static LocalizationBase< MODEL > * create(const Geometry_ &, const eckit::Configuration &)