forked from AMReX-Codes/amrex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tests/OpenMP/atomicAdd (AMReX-Codes#3805)
Co-authored-by: Axel Huebl <[email protected]>
- Loading branch information
1 parent
bde2963
commit 3fe7aad
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
if (NOT AMReX_GPU_BACKEND STREQUAL NONE) | ||
return() | ||
endif () | ||
|
||
foreach(D IN LISTS AMReX_SPACEDIM) | ||
set(_sources main.cpp) | ||
set(_input_files) | ||
|
||
setup_test(${D} _sources _input_files) | ||
|
||
unset(_sources) | ||
unset(_input_files) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
AMREX_HOME = ../../.. | ||
|
||
DEBUG = FALSE | ||
DIM = 3 | ||
COMP = gcc | ||
|
||
USE_MPI = FALSE | ||
USE_OMP = TRUE | ||
|
||
include $(AMREX_HOME)/Tools/GNUMake/Make.defs | ||
|
||
include ./Make.package | ||
include $(AMREX_HOME)/Src/Base/Make.package | ||
|
||
include $(AMREX_HOME)/Tools/GNUMake/Make.rules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CEXE_sources += main.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <AMReX.H> | ||
#include <AMReX_MultiFab.H> | ||
#include <AMReX_OpenMP.H> | ||
#include <AMReX_Print.H> | ||
|
||
using namespace amrex; | ||
|
||
void test_atomicAdd (MultiFab& mf) | ||
{ | ||
|
||
#ifdef AMREX_USE_OMP | ||
#pragma omp parallel | ||
#endif | ||
{ | ||
FArrayBox tmp; | ||
for (MFIter mfi(mf,true); mfi.isValid(); ++mfi) { | ||
Box const& tbx = mfi.growntilebox(); | ||
tmp.resize(tbx); | ||
tmp.template setVal<RunOn::Host>(0.2); | ||
mf[mfi].template atomicAdd<RunOn::Host>(tmp, tbx, tbx, 0, 0, 1); | ||
} | ||
} | ||
} | ||
|
||
void test_lockAdd (MultiFab& mf) | ||
{ | ||
|
||
#ifdef AMREX_USE_OMP | ||
#pragma omp parallel | ||
#endif | ||
{ | ||
FArrayBox tmp; | ||
for (MFIter mfi(mf,true); mfi.isValid(); ++mfi) { | ||
Box const& tbx = mfi.growntilebox(); | ||
tmp.resize(tbx); | ||
tmp.template setVal<RunOn::Host>(0.2); | ||
mf[mfi].template lockAdd<RunOn::Host>(tmp, tbx, tbx, 0, 0, 1); | ||
} | ||
} | ||
} | ||
|
||
int main (int argc, char* argv[]) | ||
{ | ||
amrex::Initialize(argc, argv); | ||
{ | ||
BoxArray ba(Box(IntVect(0),IntVect(127))); | ||
ba.maxSize(32); | ||
DistributionMapping dm(ba); | ||
|
||
MultiFab mf(ba,dm,1,2); | ||
mf.setVal(0.0); | ||
|
||
test_atomicAdd(mf); | ||
double t = amrex::second(); | ||
test_atomicAdd(mf); | ||
double t_aa = amrex::second() - t; | ||
|
||
test_lockAdd(mf); | ||
t = amrex::second(); | ||
test_lockAdd(mf); | ||
double t_la = amrex::second() - t; | ||
|
||
amrex::Print() << " atomicAdd time is " << t_aa << "\n" | ||
<< " lockAdd time is " << t_la << "\n"; | ||
} | ||
amrex::Finalize(); | ||
} |