From d506d667419a0d40080d809c691383de79e6bbd9 Mon Sep 17 00:00:00 2001 From: "Michael Kavulich, Jr" Date: Tue, 15 Oct 2019 15:51:36 -0600 Subject: [PATCH 1/3] Bug fix for building libsp without openmp: When you do not build with openmp flags (at least for gnu, haven't tested other compilers), 'OMP_GET_THREAD_NUM' and 'OMP_GET_NUM_THREADS' can not be called because these are openmp function calls, and if we are not building with openmp flags these may not be callable. This commit includes a flag and a CPP instruction so that when building without openmp, these functions do not get called, and the calling routine which expects the number of threads always gets 1 as an answer. --- macros.make.cheyenne.gnu | 4 +++- src/sp/v2.0.2/src/ncpus.F | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/macros.make.cheyenne.gnu b/macros.make.cheyenne.gnu index 1cf413d..b48f6e5 100644 --- a/macros.make.cheyenne.gnu +++ b/macros.make.cheyenne.gnu @@ -10,8 +10,10 @@ CC = gcc ifeq ($(OPENMP),1) OMPFLAGS= -fopenmp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -fbacktrace -ffree-form -fconvert=big-endian SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -O3 -fdefault-real-8 -fconvert=big-endian -cpp -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -O3 -fdefault-real-8 -fconvert=big-endian -cpp -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/src/sp/v2.0.2/src/ncpus.F b/src/sp/v2.0.2/src/ncpus.F index 4ff8ee0..1520fa5 100644 --- a/src/sp/v2.0.2/src/ncpus.F +++ b/src/sp/v2.0.2/src/ncpus.F @@ -29,6 +29,7 @@ FUNCTION NCPUS() C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - INTEGER NTHREADS, TID, OMP_GET_NUM_THREADS,OMP_GET_THREAD_NUM C Obtain thread number +#if OPENMP == 1 #ifdef LINUX !$OMP PARALLEL PRIVATE(TID) TID = OMP_GET_THREAD_NUM() @@ -41,6 +42,8 @@ FUNCTION NCPUS() #else NCPUS=NUM_PARTHDS() #endif - +#else + NCPUS=1 +#endif RETURN END From 62d0ab2359e3bf2842c69cdfd25a152f9db43384 Mon Sep 17 00:00:00 2001 From: "Michael Kavulich, Jr" Date: Tue, 15 Oct 2019 17:22:41 -0600 Subject: [PATCH 2/3] Add flags for building with/without OPENMP for sp to all macros files --- macros.make.cheyenne.intel | 4 +++- macros.make.cheyenne.pgi | 4 +++- macros.make.gaea.intel | 4 +++- macros.make.hera.intel | 4 +++- macros.make.jet.intel | 4 +++- macros.make.linux.gnu | 4 +++- macros.make.linux.intel | 4 +++- macros.make.macosx.gnu | 4 +++- macros.make.theia.gnu | 4 +++- macros.make.theia.intel | 4 +++- macros.make.theia.pgi | 4 +++- 11 files changed, 33 insertions(+), 11 deletions(-) diff --git a/macros.make.cheyenne.intel b/macros.make.cheyenne.intel index af20da6..17c9394 100644 --- a/macros.make.cheyenne.intel +++ b/macros.make.cheyenne.intel @@ -10,8 +10,10 @@ CC = icc ifeq ($(OPENMP),1) OMPFLAGS= -qopenmp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -xHOST -traceback -free -convert big_endian - SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/macros.make.cheyenne.pgi b/macros.make.cheyenne.pgi index a40fe01..94804e2 100644 --- a/macros.make.cheyenne.pgi +++ b/macros.make.cheyenne.pgi @@ -10,8 +10,10 @@ CC = pgcc ifeq ($(OPENMP),1) OMPFLAGS= -mp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -traceback -Mfree -byteswapio -c -fPIC SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -traceback -O3 -Mrecursive -i4 -r8 -byteswapio -Kieee -Mpreprocess -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -traceback -O3 -Mrecursive -i4 -r8 -byteswapio -Kieee -Mpreprocess -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/macros.make.gaea.intel b/macros.make.gaea.intel index e1b2369..7be6cfd 100644 --- a/macros.make.gaea.intel +++ b/macros.make.gaea.intel @@ -10,8 +10,10 @@ CC = icc ifeq ($(OPENMP),1) OMPFLAGS= -qopenmp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -xHOST -traceback -free -convert big_endian - SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/macros.make.hera.intel b/macros.make.hera.intel index 4a4952c..c2e8ec1 100644 --- a/macros.make.hera.intel +++ b/macros.make.hera.intel @@ -10,8 +10,10 @@ CC = icc ifeq ($(OPENMP),1) OMPFLAGS= -qopenmp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -xHOST -traceback -free -convert big_endian - SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/macros.make.jet.intel b/macros.make.jet.intel index 4a4952c..c2e8ec1 100644 --- a/macros.make.jet.intel +++ b/macros.make.jet.intel @@ -10,8 +10,10 @@ CC = icc ifeq ($(OPENMP),1) OMPFLAGS= -qopenmp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -xHOST -traceback -free -convert big_endian - SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/macros.make.linux.gnu b/macros.make.linux.gnu index 83ddf28..c18ec42 100644 --- a/macros.make.linux.gnu +++ b/macros.make.linux.gnu @@ -10,8 +10,10 @@ ARFLAGS = ifeq ($(OPENMP),1) OMPFLAGS= -fopenmp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -42,7 +44,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -fbacktrace -ffree-form -fconvert=big-endian SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -O3 -fdefault-real-8 -fconvert=big-endian -cpp -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -O3 -fdefault-real-8 -fconvert=big-endian -cpp -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/macros.make.linux.intel b/macros.make.linux.intel index 8f8388a..70981d5 100644 --- a/macros.make.linux.intel +++ b/macros.make.linux.intel @@ -10,8 +10,10 @@ CC = icc ifeq ($(OPENMP),1) OMPFLAGS= -qopenmp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -xHOST -traceback -free -convert big_endian - SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/macros.make.macosx.gnu b/macros.make.macosx.gnu index d1454de..23d1edc 100644 --- a/macros.make.macosx.gnu +++ b/macros.make.macosx.gnu @@ -10,8 +10,10 @@ ARFLAGS = ifeq ($(OPENMP),1) OMPFLAGS= -fopenmp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -fbacktrace -ffree-form -fconvert=big-endian SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -O3 -fdefault-real-8 -fconvert=big-endian -cpp -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -O3 -fdefault-real-8 -fconvert=big-endian -cpp -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/macros.make.theia.gnu b/macros.make.theia.gnu index d942aeb..265cb30 100644 --- a/macros.make.theia.gnu +++ b/macros.make.theia.gnu @@ -10,8 +10,10 @@ CC = gcc ifeq ($(OPENMP),1) OMPFLAGS= -fopenmp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -fbacktrace -ffree-form -fconvert=big-endian SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -O3 -fdefault-real-8 -fconvert=big-endian -cpp -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -O3 -fdefault-real-8 -fconvert=big-endian -cpp -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/macros.make.theia.intel b/macros.make.theia.intel index 4a4952c..c2e8ec1 100644 --- a/macros.make.theia.intel +++ b/macros.make.theia.intel @@ -10,8 +10,10 @@ CC = icc ifeq ($(OPENMP),1) OMPFLAGS= -qopenmp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -xHOST -traceback -free -convert big_endian - SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -O3 -auto -i4 -r8 -convert big_endian -assume byterecl -fp-model strict -fpp -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library diff --git a/macros.make.theia.pgi b/macros.make.theia.pgi index bcef27a..b38b1f6 100644 --- a/macros.make.theia.pgi +++ b/macros.make.theia.pgi @@ -10,8 +10,10 @@ CC = pgcc ifeq ($(OPENMP),1) OMPFLAGS= -mp + OMPCPPFLAGS= -DOPENMP else OMPFLAGS= + OMPCPPFLAGS= endif # Number of parallel tasks for gmake @@ -50,7 +52,7 @@ SIGIO_FFLAGS = $(OMPFLAGS) -O0 -g -traceback -Mfree -byteswapio -c -fPIC SIGIO_ARFLAGS = crvs # Flags for sp library -SP_FFLAGS = $(OMPFLAGS) -traceback -O3 -Mrecursive -i4 -r8 -byteswapio -Kieee -Mpreprocess -DLINUX -fPIC +SP_FFLAGS = $(OMPFLAGS) -traceback -O3 -Mrecursive -i4 -r8 -byteswapio -Kieee -Mpreprocess -DLINUX -fPIC $(OMPCPPFLAGS) SP_ARFLAGS = -ruv # Flags for w3emc library From cc870d6c377a39200d3eb3ca8db5a67c257837f5 Mon Sep 17 00:00:00 2001 From: "Michael Kavulich, Jr" Date: Tue, 15 Oct 2019 20:21:18 -0600 Subject: [PATCH 3/3] Change ifeq to ifdef for OPENMP, modify make_ncep_libs.sh to only export OPENMP=1, and leave it unset when OPENMP=0 --- make_ncep_libs.sh | 4 +++- src/sp/v2.0.2/src/ncpus.F | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/make_ncep_libs.sh b/make_ncep_libs.sh index 4eb7b96..91fccc9 100755 --- a/make_ncep_libs.sh +++ b/make_ncep_libs.sh @@ -182,7 +182,9 @@ cp -v ${MACROS_FILE}.${SYSTEM}.${COMPILER} ${MACROS_FILE} #-------------------------------------------------------------- # Copy library source to BUILD_DIR and build #-------------------------------------------------------------- -export OPENMP=${OPENMP} +if [ "$OPENMP" == "1" ]; then + export OPENMP=${OPENMP} +fi rsync -a macros.make Makefile src ${BUILD_DIR} cd ${BUILD_DIR} if [ "$APP" == "all" ]; then diff --git a/src/sp/v2.0.2/src/ncpus.F b/src/sp/v2.0.2/src/ncpus.F index 1520fa5..33f3295 100644 --- a/src/sp/v2.0.2/src/ncpus.F +++ b/src/sp/v2.0.2/src/ncpus.F @@ -29,7 +29,7 @@ FUNCTION NCPUS() C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - INTEGER NTHREADS, TID, OMP_GET_NUM_THREADS,OMP_GET_THREAD_NUM C Obtain thread number -#if OPENMP == 1 +#ifdef OPENMP #ifdef LINUX !$OMP PARALLEL PRIVATE(TID) TID = OMP_GET_THREAD_NUM()