Skip to content

Commit

Permalink
fix a tutorial for dpc++ (and cuda) (AMReX-Codes#1038)
Browse files Browse the repository at this point in the history
* fix a tutorial for dpc++ (and cuda)

* Fix code block alignment

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
  • Loading branch information
WeiqunZhang and ax3l authored Jun 19, 2020
1 parent cc65bd6 commit e16f97e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Tutorials/LinearSolvers/MultiComponent/MCNodalLinOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ void MCNodalLinOp::Fapply (int amrlev, int mglev, MultiFab& a_out,const MultiFab
domain.grow(-1); // Shrink domain so we don't operate on any boundaries
const Real* DX = m_geom[amrlev][mglev].CellSize();

amrex::AsyncArray<Real> aa(coeff.data(), coeff.size());
amrex::Real const* dcoeff = aa.data();
const int N = getNComp();

for (MFIter mfi(a_out, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
Box bx = mfi.tilebox();
Expand All @@ -43,9 +47,9 @@ void MCNodalLinOp::Fapply (int amrlev, int mglev, MultiFab& a_out,const MultiFab
for (int n = 0; n < getNComp(); n++)
amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) {
out(i,j,k,n) = 0.0;
for (int m = 0; m < getNComp(); m++)
for (int m = 0; m < N; m++)
{
out(i,j,k,n) += coeff[ncomp*n + m] *
out(i,j,k,n) += dcoeff[ncomp*n + m] *
( AMREX_D_TERM(- (in(i-1,j,k,m) - 2.0 * in(i,j,k,m) + in(i+1,j,k,m)) / DX[0] / DX[0],
- (in(i,j-1,k,m) - 2.0 * in(i,j,k,m) + in(i,j+1,k,m)) / DX[1] / DX[1],
- (in(i,j,k-1,m) - 2.0 * in(i,j,k,m) + in(i,j,k+1,m)) / DX[2] / DX[2])) ;
Expand All @@ -62,6 +66,10 @@ void MCNodalLinOp::Diag (int amrlev, int mglev, MultiFab& a_diag)
domain.grow(-1); // Shrink domain so we don't operate on any boundaries
const Real* DX = m_geom[amrlev][mglev].CellSize();

amrex::AsyncArray<Real> aa(coeff.data(), coeff.size());
amrex::Real const* dcoeff = aa.data();
const int N = getNComp();

for (MFIter mfi(a_diag, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
Box bx = mfi.tilebox();
Expand All @@ -72,7 +80,7 @@ void MCNodalLinOp::Diag (int amrlev, int mglev, MultiFab& a_diag)

for (int n = 0; n < getNComp(); n++)
amrex::ParallelFor (bx,[=] AMREX_GPU_DEVICE(int i, int j, int k) {
diag(i,j,k,n) = coeff[ncomp*n + n] *
diag(i,j,k,n) = dcoeff[N*n + n] *
( AMREX_D_TERM(+ 2.0 / DX[0] / DX[0],
+ 2.0 / DX[1] / DX[1],
+ 2.0 / DX[2] / DX[2]) );
Expand Down

0 comments on commit e16f97e

Please sign in to comment.