Repository: OceanParcels/Parcels (language: python)

Issue:
issue with openmpi stommel example
I am getting the following error
`PermissionError: [Errno 13] Permission denied: b'/scratch/msldrift/stommelU.nc'`
where `/scratch/msldrift/` is my scratch space from where I launched the job on a LSFCluster. 

This issue occur when I use more than one processor for the mpirun command as in `mpirun -np 2 ...`. This error does not occur if I use `mpirun -np 1 ...` but that is not very useful of course. It looks like the multiple processors do not inherit read/write permissions or something like that?

To further debug I am also trying to figure put where in the `example_stommel.py` code the `stommel[U,P,...].nc` files are written?



Discussion / hints:
Hmm, it may be that the two processes want to write to the same file at the same time. Note that the Stommel example first creates flow-fields in netcdf (see [here](https://github.com/OceanParcels/parcels/blob/f72c4584f35ff69ec2b56de193e187752c7b15f6/parcels/examples/example_stommel.py#L87-L89)). 

Perhaps you could set `write_fields` to False on line 84 in the example_stommel.py script? Does that help?

I don't think `write_fields` an argument you can pass when calling the function, maybe we should implement that?

Fix patch:
diff --git a/parcels/examples/example_stommel.py b/parcels/examples/example_stommel.py
index b203c1f85..d2dc88325 100644
--- a/parcels/examples/example_stommel.py
+++ b/parcels/examples/example_stommel.py
@@ -166,12 +166,14 @@ def test_stommel_fieldset(pset_mode, mode, grid_type, tmpdir):
                    help='max age of the particles (after which particles are deleted)')
     p.add_argument('-psm', '--pset_mode', choices=('soa', 'aos'), default='soa',
                    help='max age of the particles (after which particles are deleted)')
+    p.add_argument('-wf', '--write_fields', default=True,
+                   help='Write the hydrodynamic fields to NetCDF')
     args = p.parse_args()
 
     timer.args.stop()
     timer.stommel = timer.Timer('Stommel', parent=timer.root)
     stommel_example(args.particles, mode=args.mode, verbose=args.verbose, method=method[args.method],
-                    outfile=args.outfile, repeatdt=args.repeatdt, maxage=args.maxage)
+                    outfile=args.outfile, repeatdt=args.repeatdt, maxage=args.maxage, write_fields=args.write_fields)
     timer.stommel.stop()
     timer.root.stop()
     timer.root.print_tree()


Test patch:
diff --git a/tests/test_mpirun.py b/tests/test_mpirun.py
index 589fe51c9..118cf1197 100644
--- a/tests/test_mpirun.py
+++ b/tests/test_mpirun.py
@@ -21,8 +21,8 @@ def test_mpi_run(pset_mode, tmpdir, repeatdt, maxage, nump):
         outputMPI = tmpdir.join('StommelMPI')
         outputNoMPI = tmpdir.join('StommelNoMPI.zarr')
 
-        system('mpirun -np 2 python %s -p %d -o %s -r %d -a %d -psm %s' % (stommel_file, nump, outputMPI, repeatdt, maxage, pset_mode))
-        system('python %s -p %d -o %s -r %d -a %d -psm %s' % (stommel_file, nump, outputNoMPI, repeatdt, maxage, pset_mode))
+        system('mpirun -np 2 python %s -p %d -o %s -r %d -a %d -psm %s -wf False' % (stommel_file, nump, outputMPI, repeatdt, maxage, pset_mode))
+        system('python %s -p %d -o %s -r %d -a %d -psm %s -wf False' % (stommel_file, nump, outputNoMPI, repeatdt, maxage, pset_mode))
 
         files = glob(path.join(outputMPI, "proc*"))
         ds1 = xr.concat([xr.open_zarr(f) for f in files], dim='trajectory',