Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_HypreSolver.H
Go to the documentation of this file.
1
4
5#ifndef AMREX_HYPRE_SOLVER_H_
6#define AMREX_HYPRE_SOLVER_H_
7
8#include <AMReX_Geometry.H>
9#include <AMReX_iMultiFab.H>
10#include <AMReX_HypreIJIface.H>
11#include <AMReX_BLProfiler.H>
12
13#include "HYPRE.h"
14#include "_hypre_utilities.h"
15
16#include <string>
17
18namespace amrex
19{
20
29template <int MSS>
31{
32public:
33
60 template <class Marker, class Filler>
61 HypreSolver (Vector<IndexType> const& a_index_type,
62 IntVect const& a_nghost,
63 Geometry const& a_geom,
64 BoxArray const& a_grids,
65 DistributionMapping const& a_dmap, // NOLINT(modernize-pass-by-value)
66 Marker && a_marker,
67 Filler && a_filler,
68 int a_verbose = 0,
69 std::string a_options_namespace = "hypre");
70
80 template <FabArrayType MF>
81 requires (std::same_as<typename MF::value_type, HYPRE_Real>)
82 void solve (Vector<MF *> const& a_soln,
83 Vector<MF const*> const& a_rhs,
84 HYPRE_Real rel_tol, HYPRE_Real abs_tol, int max_iter);
85
87 int getNumIters () const { return m_hypre_ij->getNumIters(); }
88
90 HYPRE_Real getFinalResidualNorm () const {
91 return m_hypre_ij->getFinalResidualNorm();
92 }
93
95 HYPRE_IJMatrix getA () const { return m_hypre_ij->A(); }
97 HYPRE_IJVector getb () const { return m_hypre_ij->b(); }
99 HYPRE_IJVector getx () const { return m_hypre_ij->x(); }
100
101// public: // for cuda
102
106 template <class Marker>
107#ifdef AMREX_USE_CUDA
109#else
111#endif
112 void fill_local_id (Marker const& marker);
113
115 template <typename AI>
116 void fill_global_id ();
117
126 template <class Filler>
127 requires (IsCallable<Filler,int,int,int,int,int,
129 HYPRE_Int&, HYPRE_Int*,
130 HYPRE_Real*>::value)
131 void fill_matrix (Filler const& filler);
132
139 template <FabArrayType MF>
140 requires (std::same_as<typename MF::value_type, HYPRE_Real>)
141 void load_vectors (Vector<MF *> const& a_soln,
142 Vector<MF const*> const& a_rhs);
143
149 template <FabArrayType MF>
150 requires (std::same_as<typename MF::value_type, HYPRE_Real>)
151 void get_solution (Vector<MF*> const& a_soln);
152
153private:
154
155 int m_nvars;
156 Vector<IndexType> m_index_type;
157 IntVect m_nghost;
158 Geometry m_geom;
159 Vector<BoxArray> m_grids;
160 DistributionMapping m_dmap;
161
162 int m_verbose;
163 std::string m_options_namespace;
164
165 MPI_Comm m_comm = MPI_COMM_NULL;
166
168 Vector<iMultiFab> m_local_id;
171
172#ifdef AMREX_USE_GPU
174#endif
175
176 Vector<LayoutData<HYPRE_Int>> m_nrows_grid;
177 Vector<LayoutData<HYPRE_Int>> m_id_offset;
178 LayoutData<HYPRE_Int> m_nrows;
179 HYPRE_Int m_nrows_proc;
180
181 std::unique_ptr<HypreIJIface> m_hypre_ij;
182
183 // Non-owning references to HYPRE matrix, rhs, and solution data
184 HYPRE_IJMatrix m_A = nullptr;
185 HYPRE_IJVector m_b = nullptr;
186 HYPRE_IJVector m_x = nullptr;
187};
188
189template <int MSS>
190template <class Marker, class Filler>
192 IntVect const& a_nghost,
193 Geometry const& a_geom,
194 BoxArray const& a_grids,
195 DistributionMapping const& a_dmap, // NOLINT(modernize-pass-by-value)
196 Marker && a_marker,
197 Filler && a_filler,
198 int a_verbose,
199 std::string a_options_namespace)
200 : m_nvars (int(a_index_type.size())),
201 m_index_type (a_index_type),
202 m_nghost (a_nghost),
203 m_geom (a_geom),
204 m_dmap (a_dmap),
205 m_verbose (a_verbose),
206 m_options_namespace(std::move(a_options_namespace))
207{
208 BL_PROFILE("HypreSolver()");
209
210#ifdef AMREX_USE_MPI
211 m_comm = ParallelContext::CommunicatorSub(); // NOLINT(cppcoreguidelines-prefer-member-initializer)
212#endif
213
214 m_grids.resize(m_nvars);
215 m_local_id.resize(m_nvars);
216 m_global_id.resize(m_nvars);
217 m_nrows_grid.resize(m_nvars);
218 m_id_offset.resize(m_nvars);
219 Long nrows_max = 0;
220 for (int ivar = 0; ivar < m_nvars; ++ivar) {
221 m_grids [ivar] = amrex::convert(a_grids,m_index_type[ivar]);
222 m_local_id [ivar].define(m_grids[ivar], m_dmap, 1, 0);
223 m_global_id [ivar].define(m_grids[ivar], m_dmap, 1, m_nghost);
224 m_nrows_grid[ivar].define(m_grids[0], m_dmap);
225 m_id_offset [ivar].define(m_grids[0], m_dmap);
226 nrows_max += m_grids[ivar].numPts();
227 }
228 m_global_id_vec.define(m_grids[0], m_dmap);
229 m_nrows.define (m_grids[0], m_dmap);
230 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(nrows_max < static_cast<Long>(std::numeric_limits<HYPRE_Int>::max()-1),
231 "Need to configure Hypre with --enable-bigint");
232
233 m_owner_mask.resize(m_nvars);
234 for (int ivar = 0; ivar < m_nvars; ++ivar) {
235 m_owner_mask[ivar] = amrex::OwnerMask(m_local_id[ivar], m_geom.periodicity());
236 }
237
238#ifdef AMREX_USE_GPU
239 m_cell_offset.define(m_grids[0], m_dmap);
240#endif
241
242 fill_local_id(std::forward<Marker>(a_marker));
243
244 // At this point, m_local_id stores the ids local to each box.
245 // m_nrows_grid stores the number of unique points in each box.
246 // m_nrows_proc is the number of rowss for all variables on this MPI
247 // process. If a point is invalid, its id is invalid (i.e., a very
248 // negative number). Note that the data type of local_node_id is int,
249 // not HYPRE_Int for performance on GPU.
250
251 const int nprocs = ParallelContext::NProcsSub();
252 const int myproc = ParallelContext::MyProcSub();
253
254 Vector<HYPRE_Int> nrows_allprocs(nprocs);
255#ifdef AMREX_USE_MPI
256 if (nrows_allprocs.size() > 1) {
257 MPI_Allgather(&m_nrows_proc, sizeof(HYPRE_Int), MPI_CHAR,
258 nrows_allprocs.data(), sizeof(HYPRE_Int), MPI_CHAR, m_comm);
259 } else
260#endif
261 {
262 nrows_allprocs[0] = m_nrows_proc;
263 }
264
265 HYPRE_Int proc_begin = 0;
266 for (int i = 0; i < myproc; ++i) {
267 proc_begin += nrows_allprocs[i];
268 }
269
270 HYPRE_Int proc_end = proc_begin;
271 for (MFIter mfi(m_nrows_grid[0]); mfi.isValid(); ++mfi) {
272 for (int ivar = 0; ivar < m_nvars; ++ivar) {
273 m_id_offset[ivar][mfi] = proc_end;
274 proc_end += m_nrows_grid[ivar][mfi];
275 }
276 }
277 AMREX_ASSERT(proc_end == proc_begin + m_nrows_proc);
278
279 // To generate global ids for HYPRE, we need to remove duplicates on
280 // nodes shared by multiple Boxes with OverrideSync. So we need to use
281 // a type that supports atomicAdd. HYPRE_Int is either int or long
282 // long. The latter (i.e., long long) does not have native atomicAdd
283 // support in CUDA/HIP, whereas unsigned long long has.
284 using AtomicInt = std::conditional_t<sizeof(HYPRE_Int) == 4,
285 HYPRE_Int, unsigned long long>;
287
288 // Create and initialize A, b & x
289 HYPRE_Int ilower = proc_begin;
290 HYPRE_Int iupper = proc_end-1;
291 m_hypre_ij = std::make_unique<HypreIJIface>(m_comm, ilower, iupper, m_verbose);
292 m_hypre_ij->setRecomputePreconditioner(false); // fill_matrix calls setNeedSetup
293 m_hypre_ij->parse_inputs(m_options_namespace);
294
295 // Obtain non-owning references to the matrix, rhs, and solution data
296 m_A = m_hypre_ij->A();
297 m_b = m_hypre_ij->b();
298 m_x = m_hypre_ij->x();
299
300 fill_matrix(std::forward<Filler>(a_filler));
301}
302
303template <int MSS>
304template <class Marker>
305#ifdef AMREX_USE_CUDA
307#else
309#endif
310void HypreSolver<MSS>::fill_local_id (Marker const& marker)
311{
312 BL_PROFILE("HypreSolver::fill_local_id()");
313
314#ifdef AMREX_USE_GPU
315
316 for (MFIter mfi(m_local_id[0]); mfi.isValid(); ++mfi) {
317 int boxno = mfi.LocalIndex();
318 Long npts_tot = 0;
319 for (int ivar = 0; ivar < m_nvars; ++ivar) {
320 Box const& bx = amrex::convert(mfi.validbox(),m_index_type[ivar]);
321 npts_tot += bx.numPts();
322 }
323 m_cell_offset[mfi].resize(npts_tot);
324 npts_tot = 0;
325 int* p_cell_offset = m_cell_offset[mfi].data();
326 for (int ivar = 0; ivar < m_nvars; ++ivar) {
327 Box const& bx = amrex::convert(mfi.validbox(),m_index_type[ivar]);
328 auto const& lid = m_local_id[ivar].array(mfi);
329 auto const& owner = m_owner_mask[ivar]->const_array(mfi);
330 AMREX_ASSERT(bx.numPts() < static_cast<Long>(std::numeric_limits<int>::max()));
331 const auto npts = static_cast<int>(bx.numPts());
332 int npts_box = amrex::Scan::PrefixSum<int>(npts,
333 [=] AMREX_GPU_DEVICE (int offset) noexcept -> int
334 {
335 const Dim3 cell = bx.atOffset(offset).dim3();
336 int id = (owner ( cell.x,cell.y,cell.z ) &&
337 marker(boxno,cell.x,cell.y,cell.z,ivar)) ? 1 : 0;
338 lid(cell.x,cell.y,cell.z) = id;
339 return id;
340 },
341 [=] AMREX_GPU_DEVICE (int offset, int ps) noexcept
342 {
343 const Dim3 cell = bx.atOffset(offset).dim3();
344 if (lid(cell.x,cell.y,cell.z)) {
345 lid(cell.x,cell.y,cell.z) = ps;
346 p_cell_offset[ps] = offset;
347 } else {
348 lid(cell.x,cell.y,cell.z) = std::numeric_limits<int>::lowest();
349 }
350 },
352 m_nrows_grid[ivar][mfi] = npts_box;
353 npts_tot += npts_box;
354 p_cell_offset += npts_box;
355 }
356 m_cell_offset[mfi].resize(npts_tot);
357 }
358
359#else
360
361#ifdef AMREX_USE_OMP
362#pragma omp parallel
363#endif
364 for (MFIter mfi(m_local_id[0]); mfi.isValid(); ++mfi) {
365 int boxno = mfi.LocalIndex();
366 for (int ivar = 0; ivar < m_nvars; ++ivar) {
367 Box const& bx = amrex::convert(mfi.validbox(),m_index_type[ivar]);
368 auto const& lid = m_local_id[ivar].array(mfi);
369 auto const& owner = m_owner_mask[ivar]->const_array(mfi);
370 int id = 0;
371 const auto lo = amrex::lbound(bx);
372 const auto hi = amrex::ubound(bx);
373 for (int k = lo.z; k <= hi.z; ++k) {
374 for (int j = lo.y; j <= hi.y; ++j) {
375 for (int i = lo.x; i <= hi.x; ++i) {
376 if (owner(i,j,k) && marker(boxno,i,j,k,ivar)) {
377 lid(i,j,k) = id++;
378 } else {
379 lid(i,j,k) = std::numeric_limits<int>::lowest();
380 }
381 }}}
382 m_nrows_grid[ivar][mfi] = id;
383 }
384 }
385#endif
386
387 m_nrows_proc = 0;
388 for (MFIter mfi(m_nrows); mfi.isValid(); ++mfi) {
389 int nrows = 0;
390 for (int ivar = 0; ivar < m_nvars; ++ivar) {
391 nrows += m_nrows_grid[ivar][mfi];
392 }
393 m_nrows[mfi] = nrows;
394 m_nrows_proc += nrows;
395 }
396}
397
398template <int MSS>
399template <typename AI>
400void
402{
403 BL_PROFILE("HypreSolver::fill_global_id()");
404
405 Vector<FabArray<BaseFab<AI>>> global_id_raii;
406 Vector<FabArray<BaseFab<AI>>*> p_global_id;
407
408 if constexpr (std::is_same_v<HYPRE_Int,AI>) {
409 for (int ivar = 0; ivar < m_nvars; ++ivar) {
410 p_global_id.push_back(&(m_global_id[ivar]));
411 }
412 } else {
413 // Reserve so that the pointers taken below stay valid.
414 global_id_raii.reserve(m_nvars);
415 for (int ivar = 0; ivar < m_nvars; ++ivar) {
416 global_id_raii.emplace_back(m_global_id[ivar].boxArray(),
417 m_global_id[ivar].DistributionMap(),
418 1, m_global_id[ivar].nGrowVect(),
419 MFInfo().SetArena(The_Async_Arena()));
420 p_global_id.push_back(&(global_id_raii[ivar]));
421 }
422 }
423
424#ifdef AMREX_USE_OMP
425#pragma omp parallel if (Gpu::notInLaunchRegion())
426#endif
427 for (MFIter mfi(m_global_id[0]); mfi.isValid(); ++mfi) {
428 auto& rows_vec = m_global_id_vec[mfi];
429 rows_vec.resize(m_nrows[mfi]);
430
431 HYPRE_Int nrows = 0;
432 for (int ivar = 0; ivar < m_nvars; ++ivar) {
433 HYPRE_Int const os = m_id_offset[ivar][mfi];
434 Box bx = mfi.validbox();
435 bx.convert(m_index_type[ivar]).grow(m_nghost);
436 Array4<AI> const& gid = p_global_id[ivar]->array(mfi);
437 auto const& lid = m_local_id[ivar].const_array(mfi);
438 HYPRE_Int* rows = rows_vec.data() + nrows;
439 nrows += m_nrows_grid[ivar][mfi];
440 amrex::ParallelFor(bx,[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
441 {
442 if (lid.contains(i,j,k) && lid(i,j,k) >= 0) {
443 const auto id = lid(i,j,k) + os;
444 rows[lid(i,j,k)] = id;
445 gid(i,j,k) = static_cast<AI>(id);
446 } else {
447 gid(i,j,k) = static_cast<AI>
448 (std::numeric_limits<HYPRE_Int>::max());
449 }
450 });
451 }
452 }
453
454 for (int ivar = 0; ivar < m_nvars; ++ivar) {
455 amrex::OverrideSync(*p_global_id[ivar], *m_owner_mask[ivar],
456 m_geom.periodicity());
457 p_global_id[ivar]->FillBoundary(m_geom.periodicity());
458
459 if constexpr (!std::is_same<HYPRE_Int, AI>()) {
460 auto const& dst = m_global_id[ivar].arrays();
461 auto const& src = p_global_id[ivar]->const_arrays();
462 amrex::ParallelFor(m_global_id[ivar], m_global_id[ivar].nGrowVect(),
463 [=] AMREX_GPU_DEVICE (int b, int i, int j, int k)
464 {
465 dst[b](i,j,k) = static_cast<HYPRE_Int>(src[b](i,j,k));
466 });
467 }
468 }
469}
470
471#ifdef AMREX_USE_GPU
473namespace detail {
474template <typename T>
475void pack_matrix_gpu (Gpu::DeviceVector<HYPRE_Int>& cols_tmp,
479{
480 auto* p_cols_tmp = cols_tmp.data();
481 auto* p_mat_tmp = mat_tmp.data();
482 auto const* p_cols = cols.data();
483 auto const* p_mat = mat.data();
484 const auto N = Long(cols.size());
486 [=] AMREX_GPU_DEVICE (Long i) -> T
487 {
488 return static_cast<T>(p_cols[i] >= 0);
489 },
490 [=] AMREX_GPU_DEVICE (Long i, T s)
491 {
492 if (p_cols[i] >= 0) {
493 p_cols_tmp[s] = p_cols[i];
494 p_mat_tmp[s] = p_mat[i];
495 }
496 },
498 std::swap(cols_tmp, cols);
499 std::swap(mat_tmp, mat);
500}
501}
503#endif
504
505template <int MSS>
506template <class Filler>
507requires (IsCallable<Filler,int,int,int,int,int,
509 HYPRE_Int&, HYPRE_Int*,
510 HYPRE_Real*>::value)
511void
512HypreSolver<MSS>::fill_matrix (Filler const& filler)
513{
514 BL_PROFILE("HypreSolver::fill_matrix()");
515
519
520 MFItInfo mfitinfo;
522 for (MFIter mfi(m_local_id[0],mfitinfo); mfi.isValid(); ++mfi)
523 {
524 int boxno = mfi.LocalIndex();
525 const HYPRE_Int nrows = m_nrows[mfi];
526 if (nrows > 0)
527 {
528 ncols_vec.clear();
529 ncols_vec.resize(nrows);
530 HYPRE_Int* ncols = ncols_vec.data();
531
532 cols_vec.clear();
533 cols_vec.resize(Long(nrows)*MSS, -1);
534 HYPRE_Int* cols = cols_vec.data();
535
536 mat_vec.clear();
537 mat_vec.resize(Long(nrows)*MSS);
538 HYPRE_Real* mat = mat_vec.data();
539
540 Vector<Array4<HYPRE_Int const>> gid_v(m_nvars);
541 for (int ivar = 0; ivar < m_nvars; ++ivar) {
542 gid_v[ivar] = m_global_id[ivar].const_array(mfi);
543 }
544
545#ifdef AMREX_USE_GPU
547 (gid_v.data(), gid_v.size());
548 auto const* pgid = gid_buf.data();
549 auto const* p_cell_offset = m_cell_offset[mfi].data();
550 Long ntot = 0;
551 for (int ivar = 0; ivar < m_nvars; ++ivar) {
552 const HYPRE_Int nrows_var = m_nrows_grid[ivar][mfi];
553 if (nrows_var > 0) {
554 Box const& bx = amrex::convert(mfi.validbox(),m_index_type[ivar]);
555 ntot += Reduce::Sum<Long>(nrows_var,
556 [=] AMREX_GPU_DEVICE (HYPRE_Int offset)
557 {
558 const Dim3 cell = bx.atOffset(p_cell_offset[offset]).dim3();
559 filler(boxno, cell.x, cell.y, cell.z, ivar, pgid,
560 ncols[offset], cols+Long(offset)*MSS,
561 mat+Long(offset)*MSS);
562 return ncols[offset];
563 });
564 p_cell_offset += nrows_var;
565 ncols += nrows_var;
566 cols += Long(nrows_var)*MSS;
567 mat += Long(nrows_var)*MSS;
568 }
569 }
570 Gpu::DeviceVector<HYPRE_Int> cols_tmp(ntot);
571 Gpu::DeviceVector<HYPRE_Real> mat_tmp(ntot);
572 if (ntot >= Long(std::numeric_limits<int>::max())) {
573 detail::pack_matrix_gpu<Long>(cols_tmp, mat_tmp, cols_vec, mat_vec);
574 } else {
575 detail::pack_matrix_gpu<int>(cols_tmp, mat_tmp, cols_vec, mat_vec);
576 }
577#else
578 auto* pgid = gid_v.data();
579 for (int ivar = 0; ivar < m_nvars; ++ivar) {
580 if (m_nrows_grid[ivar][mfi] > 0) {
581 auto const& lid = m_local_id[ivar].const_array(mfi);
582 amrex::Loop(amrex::convert(mfi.validbox(),m_index_type[ivar]),
583 [=,&ncols,&cols,&mat] (int i, int j, int k)
584 {
585 if (lid(i,j,k) >= 0) {
586 filler(boxno, i, j, k, ivar, pgid, *ncols, cols, mat);
587 cols += (*ncols);
588 mat += (*ncols);
589 ++ncols;
590 }
591 });
592 }
593 }
594#endif
595
596 const auto& rows_vec = m_global_id_vec[mfi];
597 HYPRE_Int const* rows = rows_vec.data();
598
600 HYPRE_IJMatrixSetValues(m_A, nrows, ncols_vec.data(), rows,
601 cols_vec.data(), mat_vec.data());
602 Gpu::hypreSynchronize();
603 }
604 }
605 HYPRE_IJMatrixAssemble(m_A);
606 m_hypre_ij->setNeedSetup();
607}
608
609template <int MSS>
610template <FabArrayType MF>
611requires (std::same_as<typename MF::value_type, HYPRE_Real>)
612void
614 Vector<MF const*> const& a_rhs,
615 HYPRE_Real rel_tol, HYPRE_Real abs_tol, int max_iter)
616{
617 BL_PROFILE("HypreSolver::solve()");
618
619 AMREX_ASSERT(a_soln.size() == m_nvars && a_rhs.size() == m_nvars);
620
621 HYPRE_IJVectorInitialize(m_b);
622 HYPRE_IJVectorInitialize(m_x);
623
624 load_vectors(a_soln, a_rhs);
625
626 HYPRE_IJVectorAssemble(m_x);
627 HYPRE_IJVectorAssemble(m_b);
628
629 m_hypre_ij->solve(rel_tol, abs_tol, max_iter);
630
631 get_solution(a_soln);
632}
633
634template <int MSS>
635template <FabArrayType MF>
636requires (std::same_as<typename MF::value_type, HYPRE_Real>)
637void
639 Vector<MF const*> const& a_rhs)
640{
641 BL_PROFILE("HypreSolver::load_vectors()");
642
643 MFItInfo mfitinfo;
645
648 for (MFIter mfi(*a_soln[0],mfitinfo); mfi.isValid(); ++mfi)
649 {
650 const HYPRE_Int nrows = m_nrows[mfi];
651 if (nrows > 0)
652 {
653 xvec.clear();
654 xvec.resize(nrows);
655 bvec.clear();
656 bvec.resize(nrows);
657 auto* xp = xvec.data();
658 auto* bp = bvec.data();
659
660 HYPRE_Int const* rows = m_global_id_vec[mfi].data();
661
662 HYPRE_Int offset = 0;
663 for (int ivar = 0; ivar < m_nvars; ++ivar) {
664 if (m_nrows_grid[ivar][mfi] > 0) {
665 auto const& xfab = a_soln[ivar]->const_array(mfi);
666 auto const& bfab = a_rhs [ivar]->const_array(mfi);
667 auto const& lid = m_local_id[ivar].const_array(mfi);
668 HYPRE_Real* x = xp + offset;
669 HYPRE_Real* b = bp + offset;
670 Box box = amrex::convert(mfi.validbox(),m_index_type[ivar]);
671 amrex::ParallelFor(box,[=] AMREX_GPU_DEVICE (int i, int j, int k)
672 {
673 if (lid(i,j,k) >= 0) {
674 x[lid(i,j,k)] = xfab(i,j,k);
675 b[lid(i,j,k)] = bfab(i,j,k);
676 }
677 });
678 offset += m_nrows_grid[ivar][mfi];
679 }
680 }
681
683 HYPRE_IJVectorSetValues(m_x, nrows, rows, xp);
684 HYPRE_IJVectorSetValues(m_b, nrows, rows, bp);
685 Gpu::hypreSynchronize();
686 }
687 }
688}
689
690template <int MSS>
691template <FabArrayType MF>
692requires (std::same_as<typename MF::value_type, HYPRE_Real>)
693void
695{
696 BL_PROFILE("HypreSolver::get_solution()");
697
698 MFItInfo mfitinfo;
700
702 for (MFIter mfi(*a_soln[0],mfitinfo); mfi.isValid(); ++mfi)
703 {
704 const HYPRE_Int nrows = m_nrows[mfi];
705 if (nrows > 0)
706 {
707 xvec.clear();
708 xvec.resize(nrows);
709 auto* xp = xvec.data();
710
711 HYPRE_Int const* rows = m_global_id_vec[mfi].data();
712
713 HYPRE_IJVectorGetValues(m_x, nrows, rows, xp);
714 Gpu::hypreSynchronize();
715
716 HYPRE_Int offset = 0;
717 for (int ivar = 0; ivar < m_nvars; ++ivar) {
718 if (m_nrows_grid[ivar][mfi] > 0) {
719 auto const& xfab = a_soln[ivar]->array(mfi);
720 auto const& lid = m_local_id[ivar].const_array(mfi);
721 HYPRE_Real* x = xp + offset;
722 Box box = amrex::convert(mfi.validbox(),m_index_type[ivar]);
723 amrex::ParallelFor(box,[=] AMREX_GPU_DEVICE (int i, int j, int k)
724 {
725 if (lid(i,j,k) >= 0) {
726 xfab(i,j,k) = x[lid(i,j,k)];
727 }
728 });
729 offset += m_nrows_grid[ivar][mfi];
730 }
731 }
733 }
734 }
735
736 for (int ivar = 0; ivar < m_nvars; ++ivar) {
737 amrex::OverrideSync(*a_soln[ivar], *m_owner_mask[ivar],
738 m_geom.periodicity());
739 }
740}
741
742}
743
744#endif
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
Problem-domain geometry: maps between index space and physical space.
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:681
__host__ __device__ BoxND & grow(int i) noexcept
Grow in all directions by i cells (negative shrinks).
Definition AMReX_Box.H:668
__host__ __device__ Long numPts() const noexcept
Return the number of points contained in the BoxND.
Definition AMReX_Box.H:385
__host__ __device__ BoxND & convert(IndexTypeND< dim > typ) noexcept
Convert the BoxND from the current type into the argument type. This may change the BoxND coordinates...
Definition AMReX_Box.H:1008
__host__ __device__ IntVectND< dim > atOffset(Long offset) const noexcept
Given the offset, compute IntVectND<dim>.
Definition AMReX_Box.H:1105
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:55
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:87
Definition AMReX_GpuBuffer.H:24
T const * data() const noexcept
Definition AMReX_GpuBuffer.H:51
HypreSolver(Vector< IndexType > const &a_index_type, IntVect const &a_nghost, Geometry const &a_geom, BoxArray const &a_grids, DistributionMapping const &a_dmap, Marker &&a_marker, Filler &&a_filler, int a_verbose=0, std::string a_options_namespace="hypre")
Definition AMReX_HypreSolver.H:191
void load_vectors(Vector< MF * > const &a_soln, Vector< MF const * > const &a_rhs)
Copy AMReX RHS/initial guess data into the IJ vectors.
Definition AMReX_HypreSolver.H:638
int getNumIters() const
Number of iterations from the last solve().
Definition AMReX_HypreSolver.H:87
void solve(Vector< MF * > const &a_soln, Vector< MF const * > const &a_rhs, HYPRE_Real rel_tol, HYPRE_Real abs_tol, int max_iter)
Solve Ax=b after the constructor assembled the IJ matrix.
Definition AMReX_HypreSolver.H:613
HYPRE_IJVector getx() const
Access the IJ solution handle (non-owning).
Definition AMReX_HypreSolver.H:99
HYPRE_IJMatrix getA() const
Access the assembled IJ matrix handle (non-owning).
Definition AMReX_HypreSolver.H:95
void fill_matrix(Filler const &filler)
Fill each CSR row using the supplied filler functor.
Definition AMReX_HypreSolver.H:512
void fill_local_id(Marker const &marker)
Assign local ids to each owned DOF by invoking marker.
Definition AMReX_HypreSolver.H:310
void get_solution(Vector< MF * > const &a_soln)
Copy IJ solution entries back into AMReX storage.
Definition AMReX_HypreSolver.H:694
void fill_global_id()
Convert the local ids to globally unique ids visible to HYPRE.
Definition AMReX_HypreSolver.H:401
HYPRE_Real getFinalResidualNorm() const
Final residual norm from the last solve().
Definition AMReX_HypreSolver.H:90
HYPRE_IJVector getb() const
Access the assembled IJ RHS handle (non-owning).
Definition AMReX_HypreSolver.H:97
a one-thingy-per-box distributed object
Definition AMReX_LayoutData.H:13
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:88
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:176
size_type size() const noexcept
Definition AMReX_PODVector.H:654
void resize(size_type a_new_size, GrowthStrategy strategy=GrowthStrategy::Poisson)
Definition AMReX_PODVector.H:734
void clear() noexcept
Definition AMReX_PODVector.H:652
T * data() noexcept
Definition AMReX_PODVector.H:672
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
Long size() const noexcept
Definition AMReX_Vector.H:54
amrex_long Long
Definition AMReX_INT.H:30
T Sum(N n, T const *v, T init_val=0)
Compute the sum of an array of values.
Definition AMReX_Reduce.H:1082
__host__ __device__ Dim3 ubound(Array4< T > const &a) noexcept
Return the inclusive upper bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1377
ArrayND< T, 4, true > Array4
Convenient alias for a 4D ArrayND with three spatial dimensions plus a component dimension.
Definition AMReX_Array4.H:1352
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1363
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a copy of b converted to the nodal flags typ.
Definition AMReX_Box.H:1632
PODVector< T, ArenaAllocator< T > > DeviceVector
A PODVector that uses the standard memory Arena. Note that the memory might or might not be managed d...
Definition AMReX_GpuContainers.H:24
Arena * The_Async_Arena()
Definition AMReX_Arena.cpp:849
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:329
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
int MyProcSub() noexcept
my sub-rank in current frame
Definition AMReX_ParallelContext.H:76
int NProcsSub() noexcept
number of ranks in current frame
Definition AMReX_ParallelContext.H:74
static constexpr struct amrex::Scan::Type::Exclusive exclusive
static constexpr RetSum noRetSum
Definition AMReX_Scan.H:35
T PrefixSum(N n, FIN const &fin, FOUT const &fout, TYPE, RetSum a_ret_sum=retSum)
Definition AMReX_Scan.H:815
int MPI_Comm
Definition AMReX_ccse-mpi.H:51
static constexpr int MPI_COMM_NULL
Definition AMReX_ccse-mpi.H:59
Definition AMReX_Amr.cpp:50
BoxArray const & boxArray(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.boxArray().
Definition AMReX_FabArrayBase.cpp:3038
DistributionMapping const & DistributionMap(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.DistributionMap().
Definition AMReX_FabArrayBase.cpp:3043
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
std::unique_ptr< iMultiFab > OwnerMask(FabArrayBase const &mf, const Periodicity &period, const IntVect &ngrow)
Definition AMReX_iMultiFab.cpp:706
@ x
Definition AMReX_Orientation.H:14
IntVect nGrowVect(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.nGrowVect().
Definition AMReX_FabArrayBase.cpp:3033
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
const int[]
Definition AMReX_BLProfiler.cpp:1665
__host__ __device__ void Loop(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition AMReX_Loop.H:127
void OverrideSync(FabArray< FAB > &fa, FabArray< IFAB > const &msk, const Periodicity &period)
Synchronize shared nodal values using an owner mask.
Definition AMReX_FabArrayUtility.H:1656
A simple struct holding 3 int values for a 3D index.
Definition AMReX_Dim3.H:24
int x
Definition AMReX_Dim3.H:24
int z
Definition AMReX_Dim3.H:24
int y
Definition AMReX_Dim3.H:24
Test if a given type T is callable with arguments of type Args...
Definition AMReX_TypeTraits.H:214
Test if a given type T is callable with arguments of type Args...
Definition AMReX_TypeTraits.H:208
FabArray memory allocation information.
Definition AMReX_FabArray.H:73
Definition AMReX_MFIter.H:20
MFItInfo & DisableDeviceSync() noexcept
Definition AMReX_MFIter.H:47
MFItInfo & UseDefaultStream() noexcept
Definition AMReX_MFIter.H:75