mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: provide openmp compile and link flags.
- the USE_OMP preprocessor symbol is also defined with the openmp compile flag to allow conditional compilation of openmp-specific code.
This commit is contained in:
3
applications/test/openmp/Make/files
Normal file
3
applications/test/openmp/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Test-openmp.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/Test-openmp
|
||||||
4
applications/test/openmp/Make/options
Normal file
4
applications/test/openmp/Make/options
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
EXE_INC = ${COMP_OPENMP}
|
||||||
|
|
||||||
|
/* Mostly do not need to explicitly link openmp libraries */
|
||||||
|
/* EXE_LIBS = ${LINK_OPENMP} */
|
||||||
69
applications/test/openmp/Test-openmp.C
Normal file
69
applications/test/openmp/Test-openmp.C
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Description
|
||||||
|
Simple test program for compiling/running openmp
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#ifdef USE_OMP
|
||||||
|
#include <omp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
// Main program:
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int nThreads, threadId;
|
||||||
|
|
||||||
|
// Fork threads with their own copies of variables
|
||||||
|
#ifdef USE_OMP
|
||||||
|
#pragma omp parallel private(nThreads, threadId)
|
||||||
|
{
|
||||||
|
threadId = omp_get_thread_num();
|
||||||
|
nThreads = omp_get_num_threads();
|
||||||
|
|
||||||
|
// Printf rather than cout to ensure that it emits in one go
|
||||||
|
printf("Called from thread = %d\n", threadId);
|
||||||
|
|
||||||
|
// Master thread
|
||||||
|
if (threadId == 0)
|
||||||
|
{
|
||||||
|
// Printf rather than cout to ensure that it emits in one go
|
||||||
|
printf("Number of threads = %d\n", nThreads);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
std::cout << "Compiled without openmp!\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -42,18 +42,11 @@
|
|||||||
# An Int64 OpenFOAM version can use it, but the mesh size is limited
|
# An Int64 OpenFOAM version can use it, but the mesh size is limited
|
||||||
# accordingly.
|
# accordingly.
|
||||||
#
|
#
|
||||||
# If KaHIP was compiled with openmp, you may need additional
|
|
||||||
# compile or link flags in KAHIP_COMP_FLAGS KAHIP_LINK_FLAGS
|
|
||||||
#
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# USER EDITABLE PART: Changes made here may be lost with the next upgrade
|
# USER EDITABLE PART: Changes made here may be lost with the next upgrade
|
||||||
|
|
||||||
KAHIP_VERSION=kahip-2.00
|
KAHIP_VERSION=kahip-2.00
|
||||||
export KAHIP_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$KAHIP_VERSION
|
export KAHIP_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$KAHIP_VERSION
|
||||||
|
|
||||||
# Adjust as required
|
|
||||||
# export KAHIP_COMP_FLAGS="-fopenmp"
|
|
||||||
export KAHIP_LINK_FLAGS="-lgomp"
|
|
||||||
|
|
||||||
# END OF (NORMAL) USER EDITABLE PART
|
# END OF (NORMAL) USER EDITABLE PART
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -33,7 +33,6 @@ hasKahip()
|
|||||||
local header label settings
|
local header label settings
|
||||||
|
|
||||||
unset KAHIP_ARCH_PATH KAHIP_VERSION
|
unset KAHIP_ARCH_PATH KAHIP_VERSION
|
||||||
unset KAHIP_COMP_FLAGS KAHIP_LINK_FLAGS
|
|
||||||
settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/kahip) || {
|
settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/kahip) || {
|
||||||
echo "$warning (no config.sh/kahip settings)"
|
echo "$warning (no config.sh/kahip settings)"
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
EXE_INC = \
|
EXE_INC = \
|
||||||
-I$(KAHIP_ARCH_PATH)/include \
|
-I$(KAHIP_ARCH_PATH)/include \
|
||||||
-I../decompositionMethods/lnInclude \
|
-I../decompositionMethods/lnInclude
|
||||||
$(KAHIP_COMP_FLAGS)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The $(KAHIP_ARCH_PATH)/lib$WM_COMPILER_LIB_ARCH path is provided
|
* The $(KAHIP_ARCH_PATH)/lib$WM_COMPILER_LIB_ARCH path is provided
|
||||||
* to support central, non-thirdparty installations
|
* to support central, non-thirdparty installations.
|
||||||
|
*
|
||||||
|
* KaHIP is often compiled with openmp, but may be missing the
|
||||||
|
* link dependency for openmp.
|
||||||
*/
|
*/
|
||||||
LIB_LIBS = \
|
LIB_LIBS = \
|
||||||
-L$(KAHIP_ARCH_PATH)/lib \
|
-L$(KAHIP_ARCH_PATH)/lib \
|
||||||
-L$(KAHIP_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
|
-L$(KAHIP_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
|
||||||
-L$(FOAM_EXT_LIBBIN) $(KAHIP_LINK_FLAGS) -lkahip
|
-L$(FOAM_EXT_LIBBIN) $(LINK_OPENMP) -lkahip
|
||||||
|
|||||||
@ -4,5 +4,6 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linux64Clang/openmp
Normal file
4
wmake/rules/linux64Clang/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -fopenmp
|
||||||
|
LINK_OPENMP = -lgomp
|
||||||
@ -4,5 +4,6 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linux64Gcc/openmp
Normal file
4
wmake/rules/linux64Gcc/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -fopenmp
|
||||||
|
LINK_OPENMP = -lgomp
|
||||||
@ -4,5 +4,6 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linux64GccKNL/openmp
Normal file
4
wmake/rules/linux64GccKNL/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -fopenmp
|
||||||
|
LINK_OPENMP = -lgomp
|
||||||
@ -4,5 +4,6 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linux64Icc/openmp
Normal file
4
wmake/rules/linux64Icc/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -qopenmp
|
||||||
|
LINK_OPENMP = -liomp5
|
||||||
4
wmake/rules/linux64IccKNL/openmp
Normal file
4
wmake/rules/linux64IccKNL/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -qopenmp
|
||||||
|
LINK_OPENMP = -liomp5
|
||||||
@ -5,5 +5,6 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linuxARM7Gcc/openmp
Normal file
4
wmake/rules/linuxARM7Gcc/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -fopenmp
|
||||||
|
LINK_OPENMP = -lgomp
|
||||||
@ -5,5 +5,6 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linuxClang/openmp
Normal file
4
wmake/rules/linuxClang/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -fopenmp
|
||||||
|
LINK_OPENMP = -lgomp
|
||||||
@ -5,5 +5,6 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linuxGcc/openmp
Normal file
4
wmake/rules/linuxGcc/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -fopenmp
|
||||||
|
LINK_OPENMP = -lgomp
|
||||||
@ -4,6 +4,7 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/X
|
include $(DEFAULT_RULES)/X
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linuxIA64Gcc/openmp
Normal file
4
wmake/rules/linuxIA64Gcc/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -fopenmp
|
||||||
|
LINK_OPENMP = -lgomp
|
||||||
@ -4,6 +4,7 @@ GLIBS =
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/X
|
include $(DEFAULT_RULES)/X
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linuxIA64Icc/openmp
Normal file
4
wmake/rules/linuxIA64Icc/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -qopenmp
|
||||||
|
LINK_OPENMP = -liomp5
|
||||||
@ -5,5 +5,6 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
@ -5,6 +5,7 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/X
|
include $(DEFAULT_RULES)/X
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linuxPPC64Gcc/openmp
Normal file
4
wmake/rules/linuxPPC64Gcc/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -fopenmp
|
||||||
|
LINK_OPENMP = -lgomp
|
||||||
@ -5,6 +5,7 @@ PROJECT_LIBS = -l$(WM_PROJECT) -ldl
|
|||||||
|
|
||||||
include $(GENERAL_RULES)/standard
|
include $(GENERAL_RULES)/standard
|
||||||
|
|
||||||
|
include $(DEFAULT_RULES)/openmp
|
||||||
include $(DEFAULT_RULES)/X
|
include $(DEFAULT_RULES)/X
|
||||||
include $(DEFAULT_RULES)/c
|
include $(DEFAULT_RULES)/c
|
||||||
include $(DEFAULT_RULES)/c++
|
include $(DEFAULT_RULES)/c++
|
||||||
|
|||||||
4
wmake/rules/linuxPPC64leGcc/openmp
Normal file
4
wmake/rules/linuxPPC64leGcc/openmp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Flags for compiling/linking openmp
|
||||||
|
|
||||||
|
COMP_OPENMP = -DUSE_OMP -fopenmp
|
||||||
|
LINK_OPENMP = -lgomp
|
||||||
Reference in New Issue
Block a user