MPI - Gather and distribute a function to all processes (That I can evaluate at a point)

Hello, more of a conceptual question I am struggling to figure out:

Using MPI, I have computed a scalar solution, u - of which I understand is currently distributed across all processes.

Problem is, I need to be able to evaluate this function u on all processes at an arbitrary point P(x,y) (P is different on each proc) - but being distributed, the point P may or may not fall in the range in which a certain proc will have access to.

Is it possible to somehow gather the function u before sending the full u (not distributed) to all processes, such that I could evaluate the function u at any point P(x,y) on all procs?

Thanks,

1 Like

Have a look at: Problem with evaluation at a point in parallel - #6 by MiroK

Hi dokken,

Thank you for your reply,

Correct me if I am wrong, but does the code in the post you linked not only work if the point P is the same on each process? As in, all procs are concurrently looking for point P across each partitioned mesh, evaluating it if they find that it collides on a certain proc, and returning the value to all procs.

In my application, I would like to concurrently evaluate a different point on each process (such that there should not be a ‘global’ returned value - the returned value should be different on each proc.

Would there be a simple way to do this?

Thanks, any help is appreciated.

Consider something as the following. This code first checks if there is any cell on the process containing the point, then, if the point is found evaluates at this point. If the point is not on the process, it returns -1

import numpy as np
from dolfin import *
from IPython import embed

mesh = UnitSquareMesh(32, 32)
V = VectorFunctionSpace(mesh, 'CG', 1)
f_ = Expression(('x[0]+x[1]', 'x[0]'), degree=1)
f = interpolate(f_, V)


tree = BoundingBoxTree()
tree.build(mesh, mesh.topology().dim())
num_cells = mesh.num_cells()

def safe_eval(f, x):
    cell_on_proc = tree.compute_first_entity_collision(Point(x))
    val = np.zeros(2)
    if cell_on_proc < num_cells:
        f.eval_cell(val, x, Cell(mesh, cell_on_proc))
        return val
    else:
        return -1

if MPI.comm_world.rank == 0:
    x = np.array([0.7, 0.9])
elif MPI.comm_world.rank == 1:
    x = np.array([0.1, 0.8])
else:
    x = np.array([0.6, 0.1])

print(MPI.comm_world.rank, x, safe_eval(f, x))
1 Like

Hi dokken,

Thanks for this solution - It doesn’t quite do exactly as I needed but it helped me think of a completely different way to do what I needed to do!

Cheers,