Skip to content

Commit 9a073c2

Browse files
committed
Merge branch 'framework/makefile_pnetcdf_test' into develop (PR #1263)
This merge adds a test to the top-level Makefile to ensure that PnetCDF is available. With the addition of SMIOL, PnetCDF is required for all builds of MPAS. This merge prevents build issues that can arise from forgetting the PNETCDF environment variable or other issues related to finding the PnetCDF library. If the build of the test program fails, the PnetCDF test C program will be left in the MPAS-Model directory to aid in troubleshooting. * framework/makefile_pnetcdf_test: Add build check for PnetCDF to top-level Makefile
2 parents 408339d + 31e791d commit 9a073c2

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

Makefile

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ ifeq "$(OPENACC)" "true"
12661266
endif # OPENACC eq true
12671267

12681268

1269-
pio_test: openmp_test openacc_test
1269+
pio_test: openmp_test openacc_test pnetcdf_test
12701270
@#
12711271
@# PIO_VERS will be set to:
12721272
@# 0 if no working PIO library was detected (and .piotest.log will contain error messages)
@@ -1374,11 +1374,52 @@ mpi_f08_test:
13741374
$(if $(findstring 1,$(MPAS_MPI_F08)), $(eval MPI_F08_MESSAGE = "Using the mpi_f08 module."), )
13751375
$(if $(findstring 1,$(MPAS_MPI_F08)), $(info mpi_f08 module detected.))
13761376

1377+
1378+
pnetcdf_test:
1379+
@#
1380+
@# Create test C programs that look for PNetCDF header file and some symbols in it
1381+
@#
1382+
ifneq "$(PNETCDF)" ""
1383+
@echo "Checking for a working PnetCDF library..."
1384+
@printf "#include \"pnetcdf.h\"\n\
1385+
&#include \"mpi.h\"\n\
1386+
&int main(){\n\
1387+
& int err, ncid;\n\
1388+
& err = ncmpi_create(MPI_COMM_WORLD, \"foo.nc\", NC_NOCLOBBER, MPI_INFO_NULL, &ncid);\n\
1389+
& return 0;\n\
1390+
&}\n" | sed 's/&/ /' > pnetcdf.c
1391+
@( $(CC) pnetcdf.c $(CPPINCLUDES) $(CFLAGS) $(LDFLAGS) -L$(PNETCDF)/$(PNETCDFLIBLOC) -lpnetcdf -o pnetcdf.out > pnetcdf.log 2>&1; \
1392+
if [ $$? -eq 0 ] ; then \
1393+
echo "$(CC) can compile test PnetCDF C program."; \
1394+
else \
1395+
echo "*********************************************************"; \
1396+
echo "ERROR: Test PnetCDF C program could not be compiled by $(CC)."; \
1397+
echo "Please ensure you have a working PnetCDF library installed."; \
1398+
echo ""; \
1399+
echo "The following compilation command failed with errors:" ; \
1400+
echo "$(CC) pnetcdf.c $(CPPINCLUDES) $(CFLAGS) $(LDFLAGS) -L$(PNETCDF)/$(PNETCDFLIBLOC) -lpnetcdf -o pnetcdf.out"; \
1401+
echo ""; \
1402+
echo "Test program pnetcdf.c and output pnetcdf.log have been left"; \
1403+
echo "in the top-level MPAS directory for further debugging"; \
1404+
echo "*********************************************************"; \
1405+
rm -f pnetcdf.out; exit 1; \
1406+
fi )
1407+
1408+
@rm -f pnetcdf.c pnetcdf.out pnetcdf.log
1409+
else
1410+
@echo "*********************************************************"; \
1411+
echo "ERROR: The PNETCDF environment variable isn't set."; \
1412+
echo "Please set this variable to where PnetCDF is installed."; \
1413+
echo "*********************************************************"; \
1414+
exit 1
1415+
endif
1416+
1417+
13771418
ifneq "$(PIO)" ""
1378-
MAIN_DEPS = rebuild_check openmp_test openacc_test pio_test mpi_f08_test
1419+
MAIN_DEPS = rebuild_check openmp_test openacc_test pnetcdf_test pio_test mpi_f08_test
13791420
override CPPFLAGS += "-DMPAS_PIO_SUPPORT"
13801421
else
1381-
MAIN_DEPS = rebuild_check openmp_test openacc_test mpi_f08_test
1422+
MAIN_DEPS = rebuild_check openmp_test openacc_test pnetcdf_test mpi_f08_test
13821423
IO_MESSAGE = "Using the SMIOL library."
13831424
override CPPFLAGS += "-DMPAS_SMIOL_SUPPORT"
13841425
endif

0 commit comments

Comments
 (0)