Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return sqrt(assemble(dot(u - f, u - f) * dx))
def run_convergence_test():
diff = [run_test(i) for i in range(3, 8)]
from math import log
import numpy as np
conv = [log(diff[i] / diff[i + 1], 2) for i in range(len(diff) - 1)]
return np.array(conv)
if __name__ == "__main__":
import pickle
from mpi4py import MPI
l2_conv = run_convergence_test()
if MPI.COMM_WORLD.rank == 0:
with open("test-output.dat", "w") as f:
pickle.dump(l2_conv, f)
def test_l2_conv_parallel():
from mpi4py import MPI
l2_conv = run_convergence_test()
print('[%d]' % MPI.COMM_WORLD.rank, 'convergence rate:', l2_conv)
assert (l2_conv > 2.8).all()
enchilada_start = time.time()
# try cached importer first
sys.meta_path.insert(0, mpi4py_finder())
# fall back to our importer
sys.meta_path.insert(1, Importer())
from clawpack import pyclaw
MPI.COMM_WORLD.Barrier()
enchilada_elapsed = time.time() - enchilada_start
full_elapsed = time.time() - full_start
if (MPI.COMM_WORLD.rank == 0):
print "elapsed time (enchilada): %f" % enchilada_elapsed
print "elapsed time (full): %f" % full_elapsed
p_nz = 2 # Number of particles per cell along z
p_nr = 2 # Number of particles per cell along r
p_nt = 4 # Number of particles per cell along theta
# The laser
w0 = 5.e-6 # Laser waist
ctau = 5.e-6 # Laser duration
z0 = 15.e-6 # Laser centroid
# Parametric scan: Give a list of a0 values to scan,
# and pick one value that this rank takes as input parameter
a0_list = [ 2.0, 4.0 ]
if len(a0_list) != comm.size:
raise ValueError(
'This script should be launched with %d MPI ranks.'%len(a0_list))
a0 = a0_list[ comm.rank ]
# The moving window
v_window = c # Speed of the window
# The diagnostics and the checkpoints/restarts
diag_period = 50 # Period of the diagnostics in number of timesteps
save_checkpoints = False # Whether to write checkpoint files
checkpoint_period = 100 # Period for writing the checkpoints
use_restart = False # Whether to restart from a previous checkpoint
# The density profile
ramp_start = 30.e-6
ramp_length = 40.e-6
def dens_func( z, r ) :
"""Returns relative density at position z and r"""
def ComputeFlux(state, dim, flux):
from mpi4py import MPI
num_procs = MPI.COMM_WORLD.size
myid = MPI.COMM_WORLD.rank
den = state[0];
den_vel = state[1:1+dim].GetDataArray()
den_energy = state[1 + dim]
assert StateIsPhysical(state, dim), ""
pres = ComputePressure(state, dim)
den_vel2 = np.atleast_2d(den_vel)
fluxA = flux.GetDataArray()
fluxA[0,:] = den_vel
fluxA[1:1+dim, :] = den_vel2.transpose().dot(den_vel2) / den
for d in range(dim): fluxA[1+d,d] += pres
'''
ex8p.py -m fichera.mesh
ex8p.py -m square-disc-p3.mesh
ex8p.py -m star-surf.mesh -o 2
'''
import sys
from os.path import expanduser, join
import numpy as np
from numpy import sin, cos, exp, sqrt
from mfem.common.arg_parser import ArgParser
from mfem import path
import mfem.par as mfem
from mpi4py import MPI
num_procs = MPI.COMM_WORLD.size
myid = MPI.COMM_WORLD.rank
parser = ArgParser(description='Ex8p')
parser.add_argument('-m', '--mesh',
default = 'star.mesh',
action = 'store', type = str,
help='Mesh file to use.')
parser.add_argument('-o', '--order',
action = 'store', default = 1, type=int,
help = "Finite element order (polynomial degree)");
parser.add_argument('-vis', '--visualization',
action = 'store_true', default = True,
help='Enable GLVis visualization')
args = parser.parse_args()
order = args.order
def run():
try:
core()
except Exception:
print "ERROR: Exception in process %d:" % MPI.COMM_WORLD.rank
print traceback.format_exc()
Parameters
----------
ns : argparse.Namespace
the parser namespace corresponding to the ``initialize_parser``
functions
comm : MPI.Communicator
the communicator to pass to the ``ParticleMesh`` object
transfer : list, optional
list of transfer functions to apply that will be
passed to ``compute_3d_power``. If `None`, then
the default chain ``TransferFunction.NormalizeDC``,
``TransferFunction.RemoveDC``, and ``AnisotropicCIC``
will be applied
"""
rank = comm.rank if comm is not None else MPI.COMM_WORLD.rank
# handle default measurement keywords
measure_kw = {'comm':comm, 'log_level':ns.log_level}
# transfer chain
default_chain = [TransferFunction.NormalizeDC, TransferFunction.RemoveDC, AnisotropicCIC]
measure_kw.setdefault('transfer', default_chain)
if transfer is not None:
measure_kw['transfer'] = transfer
# set logging level
logger.setLevel(ns.log_level)
if rank == 0: logger.info('importing done')
# setup the particle mesh object, taking BoxSize from the painters
#!/usr/local/bin/env python
print "importing mpi4py.MPI..."
from mpi4py import MPI
print "Started node %d / %d" % (MPI.COMM_WORLD.rank, MPI.COMM_WORLD.size)
#=============================================================================================
# MODULE DOCSTRING
#=============================================================================================
"""
Replica-exchange transition path sampling in the s-field on a Kob-Andersen system.
Parallelization using mpi4py.
DESCRIPTION
REFERENCES
[1] Hedges LO, Jack RL, Garrahan JP, and Chandler D. Dynamic order-disorder in atomic models
of structural glass-formers. Science 323:1309, 2009.
def is_root():
return MPI.COMM_WORLD.rank == MPI_ROOT