Repository: spack/spack

Issue:
py-netcdf4 does not work for parallel IO
<!-- Thanks for taking the time to report this build failure. To proceed with the report please:

1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively! -->

@ skosukhin

I am trying to use parallel-netcdf with py-netcdf4 and mpi4py. I get the following error message :

Creating file with format NETCDF4_CLASSIC
Traceback (most recent call last):
  File "mpi_example.py", line 13, in <module>
    nc = Dataset('parallel_test.nc', 'w', parallel=True, comm=MPI.COMM_WORLD,
  File "netCDF4/_netCDF4.pyx", line 2157, in netCDF4._netCDF4.Dataset.__init__
ValueError: parallel mode requires MPI enabled netcdf-c

### Steps to reproduce the issue

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console

$ spack load  python parallel-netcdf py-netcdf4 py-mpi4py
$ wget https://raw.githubusercontent.com/Unidata/netcdf4-python/master/examples/mpi_example.py
$ mpirun -np 4 python mpi_example.py

```

### Information on your system

<!-- Please include the output of `spack debug report` -->

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->

### Additional information

<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists. -->


<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [ ] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [ ] I have uploaded the build log and environment files
- [x] I have searched the issues of this repo and believe this is not a duplicate



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-netcdf4/package.py b/var/spack/repos/builtin/packages/py-netcdf4/package.py
--- a/var/spack/repos/builtin/packages/py-netcdf4/package.py
+++ b/var/spack/repos/builtin/packages/py-netcdf4/package.py
@@ -18,15 +18,20 @@ class PyNetcdf4(PythonPackage):
     version('1.4.2',   sha256='b934af350459cf9041bcdf5472e2aa56ed7321c018d918e9f325ec9a1f9d1a30')
     version('1.2.7',   sha256='0c449b60183ee06238a8f9a75de7b0eed3acaa7a374952ff9f1ff06beb8f94ba')
     version('1.2.3.1', sha256='55edd74ef9aabb1f7d1ea3ffbab9c555da2a95632a97f91c0242281dc5eb919f')
+    variant("mpi", default=True, description="Parallel IO support")
 
     depends_on('py-setuptools',   type='build')
     depends_on('py-cython@0.19:', type='build')
 
     depends_on('py-numpy@1.7:', type=('build', 'run'))
     depends_on('py-cftime', type=('build', 'run'))
+    depends_on('py-mpi4py', when='+mpi', type=('build', 'run'))
 
-    depends_on('netcdf-c')
-    depends_on('hdf5@1.8.0:+hl')
+    depends_on('netcdf-c', when='-mpi')
+    depends_on('netcdf-c+mpi', when='+mpi')
+
+    depends_on('hdf5@1.8.0:+hl', when='-mpi')
+    depends_on('hdf5@1.8.0:+hl+mpi', when='+mpi')
 
     # The installation script tries to find hdf5 using pkg-config. However, the
     # version of hdf5 installed with Spack does not have pkg-config files.


Test patch: