This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Load static memory only once for all processes.

0 votes

I have some data which I interpolate onto a FunctionSpace as shown below. I would like to load this data only once so that each process does not load the redundant data. My first attempt at doing this uses mpi4py :

import numpy as np
from fenics import *
from mpi4py import MPI as nMPI
from scipy.interpolate import RectBivariateSpline
import resource

comm = nMPI.COMM_WORLD
name = nMPI.Get_processor_name()
size = comm.Get_size()
rank = comm.Get_rank()

n    = 10
mesh = UnitSquareMesh(n,n)
Q    = FunctionSpace(mesh, "CG", 1)

m    = 1000
data = np.zeros((m,m))

x = np.linspace(0,1,m)
y = np.linspace(0,1,m)

def get_spline_expression(data):
  spline = RectBivariateSpline(x, y, data)

  class newExpression(Expression):
    def __init__(self, element=None):
      pass
    def eval(self, values, x):
      values[0] = spline(x[0], x[1])

  return newExpression(element = Q.ufl_element())

if rank == 0:
  data = np.outer(np.sin(2*pi*x), np.sin(2*pi*y))
  comm.Send(data, dest=1)

if rank == 1:
  comm.Recv(data, source=0)

expr = get_spline_expression(data)

usg = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
nm  = np.linalg.norm(data)
print "Process %i : data norm = %.2f, using %i KB" % (rank,nm,usg)

The problem is that 'data' has to be initialized for each process and hence the same amount of memory is required as before.

Is there another way to do this?

asked Jun 18, 2014 by pf4d FEniCS User (2,970 points)
...