ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ParFunctions.H
Go to the documentation of this file.
1 #ifndef ERF_ParFunctions_H
2 #define ERF_ParFunctions_H
3 
4 /**
5  * Reduce a multifab to a vector of max values at each height
6  */
7 AMREX_FORCE_INLINE
8 void reduce_to_max_per_height (amrex::Vector<amrex::Real>& v,
9  std::unique_ptr<amrex::MultiFab>& mf)
10 {
11  amrex::MultiArray4<const amrex::Real> const& ma = mf->const_arrays();
12  for (int k = 0; k < v.size(); k++) {
13  v[k] = amrex::ParReduce(amrex::TypeList<amrex::ReduceOpMax>{},
14  amrex::TypeList<amrex::Real>{},
15  *mf,
16  amrex::IntVect(0),
17  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int) noexcept
18  -> amrex::GpuTuple<amrex::Real>
19  {
20  return { ma[box_no](i,j,k) };
21  });
22  }
23  amrex::ParallelDescriptor::ReduceRealMax(v.data(), v.size());
24 }
25 
26 #endif /* ERF_ParFunctions.H */
AMREX_FORCE_INLINE void reduce_to_max_per_height(amrex::Vector< amrex::Real > &v, std::unique_ptr< amrex::MultiFab > &mf)
Definition: ERF_ParFunctions.H:8