# example illustrating mixing pyDIY with mpi4py # pyDIY doesn't provide wrappers around low-level MPI commands; use them from mpi4py instead # This is the same example as exchange.py, with a few mpi4py calls sprinkled in # the order of importing diy and mpi4py doesn't matter; either order works from mpi4py import MPI import diy # can get comm either from diy or mpi4py, in this case exercising mpi4py comm = MPI.COMM_WORLD c = diy.mpi.MPIComm(comm) m = diy.Master(c) # master # try some more mpi4py to get my rank and size of comm rank = comm.Get_rank() size = comm.Get_size() print("Rank", rank, "out of a communicator of size", size) class Block: def __init__(self, core): self.core = core def show(self, cp): print(w.rank, cp.gid(), self.core) #cp.enqueue(diy.BlockID(1, 0), "abc") def send(self, cp): link = cp.link() for i in range(len(link)):
import diy w = diy.mpi.MPIComm() m = diy.Master(w) diy.add_my_block(m, 0) diy.add_my_block(m, 5) print(m)
# example illustrating reading an MFA and evaluating a point from it # assumes that a 2-d domain was previously modeled and saved as "approx.out" import diy import mfa import numpy as np # MPI, DIY world and master w = diy.mpi.MPIComm() # world m = diy.Master(w) # master # load the results and print them out print("\n\nLoading blocks and printing them out\n") a = diy.ContiguousAssigner(w.size, -1) diy.read_blocks("approx.out", a, m, load=mfa.load_block) m.foreach(lambda b, cp: b.print_block(cp, False)) # evaluate a point param = np.array([0.5, 0.5]) # input parameters where to decode the point pt = np.array([0.0, 0.0, 0.0]) # assigning fake values defines shape and type m.foreach(lambda b, cp: b.decode_point(cp, param, pt)) print("\nThe point at [u =", param[0], ", v =", param[1], "] =", pt)
# example illustrating writing diy blocks and reading them back in import diy import numpy as np import sys w = diy.mpi.MPIComm() # world m = diy.Master(w) # master class Block: def __init__(self, core): n = 10 self.data = np.empty(n) self.core = core def show(self, cp): print(w.rank, cp.gid(), self.core) def add_block(gid, core, bounds, domain, link): b = Block(core) for i in range(b.data.shape[0]): b.data[i] = i m.add(gid, b, link) nblocks = 16 domain = diy.DiscreteBounds([0,0,0], [100, 100, 100]) d = diy.DiscreteDecomposer(3, domain, nblocks) a = diy.ContiguousAssigner(w.size, nblocks) d.decompose(w.rank, a, add_block)