diff --git a/configure b/configure index a12f1f593..e94a31f11 100755 --- a/configure +++ b/configure @@ -691,6 +691,10 @@ X_PRE_LIBS X_CFLAGS CPP XMKMF +falcon_OPENMP_LINKFLAGS +falcon_OPENMP_CXXFLAGS +OPENMP_LINKFLAGS +OPENMP_CXXFLAGS falcon_OPENMP STDFLAG MAKEDIRS @@ -1492,7 +1496,7 @@ Optional Packages: --with-ccmalloc use CCMALLOC for malloc --with-dso use DSO linking --with-opt use opt for essentials - --with-openmp use OMP directives + --with-openmp use OMP directives; mac/clang only: path to libomp --with-std use this -std= --with-x use the X Window System --with-pgplot-prefix=DIR Directory where PGPLOT was installed, aka PGPLOT_DIR @@ -6763,16 +6767,47 @@ else fi -if test $with_openmp = "yes"; then - CFLAGS="$CFLAGS -fopenmp" - CXXFLAGS="$CXXFLAGS -fopenmp" - FFLAGS="$CFLAGS -fopenmp" +OPENMP_CXXFLAGS="" +OPENMP_LINKFLAGS="" +falcon_OPENMP="noOPENMP" +if test $with_openmp != "no"; then falcon_OPENMP="OPENMP" -else - falcon_OPENMP="noOPENMP" + if ${CC} --version | grep -q "clang"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we have a valid libomp path" >&5 +printf %s "checking whether we have a valid libomp path... " >&6; } + if ! (test -d "$with_openmp/lib" && test -d "$with_openmp/include"); then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: No libomp path" >&5 +printf "%s\n" "$as_me: WARNING: No libomp path" >&2;} + echo "*********************************************************************************" + echo " You are compiling on clang (either directly or because you're on OS X)" + echo " and included a --with-openmp option, but did not provide a path to a " + echo " valid libomp install. Unlike other c compilers, clang does not include" + echo " libomp. You'll need to install libomp yourself with something like brew." + echo " Note also that brew will not symlink libomp from within /usr/*/lib, citing" + echo " possible damage to the OS. You'll need to know the path to the parent" + echo " dir of include/libomp.h and lib/libomp.* and provide it with the --with-openmp" + echo " option, e.g.:" + echo " /.configure ... --with-openmp=~/mybrew/Cellar/libomp/18.0.1" + echo "*********************************************************************************" + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + OPENMP_CXXFLAGS="-Xclang -fopenmp -I$with_openmp/include " + OPENMP_LINKFLAGS="-L$with_openmp/lib -lomp " + fi + else + OPENMP_CXXFLAGS="-fopenmp" + fi fi + +falcon_OPENMP_CXXFLAGS="$OPENMP_CXXFLAGS" +falcon_OPENMP_LINKFLAGS="$OPENMP_LINKFLAGS" + + + + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' diff --git a/configure.ac b/configure.ac index e05fb6b6c..d9a120bd4 100644 --- a/configure.ac +++ b/configure.ac @@ -246,7 +246,7 @@ AC_ARG_WITH(dso, AC_ARG_WITH(opt, [ --with-opt use opt for essentials], with_opt=$withval, with_opt=no) AC_ARG_WITH(openmp, - [ --with-openmp use OMP directives], with_openmp=$withval, with_openmp=no) + [ --with-openmp use OMP directives; mac/clang only: path to libomp ], with_openmp=$withval, with_openmp=no) AC_ARG_WITH(std, [ --with-std use this -std=], with_std=$withval, with_std=c99) @@ -258,15 +258,43 @@ else fi AC_SUBST(STDFLAG) -if test $with_openmp = "yes"; then - CFLAGS="$CFLAGS -fopenmp" - CXXFLAGS="$CXXFLAGS -fopenmp" - FFLAGS="$CFLAGS -fopenmp" +OPENMP_CXXFLAGS="" +OPENMP_LINKFLAGS="" +falcon_OPENMP="noOPENMP" +if test $with_openmp != "no"; then falcon_OPENMP="OPENMP" -else - falcon_OPENMP="noOPENMP" + if ${CC} --version | grep -q "clang"; then + AC_MSG_CHECKING([whether we have a valid libomp path]) + if ! (test -d "$with_openmp/lib" && test -d "$with_openmp/include"); then + AC_MSG_WARN([No libomp path]) + echo "*********************************************************************************" + echo " You are compiling on clang (either directly or because you're on OS X)" + echo " and included a --with-openmp option, but did not provide a path to a " + echo " valid libomp install. Unlike other c compilers, clang does not include" + echo " libomp. You'll need to install libomp yourself with something like brew." + echo " Note also that brew will not symlink libomp from within /usr/*/lib, citing" + echo " possible damage to the OS. You'll need to know the path to the parent" + echo " dir of include/libomp.h and lib/libomp.* and provide it with the --with-openmp" + echo " option, e.g.:" + echo " /.configure [...] --with-openmp=~/mybrew/Cellar/libomp/18.0.1" + echo "*********************************************************************************" + else + AC_MSG_RESULT([yes]) + OPENMP_CXXFLAGS="-Xclang -fopenmp -I$with_openmp/include " + OPENMP_LINKFLAGS="-L$with_openmp/lib -lomp " + fi + else + OPENMP_CXXFLAGS="-fopenmp" + fi fi AC_SUBST(falcon_OPENMP) +AC_SUBST(OPENMP_CXXFLAGS) +AC_SUBST(OPENMP_LINKFLAGS) +falcon_OPENMP_CXXFLAGS="$OPENMP_CXXFLAGS" +falcon_OPENMP_LINKFLAGS="$OPENMP_LINKFLAGS" +AC_SUBST(falcon_OPENMP_CXXFLAGS) +AC_SUBST(falcon_OPENMP_LINKFLAGS) + dnl --------------------------------------------------------------------- dnl Check for basic X windows stuff : AC_PATH_XTRA -> X_CFLAGS and X_LIBS diff --git a/makedefs.in b/makedefs.in index 46cc6991c..54fa22e96 100644 --- a/makedefs.in +++ b/makedefs.in @@ -78,6 +78,11 @@ GSL_LIB = PLPLOT_INC = @PLPLOT_CFLAGS@ PLPLOT_LIB = @PLPLOT_LIBS@ +# OPENMP +OPENMP_CXXFLAGS=@OPENMP_CXXFLAGS@ +OPENMP_LINKFLAGS=@OPENMP_LINKFLAGS@ + + # FFTW # -lfftw3, or -lfftw3f or -lfftw3l (depending on precision library, for float or long double) # [actually still not used yet] @@ -149,10 +154,10 @@ LOPT = @LDFLAGS@ # for shared libaries CCSHARED = @CCSHARED@ # everything -CFLAGS = $(COPT) $(CCSHARED) $(NEMO_CFLAGS) $(PFLAGS) @STDFLAG@ -CXXFLAGS = $(COPT) $(CCSHARED) $(NEMO_CFLAGS) +CFLAGS = $(COPT) $(CCSHARED) $(NEMO_CFLAGS) $(PFLAGS) $(OPENMP_CXXFLAGS) @STDFLAG@ +CXXFLAGS = $(COPT) $(CCSHARED) $(NEMO_CFLAGS) $(OPENMP_CXXFLAGS) FFLAGS = $(FOPT) $(CCSHARED) $(NEMO_FFLAGS) -LDFLAGS = $(LOPT) $(NEMO_LDFLAGS) +LDFLAGS = $(LOPT) $(NEMO_LDFLAGS) $(OPENMP_LIBFLAGS) CPPFLAGS = @CPPFLAGS@ RANLIB = @RANLIB@ diff --git a/src/kernel/io/Makefile b/src/kernel/io/Makefile index 3714f91c7..b156b2753 100644 --- a/src/kernel/io/Makefile +++ b/src/kernel/io/Makefile @@ -109,7 +109,7 @@ endian: endian.c $(CC) $(CFLAGS) -DTOOLBOX -o endian endian.c $(NEMO_LIBS) getpartest: getparam.c - $(CC) $(CFLAGS) -o getpartest -DTESTBED getparam.c $(NEMO_LIBS) + $(CC) $(CFLAGS) $(OPENMP_CXXFLAGS) -o getpartest -DTESTBED getparam.c $(NEMO_LIBS) $(OPENMP_LINKFLAGS) stropentest: stropen.c $(CC) $(CFLAGS) -o stropentest -DTESTBED stropen.c $(NEMO_LIBS) diff --git a/src/kernel/io/getparam.c b/src/kernel/io/getparam.c index 6b0c5a2d0..eed0c574b 100644 --- a/src/kernel/io/getparam.c +++ b/src/kernel/io/getparam.c @@ -230,14 +230,14 @@ //#if defined(ENABLE_OPENMP) -#if _OPENMP +//#if _OPENMP #include local double omp_t1, omp_t2; #else typedef int omp_int_t; inline omp_int_t omp_get_thread_num() { return 0;} inline omp_int_t omp_get_max_threads() { return 1;} -#endif +//#endif #if defined(TCL7) # include diff --git a/src/tutor/mp/Makefile b/src/tutor/mp/Makefile index 14ce94f3d..8b73a52a9 100644 --- a/src/tutor/mp/Makefile +++ b/src/tutor/mp/Makefile @@ -4,7 +4,7 @@ CC = gcc MPICC = mpicc -TIME = /usr/bin/time -f "%U %S %e %P" +TIME = /usr/bin/time include $(NEMOLIB)/makedefs @@ -16,7 +16,7 @@ clean: rm -f $(BINS) hello1: - $(CC) -fopenmp -O3 -o hello1 hellomp.c -lm + $(CC) $(OPENMP_CXXFLAGS) -O3 -o hello1 hellomp.c -lm $(OPENMP_LINKFLAGS) hello2: $(CC) -O3 -o hello2 hellomp.c -lm @@ -27,7 +27,7 @@ bench: $(BINS) heated_plate_openmp: - $(CC) $(CFLAGS) -fopenmp -o heated_plate_openmp heated_plate_openmp.c $(NEMO_LIBS) + $(CC) $(CFLAGS) $(OPENMP_CXXFLAGS) -o heated_plate_openmp heated_plate_openmp.c $(NEMO_LIBS) $(OPENMP_LINKFLAGS) bench2: heated_plate_openmp $(TIME) ./heated_plate_openmp nprocs=4 @@ -48,7 +48,7 @@ bench4: # scaling from https://stackoverflow.com/questions/19780554/what-limits-scaling-in-this-simple-openmp-program scaling: scaling.c - $(CC) scaling.c -std=c99 -fopenmp -O3 -o scaling -lm + $(CC) scaling.c -std=c99 $(OPENMP_CXXFLAGS) -O3 -o scaling -lm $(OPENMP_LINKFLAGS) ONT=1 2 4 8 16 bench5: scaling @@ -58,7 +58,7 @@ bench5: scaling quad_openmp: quad_openmp.c - gcc -fopenmp quad_openmp.c -o quad_openmp + gcc $(OPENMP_CXXFLAGS) quad_openmp.c -o quad_openmp $(OPENMP_LINKFLAGS) bench6: quad_openmp @echo OMP_NUM_THREADS ONT=$(ONT) diff --git a/usr/dehnen/falcON/src/public/lib/bodyfunc.cc b/usr/dehnen/falcON/src/public/lib/bodyfunc.cc index 7cff22fb4..9c560b927 100644 --- a/usr/dehnen/falcON/src/public/lib/bodyfunc.cc +++ b/usr/dehnen/falcON/src/public/lib/bodyfunc.cc @@ -35,6 +35,7 @@ #include #include #include +#include using namespace falcON; //////////////////////////////////////////////////////////////////////////////// @@ -154,8 +155,8 @@ namespace { // compiles a falcON C++ program in fname using compiler flags const char* falcON_path = falcON::directory(); if(falcON_path == 0) throw BfErr("cannot locate falcON directory"); - char cmmd[512]; - SNprintf(cmmd,512,"cd /tmp; %s %s.cc -o %s.so" + char cmmd[PATH_MAX]; + SNprintf(cmmd,PATH_MAX,"cd /tmp; %s %s.cc -o %s.so" " %s -shared -fPIC -I%s/inc -I%s/inc/utils -O2" #if __cplusplus >= 201103L " -std=c++0x" @@ -172,14 +173,20 @@ namespace { " -DfalcON_SINGLE" #endif #if defined(__INTEL_COMPILER) - " -ip -xHost -fpic -falign-functions -openmp -g -Wall" - + " -ip -xHost -fpic -falign-functions -g -Wall" +# if "x$OPENMP" != "x" + " -openmp" +# endif // " -march=native -mfpmath=sse -mpreferred-stack-boundary=4 -ggdb3" +#elif defined(__clang__) + " -mfpmath=sse -ggdb3" + " -Wall -Wextra -Winit-self -Wshadow -Woverloaded-virtual -fPIC" + " -std=c++11 -funroll-loops -fforce-addr $OPENMP_CXXFLAGS $OPENMP_LINKFLAGS" #elif defined(__GNUC__) " -mfpmath=sse -mpreferred-stack-boundary=4 -ggdb3" " -Wall -Wextra -Winit-self -Wshadow -Woverloaded-virtual -fPIC" " -std=c++11" - " -fopenmp -funroll-loops -fforce-addr" + " $OPENMP_CXXFLAGS -funroll-loops -fforce-addr $OPENMP_LINKFLAGS" #else " -fpic -openmp -g" #endif @@ -193,8 +200,8 @@ namespace { if(system(cmmd)) { if(debug(debug_depth)) { std::cerr<<"could not compile temporary file /tmp/"< /dev/stderr",fname); + char show[PATH_MAX]; + SNprintf(show,PATH_MAX,"more /tmp/%s.cc > /dev/stderr",fname); int rr; rr=system(show); std::cerr<<"\nwith the command\n\""< /dev/null 2>&1",fname); + char cmmd[PATH_MAX]; + SNprintf(cmmd,PATH_MAX,"rm -f /tmp/%s.* > /dev/null 2>&1",fname); DebugInfo(4,"executing \"%s\"\n",cmmd); int rr=system(cmmd); } @@ -510,7 +517,7 @@ namespace { "#define BD_TEST\n" "#define body_func\n" "#include \n\n" - "real _P[10]={RNG()};\n\n" + "real _P[10]={static_cast(RNG())};\n\n" "extern \"C\" {\n" " fieldset "<