Set_local() in parallel

Hello,

I have the expansion coefficients of a function saved as a numpy array and now I need to load it in parallel. This simple script demonstrates what I’m trying to do

import dolfin as dl
from mpi4py import MPI
import numpy as np

comm = MPI.COMM_WORLD
rank = comm.Get_rank()

mesh = dl.Mesh(comm, ‘path_of_mesh.xml’)
V = dl.FunctionSpace(mesh,‘CG’, 1)

coeff = np.load(‘data_path.npz’)[‘coeff’]

func = Function(V)
func.vector().set_local(coeff)

This code does not work because coeff does not have the same dimension for each rank. Do you know how I can distribute coeff?

PS: I created coeff on a single process so all has the full vector of the coefficients.

thank you

This is not a trivial task in parallel, and I would strongly suggest you to use the checkpoint functionality in DOLFIN to save this data to a format supported by DOLFIN (say HDF5File or XDMFFile), which can be read in again in parallel.

See for instance: Loading xdmf data back in - #4 by dokken

Also note that xml formats are not suitable for parallel computation, and you should use the xdmf-file format

Hi Dokken,

Thank you. I will do the changes as you suggested.