Skip to content

Commit 92fbc0c

Browse files
committed
Squashed commit of the following:
commit 65668443c88a582a4c24e76da00c19f6894f9653 Author: Michael Hirsch, Ph.D <scivision@users.noreply.github.com> Date: Mon Dec 31 01:18:16 2018 -0500 ifort compat commit dde05ba28b0c98d8ef3f1e032d97fbc801765b3b Author: Michael Hirsch, Ph.D <scivision@users.noreply.github.com> Date: Mon Dec 31 01:15:37 2018 -0500 check for MPI working commit 052a1c3b04b20377efe27a19f9aae3fe266232a0 Author: Michael Hirsch, Ph.D <scivision@users.noreply.github.com> Date: Mon Dec 31 01:09:43 2018 -0500 lapack95dir commit 1c8775e Author: Michael Hirsch, Ph.D <scivision@users.noreply.github.com> Date: Mon Dec 31 00:06:39 2018 -0500 generalizing lapack95 restore switch lapack95 netlib or gnu+mkl working clean find lapack95 commit ca40a9b Author: Michael <scivision@users.noreply.github.com> Date: Sun Dec 30 17:13:11 2018 -0500 move lapack95 to own example
1 parent 1884df7 commit 92fbc0c

File tree

9 files changed

+166
-62
lines changed

9 files changed

+166
-62
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_subdirectory(contiguous)
2121
add_subdirectory(cxx)
2222
add_subdirectory(hdf5)
2323
add_subdirectory(io)
24+
add_subdirectory(lapack95)
2425
add_subdirectory(mpi)
2526
add_subdirectory(netcdf)
2627
add_subdirectory(openmp)

array/CMakeLists.txt

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,11 @@
11
cmake_minimum_required (VERSION 3.3)
2-
project(fortran2018array Fortran C) # C is NECESSARY for MKL detection!
2+
project(fortran2018array Fortran)
33
enable_testing()
44

