From 995c55b60e49b7db0815d241d1c2ce9558b2fc2a Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Tue, 19 Dec 2017 16:07:15 +0100
Subject: [PATCH] CONFIG: add clang third-party lib to LD_LIBRARY_PATH

- required if there is no system openmp and libomp or libgomp are
  only found in the clang hierarchy

STYLE: add some notes in the openmp rules.

- the _OPENMP macro is now used in low-level testing files
---
 applications/test/openmp/Make/options  |  2 +-
 applications/test/openmp/Test-openmp.C | 16 ++++++++++++----
 etc/config.csh/settings                |  1 +
 etc/config.sh/settings                 |  1 +
 wmake/rules/linux64Clang/openmp        |  4 ++++
 wmake/rules/linux64Cray/openmp         |  1 +
 wmake/rules/linux64Gcc/openmp          |  1 +
 wmake/rules/linux64GccKNL/openmp       |  1 +
 wmake/rules/linux64Icc/openmp          |  1 +
 wmake/rules/linux64IccKNL/openmp       |  1 +
 wmake/rules/linuxARM64Clang/openmp     |  4 ++++
 wmake/rules/linuxARM64Gcc/openmp       |  1 +
 wmake/rules/linuxARM7Gcc/openmp        |  1 +
 wmake/rules/linuxClang/openmp          |  4 ++++
 wmake/rules/linuxGcc/openmp            |  1 +
 wmake/rules/linuxIA64Gcc/openmp        |  1 +
 wmake/rules/linuxIA64Icc/openmp        |  1 +
 wmake/rules/linuxPPC64Gcc/openmp       |  1 +
 wmake/rules/linuxPPC64leGcc/openmp     |  1 +
 19 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/applications/test/openmp/Make/options b/applications/test/openmp/Make/options
index 54eed51fb98..9c1cb59980f 100644
--- a/applications/test/openmp/Make/options
+++ b/applications/test/openmp/Make/options
@@ -1,4 +1,4 @@
-EXE_INC = ${COMP_OPENMP}
+EXE_INC = ${COMP_OPENMP} /* -UUSE_OMP */
 
 /* Mostly do not need to explicitly link openmp libraries */
 /* EXE_LIBS = ${LINK_OPENMP} */
diff --git a/applications/test/openmp/Test-openmp.C b/applications/test/openmp/Test-openmp.C
index acb68e9ed86..1ac9762c763 100644
--- a/applications/test/openmp/Test-openmp.C
+++ b/applications/test/openmp/Test-openmp.C
@@ -30,7 +30,7 @@ Description
 #include <cstdlib>
 #include <iostream>
 
-#ifdef USE_OMP
+#if _OPENMP
 #include <omp.h>
 #endif
 
