Skip to content
This repository has been archived by the owner on Apr 8, 2021. It is now read-only.

Commit

Permalink
Bug fix for building libsp without openmp:
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mkavulich committed Oct 15, 2019
1 parent 53680b0 commit d506d66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion macros.make.cheyenne.gnu
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ CC = gcc

ifeq ($(OPENMP),1)
OMPFLAGS= -fopenmp
OMPCPPFLAGS= -DOPENMP
else
OMPFLAGS=
OMPCPPFLAGS=
endif

# Number of parallel tasks for gmake
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/sp/v2.0.2/src/ncpus.F
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -41,6 +42,8 @@ FUNCTION NCPUS()
#else
NCPUS=NUM_PARTHDS()
#endif

#else
NCPUS=1
#endif
RETURN
END

0 comments on commit d506d66

Please sign in to comment.