55
get_directory_property(hasParent PARENT_DIRECTORY)
66
if(NOT hasParent)
77
include(../cmake/compilers.cmake)
88
endif()
9-
#=== Lapack95 MKL Example with Intel OR Gfortran compilers ===
10-
set(BLA_F95 ON)
11-
12-
if(USE_MKL)
13-
# be sure you have from terminal:
14-
# . $MKLROOT/mklvars.sh"
15-
16-
if(NOT CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
17-
# be sure Lapack95 is build for your compiler
18-
if(FC)
19-
# no "-j" make option ...=.
20-
execute_process(COMMAND make libintel64 INSTALL_DIR=${CMAKE_CURRENT_BINARY_DIR} interface=lp64 FC=${FC}
21-
WORKING_DIRECTORY $ENV{MKLROOT}/interfaces/lapack95
22-
)
23-
else()
24-
message(FATAL_ERROR "specify compiler, e.g.: FC=gfortran cmake -DUSE_MKL=on ..")
25-
endif()
26-
endif()
27-
28-
29-
set(BLA_VENDOR Intel10_64lp_seq)
30-
find_package(LAPACK)
31-
32-
# make sure include_dirs "lp64" or "ilp64" matches BLA_VENDOR
33-
if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
34-
set(LAPACK95_INCLUDE_DIRS $ENV{MKLROOT}/include/intel64/lp64)
35-
36-
list(INSERT LAPACK95_LIBRARIES 0 $ENV{MKLROOT}/lib/intel64_lin/libmkl_lapack95_lp64.a)
37-
else()
38-
set(LAPACK95_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/include/intel64/lp64)
39-
40-
list(INSERT LAPACK95_LIBRARIES 0 ${CMAKE_CURRENT_BINARY_DIR}/lib/intel64/libmkl_lapack95_lp64.a)
41-
endif()
42-
43-
endif()
44-
45-
46-
if(LAPACK95_FOUND)
47-
add_executable(svd intel_gesvd.f90)
48-
target_link_libraries(svd PRIVATE ${LAPACK95_LIBRARIES} ${FLIBS})
49-
target_include_directories(svd PRIVATE ${LAPACK95_INCLUDE_DIRS})
50-
target_compile_options(svd PRIVATE ${FFLAGS} ${LAPACK_LINKER_FLAGS})
51-
add_test(NAME FortranSVD COMMAND svd)
52-
endif()
53-
54-
#=== LAPACK MKL example with Intel OR Gfortran compilers ===
55-
set(BLA_F95 OFF)
56-
find_package(LAPACK)
57-
58-
if(LAPACK_FOUND)
59-
add_executable(dsvd intel_dgesvd.f90)
60-
target_link_libraries(dsvd PRIVATE ${LAPACK_LIBRARIES} ${FLIBS})
61-
target_include_directories(dsvd PRIVATE ${LAPACK_INCLUDE_DIRS})
62-
add_test(NAME FortranDsvd COMMAND dsvd)
63-
endif()
649

6510
if(f08errorstop)
6611
# ------- rot90, flip --------

cmake/Modules/FindLAPACK95.cmake

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2+
# file Copyright.txt or https://cmake.org/licensing for details.
3+
4+
#[=======================================================================[.rst:
5+
FindLAPACK95
6+
------------
7+
8+
Finds the LAPACK95 library (MKL or Netlib)
9+
10+
Input Variables
11+
^^^^^^^^^^^^^^^
12+
13+
``USEMKL``
14+
specifies to search for MKL Lapack95 instead of Netlib.
15+
16+
Result Variables
17+
^^^^^^^^^^^^^^^^
18+
19+
``LAPACK95_FOUND``
20+
System has the LAPACK95 library
21+
``LAPACK95_INCLUDE_DIRS``
22+
LAPACK95 header files
23+
``LAPACK95_LIBRARIES``
24+
LAPACK95 libraries
25+
26+
#]=======================================================================]
27+
28+
29+
if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
30+
31+
find_path(LAPACK95_INCLUDE_DIR
32+
NAMES lapack95.mod
33+
PATHS ENV MKLROOT
34+
PATH_SUFFIXES include/intel64/lp64
35+
NO_DEFAULT_PATH)
36+
37+
foreach(slib mkl_blas95_lp64 mkl_lapack95_lp64 mkl_intel_lp64 mkl_sequential mkl_core)
38+
find_library(LAPACK95_${slib}_LIBRARY
39+
NAMES ${slib}
40+
PATHS ENV MKLROOT
41+
PATH_SUFFIXES lib/intel64
42+
NO_DEFAULT_PATH)
43+
if(NOT LAPACK95_${slib}_LIBRARY)
44+
message(FATAL_ERROR "NOT FOUND: " ${slib} ${LAPACK95_${slib}_LIBRARY})
45+
endif()
46+
# message(STATUS "Intel MKL LAPACK95 FOUND: " ${slib} ${LAPACK95_${slib}_LIBRARY})
47+
list(APPEND LAPACK95_LIBRARY ${LAPACK95_${slib}_LIBRARY})
48+
mark_as_advanced(LAPACK95_${slib}_LIBRARY)
49+
endforeach()
50+
list(APPEND LAPACK95_LIBRARY pthread dl m)
51+
52+
elseif(USEMKL) # MKL with non-Intel compiler
53+
set(BLA_F95 OFF)
54+
find_package(LAPACK REQUIRED)
55+
56+
find_path(LAPACK95_INCLUDE_DIR
57+
NAMES lapack95.mod
58+
PATHS include ${LAPACK95_ROOT}/include
59+
PATH_SUFFIXES intel64/lp64
60+
NO_DEFAULT_PATH)
61+
62+
find_library(LAPACK95_LIBRARY
63+
NAMES mkl_lapack95_lp64
64+
PATHS lib ${LAPACK95_ROOT}/lib
65+
PATH_SUFFIXES intel64
66+
NO_DEFAULT_PATH)
67+
68+
else() # Netlib
69+
set(BLA_F95 OFF)
70+
find_package(LAPACK REQUIRED)
71+
72+
find_path(LAPACK95_INCLUDE_DIR
73+
NAMES f95_lapack.mod
74+
PATHS ${LAPACK95_ROOT}/include)
75+
76+
find_library(LAPACK95_LIBRARY
77+
NAMES lapack95
78+
PATHS ${LAPACK95_ROOT}/lib)
79+
80+
endif()
81+
82+
include(FindPackageHandleStandardArgs)
83+
find_package_handle_standard_args(LAPACK95
84+
REQUIRED_VARS LAPACK95_LIBRARY LAPACK95_INCLUDE_DIR)
85+
86+
if(LAPACK95_FOUND)
87+
set(LAPACK95_LIBRARIES ${LAPACK95_LIBRARY} ${LAPACK_LIBRARIES}) # MUST be in this order!
88+
set(LAPACK95_INCLUDE_DIRS ${LAPACK95_INCLUDE_DIR} ${LAPACK_INCLUDE_DIRS})
89+
endif()
90+
91+
mark_as_advanced(LAPACK95_INCLUDE_DIR LAPACK95_LIBRARY)
92+

lapack95/CMakeLists.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
cmake_minimum_required (VERSION 3.12)
2+
project(fortran2018array Fortran C) # C is NECESSARY for MKL detection!
3+
enable_testing()
4+
5+
cmake_policy(SET CMP0074 NEW)
6+
7+
get_directory_property(hasParent PARENT_DIRECTORY)
8+
if(NOT hasParent)
9+
include(../cmake/compilers.cmake)
10+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/)
11+
endif()
12+
13+
if(UNIX AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
14+
set(CMAKE_INSTALL_PREFIX "~/.local" CACHE PATH "..." FORCE)
15+
endif()
16+
17+
if(DEFINED ENV{MKLROOT})
18+
set(USEMKL 1)
19+
else()
20+
set(USEMKL 0)
21+
endif()
22+
23+
if(NOT CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
24+
set(LAPACK95_ROOT ${CMAKE_INSTALL_PREFIX})
25+
endif()
26+
27+
28+
find_package(LAPACK95)
29+
30+
if(USEMKL AND NOT LAPACK95_FOUND)
31+
get_filename_component(FC ${CMAKE_Fortran_COMPILER} NAME)
32+
33+
execute_process(COMMAND make libintel64 INSTALL_DIR=${CMAKE_INSTALL_PREFIX} interface=lp64 FC=${FC}
34+
WORKING_DIRECTORY $ENV{MKLROOT}/interfaces/lapack95)
35+
36+
find_package(LAPACK95)
37+
endif()
38+
39+
if(LAPACK95_FOUND)
40+
add_executable(svd demo_gesvd.F90)
41+
target_link_libraries(svd PRIVATE ${LAPACK95_LIBRARIES} ${FLIBS})
42+
target_include_directories(svd PRIVATE ${LAPACK95_INCLUDE_DIRS})
43+
target_compile_options(svd PRIVATE ${FFLAGS})
44+
target_compile_definitions(svd PRIVATE USEMKL=${USEMKL})
45+
add_test(NAME FortranSVD COMMAND svd)
46+
endif()
47+
48+
#=== LAPACK MKL example with Intel OR Gfortran compilers ===
49+
find_package(LAPACK)
50+
51+
if(LAPACK_FOUND)
52+
add_executable(dsvd intel_dgesvd.f90)
53+
target_link_libraries(dsvd PRIVATE ${LAPACK_LIBRARIES} ${FLIBS})
54+
target_include_directories(dsvd PRIVATE ${LAPACK_INCLUDE_DIRS})
55+
add_test(NAME FortranDsvd COMMAND dsvd)
56+
endif()
57+

lapack95/bin/.ignore

Whitespace-only changes.
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
program intel_svd
2-
use lapack95,only: gesvd
2+
3+
#if USEMKL
4+
use lapack95, only: gesvd
5+
#else
6+
use f95_lapack, only: gesvd=>la_gesvd
7+
#endif
38

49
use,intrinsic:: iso_fortran_env, only: sp=>real32, dp=>real64, compiler_version, stderr=>error_unit
510

@@ -27,7 +32,7 @@ program intel_svd
2732
real(dp) :: s64(M), e64(M), maxerr
2833
real(sp) :: s32(M), a32(M, N), e32(M)
2934

30-
A32 = A
35+
A32 = real(A, sp)
3136

3237

3338
call gesvd(A,s64)
@@ -36,10 +41,12 @@ program intel_svd
3641
print *,compiler_version()
3742
print '(I3,A,3ES20.12)',storage_size(s64),' bits: error mag: ',e64
3843

44+
#if USEMKL
3945
call gesvd(A32, s32)
4046
e32 = s32 - [2.460504870018764_sp, 1.699628148275318_sp, 0.239123278256554_sp]
4147

4248
print '(I3,A,3ES20.12)',storage_size(s32),' bits: error mag: ',e32
49+
#endif
4350

4451
maxerr=maxval(abs(e64))
4552

mpi/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ else()
1717
find_package(MPI COMPONENTS Fortran)
1818
endif()
1919

20-
if(NOT MPI_Fortran_FOUND)
20+
if(NOT hasMPI OR NOT MPI_Fortran_FOUND)
2121
return()
2222
endif()
2323
include(mpi.cmake)

system/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ add_executable(playsound play_sound.f90)
3030
target_compile_options(playsound PRIVATE ${FFLAGS})
3131
target_link_libraries(playsound ${FLIBS})
3232

33-
add_executable(callpython call_python_script.f90)
34-
target_compile_options(callpython PRIVATE ${FFLAGS})
35-
target_link_libraries(callpython osdet ${FLIBS})
33+
if(f18errorstop)
34+
add_executable(callpython call_python_script.f90)
35+
target_compile_options(callpython PRIVATE ${FFLAGS})
36+
target_link_libraries(callpython osdet ${FLIBS})
37+
endif()

0 commit comments

Comments
 (0)