From 7ee5a6af7c1f32e592200b123f01aba75234f2a8 Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Fri, 18 Jan 2019 06:58:46 -0500 Subject: [PATCH] This should fix psblas errors on windows --- CMakeLists.txt | 67 ++++++++++++++++---------- base/CMakeLists.txt | 16 +++++-- base/modules/gettimeofday.c | 59 +++++++++++++++++++++++ cmake/FindMETIS.cmake | 95 +++++++++++++++++++++++++++++++++++++ util/CMakeLists.txt | 10 +++- 5 files changed, 215 insertions(+), 32 deletions(-) create mode 100644 base/modules/gettimeofday.c create mode 100644 cmake/FindMETIS.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a2e320d8b..87419b827 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -277,10 +277,18 @@ endif() #------------------------------ # Find Linear Algebra Libraries #------------------------------ +#set(BLA_STATIC 1) find_package(BLAS REQUIRED) find_package(LAPACK REQUIRED) add_definitions(-DHAVE_LAPACK) + +#-------------------------------- +# Find METIS partitioning library +#-------------------------------- +include(${CMAKE_CURRENT_LIST_DIR}/cmake/FindMETIS.cmake) +find_package(METIS) + #--------------------------------------------------- # Use standardized GNU install directory conventions #--------------------------------------------------- @@ -336,29 +344,29 @@ install( if(MPI_FOUND) -#------------------------------------------ -# Add portable unistall command to makefile -#------------------------------------------ -# Adapted from the CMake Wiki FAQ -configure_file ( "${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in" "${CMAKE_BINARY_DIR}/uninstall.cmake" + #------------------------------------------ + # Add portable unistall command to makefile + #------------------------------------------ + # Adapted from the CMake Wiki FAQ + configure_file ( "${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in" "${CMAKE_BINARY_DIR}/uninstall.cmake" @ONLY) -add_custom_target ( uninstall - COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/uninstall.cmake" ) - -add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure) -# See JSON-Fortran's CMakeLists.txt file to find out how to get the check target to depend -# on the test executables - -#---------------------------------- -# Determine if we're using Open MPI -#--------------------------------- -execute_process(COMMAND ${MPIEXEC} --version - OUTPUT_VARIABLE mpi_version_out) -if (mpi_version_out MATCHES "[Oo]pen[ -][Mm][Pp][Ii]") - message( STATUS "OpenMPI detected") - set ( openmpi true ) -endif () + add_custom_target ( uninstall + COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/uninstall.cmake" ) + + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure) + # See JSON-Fortran's CMakeLists.txt file to find out how to get the check target to depend + # on the test executables + + #---------------------------------- + # Determine if we're using Open MPI + #--------------------------------- + execute_process(COMMAND ${MPIEXEC} --version + OUTPUT_VARIABLE mpi_version_out) + if (mpi_version_out MATCHES "[Oo]pen[ -][Mm][Pp][Ii]") + message( STATUS "OpenMPI detected") + set ( openmpi true ) + endif() endif() #--------------------------------------- @@ -369,7 +377,8 @@ endif() # cbind.a, util.a krylov.a prec.a base.a include(${CMAKE_CURRENT_LIST_DIR}/base/CMakeLists.txt) -add_library(base ${base_source_files}) +add_library(base_C OBJECT ${base_source_C_files}) +add_library(base ${base_source_files} $) set_target_properties(base PROPERTIES Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}" @@ -383,7 +392,9 @@ target_include_directories(base PUBLIC if(MPI_FOUND) target_link_libraries(base PUBLIC ${MPI_C_LIBRARIES} ${MPI_Fortran_LIBRARIES}) endif() - +target_link_libraries(base + PUBLIC ${LAPACK_LINKER_FLAGS} ${LAPACK_LIBRARIES} ${LAPACK95_LIBRARIES} + PUBLIC ${BLAS_LINKER_FLAGS} ${BLAS_LIBRARIES} ${BLAS95_LIBRARIES}) include(${CMAKE_CURRENT_LIST_DIR}/prec/CMakeLists.txt) add_library(prec ${prec_source_files}) @@ -414,7 +425,8 @@ target_include_directories(krylov PUBLIC target_link_libraries(krylov PUBLIC base prec) include(${CMAKE_CURRENT_LIST_DIR}/util/CMakeLists.txt) -add_library(util ${util_source_files}) +add_library(util_C OBJECT ${util_source_C_files}) +add_library(util ${util_source_files} $) set_target_properties(util PROPERTIES Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}" @@ -426,7 +438,12 @@ target_include_directories(util PUBLIC $ $) target_link_libraries(util PUBLIC base prec) - +if(METIS_FOUND) + target_include_directories(util + PUBLIC ${METIS_INCLUDES}) + target_link_libraries(util + PUBLIC ${METIS_LIBRARIES}) +endif() install(DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING PATTERN "*.mod") diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index d18e52907..abe85e552 100644 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -103,7 +103,6 @@ modules/comm/psb_s_comm_mod.f90 modules/comm/psb_s_linmap_mod.f90 modules/comm/psb_z_comm_mod.f90 modules/comm/psb_z_linmap_mod.f90 -modules/cutil.c modules/desc/psb_desc_const_mod.f90 modules/desc/psb_desc_mod.F90 modules/desc/psb_gen_block_map_mod.f90 @@ -402,10 +401,17 @@ tools/psb_zspins.f90 tools/psb_zspins.f90 tools/psb_zsprn.f90 ) -if (SERIAL_MPI) - set(PSB_base_source_files ${PSB_base_source_files} modules/fakempi.c) -endif() - foreach(file IN LISTS PSB_base_source_files) list(APPEND base_source_files ${CMAKE_CURRENT_LIST_DIR}/${file}) endforeach() + +list(APPEND PSB_base_source_C_files modules/cutil.c) +if (SERIAL_MPI) + list(APPEND PSB_base_source_C_files modules/fakempi.c) +endif() +if(WIN32) + list(APPEND PSB_base_source_C_files modules/gettimeofday.c) +endif() +foreach(file IN LISTS PSB_base_source_C_files) + list(APPEND base_source_C_files ${CMAKE_CURRENT_LIST_DIR}/${file}) +endforeach() diff --git a/base/modules/gettimeofday.c b/base/modules/gettimeofday.c new file mode 100644 index 000000000..46d16519d --- /dev/null +++ b/base/modules/gettimeofday.c @@ -0,0 +1,59 @@ +/* + * gettimeofday.c + * Win32 gettimeofday() replacement + * + * src/port/gettimeofday.c + * + * Copyright (c) 2003 SRA, Inc. + * Copyright (c) 2003 SKC, Inc. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose, without fee, and without a + * written agreement is hereby granted, provided that the above + * copyright notice and this paragraph and the following two + * paragraphs appear in all copies. + * + * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, + * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING + * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS + * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS + * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#include "c.h" + +#include + + +/* FILETIME of Jan 1 1970 00:00:00. */ +static const unsigned __int64 epoch = ((unsigned __int64) 116444736000000000ULL); + +/* + * timezone information is stored outside the kernel so tzp isn't used anymore. + * + * Note: this function is not for Win32 high precision timing purpose. See + * elapsed_time(). + */ +int +gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + FILETIME file_time; + SYSTEMTIME system_time; + ULARGE_INTEGER ularge; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + ularge.LowPart = file_time.dwLowDateTime; + ularge.HighPart = file_time.dwHighDateTime; + + tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); + tp->tv_usec = (long) (system_time.wMilliseconds * 1000); + + return 0; +} diff --git a/cmake/FindMETIS.cmake b/cmake/FindMETIS.cmake new file mode 100644 index 000000000..21f95f572 --- /dev/null +++ b/cmake/FindMETIS.cmake @@ -0,0 +1,95 @@ +if (METIS_INCLUDES AND METIS_LIBRARIES) + set(METIS_FIND_QUIETLY TRUE) +endif (METIS_INCLUDES AND METIS_LIBRARIES) + +if( DEFINED ENV{METISDIR} ) + if( NOT DEFINED METIS_ROOT ) + set(METIS_ROOT "$ENV{METISDIR}") + endif() +endif() + +if( (DEFINED ENV{METIS_ROOT}) OR (DEFINED METIS_ROOT) ) + if( NOT DEFINED METIS_ROOT) + set(METIS_ROOT "$ENV{METIS_ROOT}") + endif() + set(METIS_HINTS "${METIS_ROOT}") +endif() + +find_path(METIS_INCLUDES + NAMES + metis.h + HINTS + ${METIS_HINTS} + PATHS + "${INCLUDE_INSTALL_DIR}" + /usr/local/opt + /usr/local + PATH_SUFFIXES + include + ) + +if(METIS_INCLUDES) + foreach(include IN_LISTS METIS_INCLUDES) + get_filename_component(mts_include_dir "${include}" DIRECTORY) + get_filename_component(mts_abs_include_dir "${mts_include_dir}" ABSOLUTE) + get_filename_component(new_mts_hint "${include_dir}/.." ABSOLUTE ) + list(APPEND METIS_HINTS "${new_mts_hint}") + break() + endforeach() +endif() + +if(METIS_HINTS) + list(REMOVE_DUPLICATES METIS_HINTS) +endif() + +macro(_metis_check_version) + file(READ "${METIS_INCLUDES}/metis.h" _metis_version_header) + + string(REGEX MATCH "define[ \t]+METIS_VER_MAJOR[ \t]+([0-9]+)" _metis_major_version_match "${_metis_version_header}") + set(METIS_MAJOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+METIS_VER_MINOR[ \t]+([0-9]+)" _metis_minor_version_match "${_metis_version_header}") + set(METIS_MINOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+METIS_VER_SUBMINOR[ \t]+([0-9]+)" _metis_subminor_version_match "${_metis_version_header}") + set(METIS_SUBMINOR_VERSION "${CMAKE_MATCH_1}") + if(NOT METIS_MAJOR_VERSION) + message(STATUS "Could not determine Metis version. Assuming version 4.0.0") + set(METIS_VERSION 4.0.0) + else() + set(METIS_VERSION ${METIS_MAJOR_VERSION}.${METIS_MINOR_VERSION}.${METIS_SUBMINOR_VERSION}) + endif() + if(${METIS_VERSION} VERSION_LESS ${Metis_FIND_VERSION}) + set(METIS_VERSION_OK FALSE) + else() + set(METIS_VERSION_OK TRUE) + endif() + + if(NOT METIS_VERSION_OK) + message(STATUS "Metis version ${METIS_VERSION} found in ${METIS_INCLUDES}, " + "but at least version ${Metis_FIND_VERSION} is required") + endif(NOT METIS_VERSION_OK) +endmacro(_metis_check_version) + +if(METIS_INCLUDES AND Metis_FIND_VERSION) + _metis_check_version() +else() + set(METIS_VERSION_OK TRUE) +endif() + + +find_library(METIS_LIBRARIES metis + HINTS + ${METIS_HINTS} + PATHS + "${LIB_INSTALL_DIR}" + /usr/local/ + /usr/local/opt + PATH_SUFFIXES + lib + lib64 + metis/lib) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(METIS DEFAULT_MSG + METIS_INCLUDES METIS_LIBRARIES METIS_VERSION_OK) + +mark_as_advanced(METIS_INCLUDES METIS_LIBRARIES) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 811f9bba5..5c77191e7 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -1,6 +1,4 @@ set(PSB_util_source_files - metis_int.c - psb_amd_order.c psb_blockpart_mod.f90 psb_c_hbio_impl.f90 psb_c_mat_dist_impl.f90 @@ -34,3 +32,11 @@ set(PSB_util_source_files foreach(file IN LISTS PSB_util_source_files) list(APPEND util_source_files ${CMAKE_CURRENT_LIST_DIR}/${file}) endforeach() + +set(PSB_util_source_C_files + metis_int.c + psb_amd_order.c + ) +foreach(file IN LISTS PSB_util_source_C_files) + list(APPEND util_source_C_files ${CMAKE_CURRENT_LIST_DIR}/${file}) +endforeach()