Repository: NVIDIA/hpc-container-maker

Issue:
Netcdf with pnetCDF support
What is the correct syntax to install netcdf with pnetcdf support using hpc-container-maker?

Assuming that pnetcdf is installed in /usr/local/pnetcdf, it does not seem sufficient to add 

enable_pnetcdf='/usr/local/pnetcdf'

Whatever I tried nc-config --all always shows --has-pnetcdf   -> no




Discussion:

Patch:
diff --git a/docs/building_blocks.md b/docs/building_blocks.md
index 3161373..0443ffa 100644
--- a/docs/building_blocks.md
+++ b/docs/building_blocks.md
@@ -3931,8 +3931,8 @@ configuring.  For instance, `enable_foo=True` maps to
 Underscores in the parameter name are converted to dashes.
 
 - __environment__: Boolean flag to specify whether the environment
-(`LD_LIBRARY_PATH` and `PATH`) should be modified to include
-PnetCDF. The default is True.
+(`CPATH`, `LD_LIBRARY_PATH`, `LIBRARY_PATH`, and `PATH`) should be
+modified to include PnetCDF. The default is True.
 
 - __ldconfig__: Boolean flag to specify whether the PnetCDF library
 directory should be added dynamic linker cache.  If False, then
diff --git a/hpccm/building_blocks/pnetcdf.py b/hpccm/building_blocks/pnetcdf.py
index 06f7d89..8bf05fb 100644
--- a/hpccm/building_blocks/pnetcdf.py
+++ b/hpccm/building_blocks/pnetcdf.py
@@ -63,8 +63,8 @@ class pnetcdf(bb_base, hpccm.templates.envvars, hpccm.templates.ldconfig):
     Underscores in the parameter name are converted to dashes.
 
     environment: Boolean flag to specify whether the environment
-    (`LD_LIBRARY_PATH` and `PATH`) should be modified to include
-    PnetCDF. The default is True.
+    (`CPATH`, `LD_LIBRARY_PATH`, `LIBRARY_PATH`, and `PATH`) should be
+    modified to include PnetCDF. The default is True.
 
     ldconfig: Boolean flag to specify whether the PnetCDF library
     directory should be added dynamic linker cache.  If False, then
@@ -135,6 +135,10 @@ class pnetcdf(bb_base, hpccm.templates.envvars, hpccm.templates.ldconfig):
         self.__download()
 
         # Set the environment variables
+        self.environment_variables['CPATH'] = '{}:$CPATH'.format(
+            posixpath.join(self.__prefix, 'include'))
+        self.environment_variables['LIBRARY_PATH'] = '{}:$LIBRARY_PATH'.format(
+            posixpath.join(self.__prefix, 'lib'))
         self.environment_variables['PATH'] = '{}:$PATH'.format(
             posixpath.join(self.__prefix, 'bin'))
         if not self.ldconfig:


Test patch:
diff --git a/test/test_pnetcdf.py b/test/test_pnetcdf.py
index 9ab2833..5ad0baa 100644
--- a/test/test_pnetcdf.py
+++ b/test/test_pnetcdf.py
@@ -55,7 +55,9 @@ RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://
     make -j$(nproc) && \
     make -j$(nproc) install && \
     rm -rf /var/tmp/pnetcdf-1.12.1 /var/tmp/pnetcdf-1.12.1.tar.gz
-ENV LD_LIBRARY_PATH=/usr/local/pnetcdf/lib:$LD_LIBRARY_PATH \
+ENV CPATH=/usr/local/pnetcdf/include:$CPATH \
+    LD_LIBRARY_PATH=/usr/local/pnetcdf/lib:$LD_LIBRARY_PATH \
+    LIBRARY_PATH=/usr/local/pnetcdf/lib:$LIBRARY_PATH \
     PATH=/usr/local/pnetcdf/bin:$PATH''')
 
     @ubuntu
@@ -83,7 +85,9 @@ RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://
     make -j$(nproc) install && \
     echo "/usr/local/pnetcdf/lib" >> /etc/ld.so.conf.d/hpccm.conf && ldconfig && \
     rm -rf /var/tmp/parallel-netcdf-1.10.0 /var/tmp/parallel-netcdf-1.10.0.tar.gz
-ENV PATH=/usr/local/pnetcdf/bin:$PATH''')
+ENV CPATH=/usr/local/pnetcdf/include:$CPATH \
+    LIBRARY_PATH=/usr/local/pnetcdf/lib:$LIBRARY_PATH \
+    PATH=/usr/local/pnetcdf/bin:$PATH''')
 
     @ubuntu
     @docker
@@ -98,5 +102,7 @@ RUN apt-get update -y && \
         libatomic1 && \
     rm -rf /var/lib/apt/lists/*
 COPY --from=0 /usr/local/pnetcdf /usr/local/pnetcdf
-ENV LD_LIBRARY_PATH=/usr/local/pnetcdf/lib:$LD_LIBRARY_PATH \
+ENV CPATH=/usr/local/pnetcdf/include:$CPATH \
+    LD_LIBRARY_PATH=/usr/local/pnetcdf/lib:$LD_LIBRARY_PATH \
+    LIBRARY_PATH=/usr/local/pnetcdf/lib:$LIBRARY_PATH \
     PATH=/usr/local/pnetcdf/bin:$PATH''')