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

Switching between serial and parallel with HDF5File

+1 vote

So i have a code that runs just fine in serial and except for a small part it runs fine (and much faster in parallel). Since the part that runs only in serial needs interpolate,SubMesh and a selfmade extracting function that needs the mesh on one process, i thought about running just that part in serial. And well i thought i could just save my mesh with

    f = HDF5File(mesh.mpi_comm(),'mesh.h5','w')
    f.write(mesh,'mesh')

then go to

  if MPI.rank(mpi_comm_world()) == 0:
      mesh = Mesh(mpi_comm_self())
      f = HDF5File(mesh.mpi_comm(),'mesh.h5','r')
      f.read(mesh, 'mesh',False)
      #run the whole stuff in serial
      #mesh.move is also used here, so the mesh is changed

and after that leave the if-clause and distribute the (locally saved and changed) mesh with

    MeshPartitioning.build_distributed_mesh(mesh)

Well the first part, i.e. the writing, works, but the loading just doesn't happen, so i guess i can't do it the way i want to do it, but i don't understand why. And i don't understand how to make that work either.. Well the guess is, that it tries to load the mesh on every process, but since there is the if-clause, only process 0 gets there and the programm halts, but shouldn't mpi_comm_self() force it to load the mesh on just process 0?

Hope someone has an idea, i am thankful for every information and help :)

Best regards

asked Sep 27, 2016 by Alawvahr FEniCS Novice (170 points)
...