@@ -39,11 +39,19 @@ Description
 
 int main(int argc, char *argv[])
 {
+#if USE_OMP
+    std::cout << "USE_OMP defined (" << USE_OMP << ")\n";
+#else
+    std::cout << "USE_OMP undefined\n";
+#endif
+
+#if _OPENMP
+    std::cout << "_OPENMP = " << _OPENMP << "\n\n";
+
+    // Fork threads with their own copies of variables
     int nThreads, threadId;
 
-// Fork threads with their own copies of variables
-#ifdef USE_OMP
-#pragma omp parallel private(nThreads, threadId)
+    #pragma omp parallel private(nThreads, threadId)
     {
         threadId = omp_get_thread_num();
         nThreads = omp_get_num_threads();
diff --git a/etc/config.csh/settings b/etc/config.csh/settings
index 4c88b294b83..37c49f4e91d 100644
--- a/etc/config.csh/settings
+++ b/etc/config.csh/settings
@@ -302,6 +302,7 @@ CLANG_NOT_FOUND
 
     _foamAddMan     $clangDir/man
     _foamAddPath    $clangDir/bin
+    _foamAddLib     $clangDir/lib  # For things like libomp (openmp) etc
 
     if ($?FOAM_VERBOSE && $?prompt) then
         echo "Using ThirdParty compiler"
diff --git a/etc/config.sh/settings b/etc/config.sh/settings
index 286339aa536..33aa7fa8937 100644
--- a/etc/config.sh/settings
+++ b/etc/config.sh/settings
@@ -287,6 +287,7 @@ CLANG_NOT_FOUND
 
     _foamAddMan     $clangDir/share/man
     _foamAddPath    $clangDir/bin
+    _foamAddLib     $clangDir/lib  # For things like libomp (openmp) etc
 
     if [ "$FOAM_VERBOSE" -a "$PS1" ]
     then
diff --git a/wmake/rules/linux64Clang/openmp b/wmake/rules/linux64Clang/openmp
index bcb805f57c6..070a2c5d3ad 100644
--- a/wmake/rules/linux64Clang/openmp
+++ b/wmake/rules/linux64Clang/openmp
@@ -1,4 +1,8 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
+# -
+# Clang provides 'omp' and a link for 'gomp'.
+# With 'gomp' we can use system libs.
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linux64Cray/openmp b/wmake/rules/linux64Cray/openmp
index bcb805f57c6..cd007d15291 100644
--- a/wmake/rules/linux64Cray/openmp
+++ b/wmake/rules/linux64Cray/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linux64Gcc/openmp b/wmake/rules/linux64Gcc/openmp
index bcb805f57c6..cd007d15291 100644
--- a/wmake/rules/linux64Gcc/openmp
+++ b/wmake/rules/linux64Gcc/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linux64GccKNL/openmp b/wmake/rules/linux64GccKNL/openmp
index bcb805f57c6..cd007d15291 100644
--- a/wmake/rules/linux64GccKNL/openmp
+++ b/wmake/rules/linux64GccKNL/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linux64Icc/openmp b/wmake/rules/linux64Icc/openmp
index 154c9e5743d..738673ca91c 100644
--- a/wmake/rules/linux64Icc/openmp
+++ b/wmake/rules/linux64Icc/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -qopenmp
 LINK_OPENMP = -liomp5
diff --git a/wmake/rules/linux64IccKNL/openmp b/wmake/rules/linux64IccKNL/openmp
index 154c9e5743d..738673ca91c 100644
--- a/wmake/rules/linux64IccKNL/openmp
+++ b/wmake/rules/linux64IccKNL/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -qopenmp
 LINK_OPENMP = -liomp5
diff --git a/wmake/rules/linuxARM64Clang/openmp b/wmake/rules/linuxARM64Clang/openmp
index bcb805f57c6..070a2c5d3ad 100644
--- a/wmake/rules/linuxARM64Clang/openmp
+++ b/wmake/rules/linuxARM64Clang/openmp
@@ -1,4 +1,8 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
+# -
+# Clang provides 'omp' and a link for 'gomp'.
+# With 'gomp' we can use system libs.
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linuxARM64Gcc/openmp b/wmake/rules/linuxARM64Gcc/openmp
index bcb805f57c6..cd007d15291 100644
--- a/wmake/rules/linuxARM64Gcc/openmp
+++ b/wmake/rules/linuxARM64Gcc/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linuxARM7Gcc/openmp b/wmake/rules/linuxARM7Gcc/openmp
index bcb805f57c6..cd007d15291 100644
--- a/wmake/rules/linuxARM7Gcc/openmp
+++ b/wmake/rules/linuxARM7Gcc/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linuxClang/openmp b/wmake/rules/linuxClang/openmp
index bcb805f57c6..070a2c5d3ad 100644
--- a/wmake/rules/linuxClang/openmp
+++ b/wmake/rules/linuxClang/openmp
@@ -1,4 +1,8 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
+# -
+# Clang provides 'omp' and a link for 'gomp'.
+# With 'gomp' we can use system libs.
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linuxGcc/openmp b/wmake/rules/linuxGcc/openmp
index bcb805f57c6..cd007d15291 100644
--- a/wmake/rules/linuxGcc/openmp
+++ b/wmake/rules/linuxGcc/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linuxIA64Gcc/openmp b/wmake/rules/linuxIA64Gcc/openmp
index bcb805f57c6..cd007d15291 100644
--- a/wmake/rules/linuxIA64Gcc/openmp
+++ b/wmake/rules/linuxIA64Gcc/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linuxIA64Icc/openmp b/wmake/rules/linuxIA64Icc/openmp
index 154c9e5743d..738673ca91c 100644
--- a/wmake/rules/linuxIA64Icc/openmp
+++ b/wmake/rules/linuxIA64Icc/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -qopenmp
 LINK_OPENMP = -liomp5
diff --git a/wmake/rules/linuxPPC64Gcc/openmp b/wmake/rules/linuxPPC64Gcc/openmp
index bcb805f57c6..cd007d15291 100644
--- a/wmake/rules/linuxPPC64Gcc/openmp
+++ b/wmake/rules/linuxPPC64Gcc/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linuxPPC64leGcc/openmp b/wmake/rules/linuxPPC64leGcc/openmp
index bcb805f57c6..cd007d15291 100644
--- a/wmake/rules/linuxPPC64leGcc/openmp
+++ b/wmake/rules/linuxPPC64leGcc/openmp
@@ -1,4 +1,5 @@
 # Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
 
 COMP_OPENMP = -DUSE_OMP -fopenmp
 LINK_OPENMP = -lgomp
-- 
GitLab