Newer
Older
__copyright__ = """
Copyright (C) 2017 Ellis Hoag
Copyright (C) 2017 Andreas Kloeckner
"""
__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import pytest
import os
from meshmode.array_context import PyOpenCLArrayContext
from meshmode.dof_array import flat_norm
logging.basicConfig()
logger.setLevel(logging.INFO)
from grudge import sym, bind, DGDiscretizationWithBoundaries
cl_ctx = cl.create_some_context()
queue = cl.CommandQueue(cl_ctx)
from meshmode.distributed import MPIMeshDistributor, get_partition_by_pymetis
from mpi4py import MPI
comm = MPI.COMM_WORLD
num_parts = comm.Get_size()
mesh_dist = MPIMeshDistributor(comm)
if mesh_dist.is_mananger_rank():
from meshmode.mesh.generation import generate_regular_rect_mesh
part_per_element = get_partition_by_pymetis(mesh, num_parts)
local_mesh = mesh_dist.send_mesh_parts(mesh, part_per_element, num_parts)
else:
local_mesh = mesh_dist.receive_mesh_part()
vol_discr = DGDiscretizationWithBoundaries(actx, local_mesh, order=5,
mpi_communicator=comm)
sym_x = sym.nodes(local_mesh.dim)
myfunc_symb = sym.sin(np.dot(sym_x, [2, 3]))
myfunc = bind(vol_discr, myfunc_symb)(actx)
sym.project("vol", "all_faces")(sym.var("myfunc")))
sym.project("vol", "int_faces")(sym.var("myfunc")))
sym.project(sym.BTAG_ALL, "all_faces")(
sym.project("vol", sym.BTAG_ALL)(sym.var("myfunc"))))
sym.project("int_faces", "all_faces")(
sym.OppositeInteriorFaceSwap("int_faces")(
sym_int_faces_func)
) - (sym_all_faces_func - sym_bdry_faces_func)
)
hopefully_zero = bound_face_swap(myfunc=myfunc)
error = flat_norm(hopefully_zero, np.inf)
print(__file__)
with np.printoptions(threshold=100000000, suppress=True):
logger.debug(hopefully_zero)
logger.info("error: %.5e", error)
from mpi4py import MPI
comm = MPI.COMM_WORLD
from meshmode.distributed import MPIMeshDistributor, get_partition_by_pymetis
if mesh_dist.is_mananger_rank():
from meshmode.mesh.generation import generate_regular_rect_mesh
mesh = generate_regular_rect_mesh(a=(-0.5,)*dim,
b=(0.5,)*dim,
n=(16,)*dim)
part_per_element = get_partition_by_pymetis(mesh, num_parts)
local_mesh = mesh_dist.send_mesh_parts(mesh, part_per_element, num_parts)
else:
local_mesh = mesh_dist.receive_mesh_part()
vol_discr = DGDiscretizationWithBoundaries(actx, local_mesh, order=order,
source_center = np.array([0.1, 0.22, 0.33])[:local_mesh.dim]
source_width = 0.05
source_omega = 3
sym_x = sym.nodes(local_mesh.dim)
sym_source_center_dist = sym_x - source_center
sym_t = sym.ScalarVariable("t")
Andreas Klöckner
committed
from grudge.models.wave import WeakWaveOperator
Andreas Klöckner
committed
op = WeakWaveOperator(0.1, vol_discr.dim,
source_f=(
sym.sin(source_omega*sym_t)
* sym.exp(
-np.dot(sym_source_center_dist, sym_source_center_dist)
/ source_width**2)),
dirichlet_tag=BTAG_NONE,
neumann_tag=BTAG_NONE,
radiation_tag=BTAG_ALL,
flux_type="upwind")
from pytools.obj_array import flat_obj_array
fields = flat_obj_array(vol_discr.zeros(actx),
[vol_discr.zeros(actx) for i in range(vol_discr.dim)])
# FIXME: Should meshmode consider BTAG_PARTITION to be a boundary?
# Fails because: "found faces without boundary conditions"
# op.check_bc_coverage(local_mesh)
from pytools.log import LogManager, \
add_general_quantities, \
# NOTE: LogManager hangs when using a file on a shared directory.
logmgr = LogManager(log_filename, "w", comm)
add_run_info(logmgr)
add_general_quantities(logmgr)
{"rank_data_swap_timer": IntervalTimer("rank_data_swap_timer",
"Time spent evaluating RankDataSwapAssign"),
"rank_data_swap_counter": EventCounter("rank_data_swap_counter",
"Number of RankDataSwapAssign instructions evaluated"),
"exec_timer": IntervalTimer("exec_timer",
"Total time spent executing instructions"),
"insn_eval_timer": IntervalTimer("insn_eval_timer",
"Time spend evaluating instructions"),
"future_eval_timer": IntervalTimer("future_eval_timer",
"Time spent evaluating futures"),
"busy_wait_timer": IntervalTimer("busy_wait_timer",
"Time wasted doing busy wait")}
for quantity in log_quantities.values():
logmgr.add_quantity(quantity)
logger.debug("\n%s", sym.pretty(op.sym_operator()))
val, rhs.profile_data = bound_op(profile_data=rhs.profile_data,
return val
rhs.profile_data = {}
logger.info("[%04d] dt %.5e nsteps %4d", i_local_rank, dt, nsteps)
# from grudge.shortcuts import make_visualizer
# vis = make_visualizer(vol_discr, vis_order=order)
step = 0
norm = bind(vol_discr, sym.norm(2, sym.var("u")))
from time import time
t_last_step = time()
for event in dt_stepper.run(t_end=final_t):
if isinstance(event, dt_stepper.StateComputed):
assert event.component_id == "w"
logger.debug("[%04d] t = %.5e |u| = %.5e ellapsed %.5e",
step, event.t,
# if step % 10 == 0:
# vis.write_vtk_file("rank%d-fld-%04d.vtu" % (i_local_rank, step),
# [("u", event.state_component[0]),
# ("v", event.state_component[1:])])
def print_profile_data(data):
logger.info("""execute() for rank %d:\n
\tInstruction Evaluation: %g\n
\tFuture Evaluation: %g\n
\tBusy Wait: %g\n
\tTotal: %g seconds""",
i_local_rank,
data['insn_eval_time'] / data['total_time'] * 100,
data['future_eval_time'] / data['total_time'] * 100,
data['busy_wait_time'] / data['total_time'] * 100,
data['total_time'])
print_profile_data(rhs.profile_data)
logger.info("Rank %d exiting", i_local_rank)
pytest.importorskip("pymetis")
from subprocess import check_call
import sys
"mpiexec", "-np", str(num_ranks),
"-x", "RUN_WITHIN_MPI=1",
"-x", "TEST_MPI_COMMUNICATION=1",
sys.executable, __file__])
@pytest.mark.parametrize("num_ranks", [2])
def test_simple_mpi(num_ranks):
pytest.importorskip("pymetis")
"mpiexec", "-np", str(num_ranks),
"-x", "RUN_WITHIN_MPI=1",
"-x", "TEST_SIMPLE_MPI_COMMUNICATION=1",
# https://mpi4py.readthedocs.io/en/stable/mpi4py.run.html
sys.executable, "-m", "mpi4py.run", __file__])
if "RUN_WITHIN_MPI" in os.environ:
if "TEST_MPI_COMMUNICATION" in os.environ:
mpi_communication_entrypoint()
else:
import sys
if len(sys.argv) > 1:
exec(sys.argv[1])
else:
from pytest import main