Problem with XDMFFile in parallel

Hello everyone,

I stubled across a problem (and its solution) with using FEniCS in parallel. For the sake of completeness and documentation, I will present both the problem and its solution here, for others to be able to find it.

When using FEniCS from a compute cluster on more than a single node, parallel output using XDMFFile did not work properly. In particular, FEniCS did not generate the corresponding .h5 files needed to store the solution.

The problem was that, when running the code on a single machine, the output directory for the files was created automatically. However, when running on two nodes or more, this did not happen automatically, so that the .h5 could not be written. However, the directory was created after (trying to) write the .h5 files, so that the corresponding .xdmf files were saved, but the associated .h5 files did not exist.
If one creates the target directory before invoking the XDMFFile.write or XDMFFile.write_checkpoint commands, everything works fine and as expected.