adding openmp in CMakeLists.txt

31 views
Skip to first unread message

Lance Zhang

unread,
Jul 17, 2023, 3:42:16 PM7/17/23
to deal.II User Group
Hello everyone,

I have one problem when I tried to add openmp lib to CMakeLists.txt to use parallel functionality.

May I know how I could add openmp lib?

And one more question,I wrote two code files which are called gcmma and mma,may I know how could I add these two files in this CMakeLists as well?

I tried to find the lib and add them in this txt file,but the error still exists.

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SET(CLEAN_UP_FILES
  # a custom list of globs, e.g. *.log *.vtk
  *.vtk
)

# Usually, you will not need to modify anything beyond this point...

CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)

include_directories(/usr/include/trilinos)
include_directories(/usr/lib/x86_64-linux-gnu/openmpi/include)
include_directories(/usr/include/suitesparse)
include_directories(/usr/lib/petscdir/petsc3.15/x86_64-linux-gnu-real/include)

add_library(mma_gcmma OBJECT gcmma/GCMMASolver.cpp)
add_library(mma_mma OBJECT mma/MMASolver.cpp)

# find Eigen
find_package(Eigen3 REQUIRED)

# include Eigen
include_directories(${EIGEN3_INCLUDE_DIR})



#find_package(OpenMP REQUIRED)
#target_link_libraries(cook_membrane PUBLIC OpenMP::OpenMP_CXX)



FIND_PACKAGE(deal.II 9.3.0 QUIET
  HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
  )
IF(NOT ${deal.II_FOUND})
  MESSAGE(FATAL_ERROR "\n"
    "*** Could not locate deal.II. ***\n\n"
    "You may want to either pass a flag -DDEAL_II_DIR=/path/to/deal.II to cmake\n"
    "or set an environment variable \"DEAL_II_DIR\" that contains this path."
    )
ENDIF()
#target_link_libraries(cook_membrane mma_gcmma mma_mma ${DEAL_II_LIBRARIES})

DEAL_II_INITIALIZE_CACHED_VARIABLES()
PROJECT(${TARGET})
DEAL_II_INVOKE_AUTOPILOT()

SET(CLEAN_UP_FILES *.log *.gmv *.gnuplot *.gpl *.eps *.pov *.ucd *.d2 *.vtu *.pvtu)
MESSAGE(STATUS "deal.II_DIR: ${deal.II_DIR}")
MESSAGE(STATUS "DEAL_II_DIR: ${DEAL_II_DIR}")

#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Could anyone provide any hint or suggestions?

Thanks
Best regards
Lance


 

Matthias Maier

unread,
Jul 17, 2023, 6:39:53 PM7/17/23
to dea...@googlegroups.com
- Most of your find package calls have to come after the project(...)
call. deal.II is a bit special - we call find_package(deal.II) before
project() so that the compiler is configured to be the same as the
one used for deal.II.

- Also you only need to call target_link_libraries() with the imported
libraries. This will set up everything:

- You cannot use the "PUBLIC" keyword with target_link_libraries at
the moment in combination with DEAL_II_INVOKE_AUTOPILOT... :-(

- I am guessing a bit because you have not quoted the full
CMakeLists.txt.

but the following should work:


set(TARGET "cook_membrane")

set(TARGET_SRC
gcmma/GCMMASolver.cpp
mma/MMASolver.cpp
cook_membrane.cpp
)

find_package(deal.II 9.3.0 REQUIRED
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)

DEAL_II_INITIALIZE_CACHED_VARIABLES()
project(${TARGET})
DEAL_II_INVOKE_AUTOPILOT()

find_package(Eigen3 REQUIRED)
find_package(OpenMP REQUIRED)

target_link_libraries(${TARGET} Eigen3::Eigen OpenMP::OpenMP_CXX)
Reply all
Reply to author
Forward
0 new messages