Skip to content

Commit

Permalink
Add amrex::Print() Like Function (#174)
Browse files Browse the repository at this point in the history
* Add amrex::Print() Like Function

Add `amr.Print(...)` that behaves like Python's `print()`,
but only prints on the AMReX IOProcessor.

* Test `amr.Print(...)`

* amr.Print(): Fallback to All if not Init

and warn
  • Loading branch information
ax3l authored Aug 15, 2023
1 parent 351f4bf commit 8afc221
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/amrex/space1d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@
#
def d_decl(x, y, z):
return (x,)


def Print(*args, **kwargs):
"""Wrap amrex::Print() - only the IO processor writes"""
if not initialized():
print("warning: Print all - AMReX not initialized")
print(*args, **kwargs)
elif ParallelDescriptor.IOProcessor():
print(*args, **kwargs)
9 changes: 9 additions & 0 deletions src/amrex/space2d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@
#
def d_decl(x, y, z):
return (x, y)


def Print(*args, **kwargs):
"""Wrap amrex::Print() - only the IO processor writes"""
if not initialized():
print("warning: Print all - AMReX not initialized")
print(*args, **kwargs)
elif ParallelDescriptor.IOProcessor():
print(*args, **kwargs)
9 changes: 9 additions & 0 deletions src/amrex/space3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@
#
def d_decl(x, y, z):
return (x, y, z)


def Print(*args, **kwargs):
"""Wrap amrex::Print() - only the IO processor writes"""
if not initialized():
print("warning: Print all - AMReX not initialized")
print(*args, **kwargs)
elif ParallelDescriptor.IOProcessor():
print(*args, **kwargs)
5 changes: 5 additions & 0 deletions tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
def test_concatenate():
pltname = amr.concatenate("plt", 1000, 5)
assert pltname == "plt01000"


def test_print():
print("hello from everyone")
amr.Print("byeee from IO processor")

0 comments on commit 8afc221

Please sign in to comment.