From 9ed59a455d6b64e1cad29af6083d394a5dbae148 Mon Sep 17 00:00:00 2001 From: Debolskiy Andrey <and.debol@gmail.com> Date: Mon, 22 Jun 2020 21:06:18 +0300 Subject: [PATCH] remade building system to Cmake --- .gitignore | 4 +- CMakeLists.txt | 316 +++++++++++++++++++++++++++++ ParLib.src/CMakeLists.txt | 247 ++++++++++++++++++++++ ParLib.src/README | 5 +- ParLib.src/bexchangef.c | 2 +- ParLib.src/man/CMakeLists.txt | 6 + ParLib.src/parlib.c | 46 ++--- ParLib.src/parlib.h | 1 - ParLib.src/parlibc-test.c | 13 ++ ParLib.src/parlibf.c | 7 +- ParLib.src/parlibf.h | 17 +- ParLib.src/parlibf_test.f90 | 8 + ParLib.src/plutils/CMakeLists.txt | 8 + ParLib.src/{ => plutils}/plutils.c | 26 +-- ParLib.src/{ => plutils}/plutils.h | 4 +- 15 files changed, 657 insertions(+), 53 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 ParLib.src/CMakeLists.txt create mode 100644 ParLib.src/man/CMakeLists.txt create mode 100644 ParLib.src/parlibc-test.c create mode 100644 ParLib.src/parlibf_test.f90 create mode 100644 ParLib.src/plutils/CMakeLists.txt rename ParLib.src/{ => plutils}/plutils.c (90%) rename ParLib.src/{ => plutils}/plutils.h (91%) diff --git a/.gitignore b/.gitignore index 69f2b7b..81c0ed9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -#This is a gitignore file for parlib +#This is a gitignore file for parLIB #object files *.o @@ -7,3 +7,5 @@ #copied manual and headers ./man/ include/ +.idea/ +.DS_Store \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ba51d68 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,316 @@ +if (POLICY CMP0001) + cmake_policy(SET CMP0001 OLD) +endif (POLICY CMP0001) +set(CMAKE_BACKWARDS_COMPATIBILITY 2.8.12) +cmake_minimum_required(VERSION 2.8.12) +if (POLICY CMP0048) + cmake_policy(SET CMP0048 NEW) +endif (POLICY CMP0048) +if (POLICY CMP0054) + cmake_policy(SET CMP0054 NEW) +endif (POLICY CMP0054) +if (POLICY CMP0076) + cmake_policy(SET CMP0076 NEW) +endif (POLICY CMP0076) + +project(parLIB VERSION 2.3 + DESCRIPTION "INM ParLib is a high level library facilitating the coding of finite difference and spectral approximation weather and climate prediction models on distributed memory parallel computers." + HOMEPAGE_URL "http://tesla.parallel.ru/debol/parlib" + LANGUAGES C CXX Fortran) + +# specify the C++ standard +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED False) + +# Force verbose make output +set(CMAKE_VERBOSE_MAKEFILE ON) +# auto-configure style checks, other CMake modules. +INCLUDE(CheckLibraryExists) +INCLUDE(CheckIncludeFile) +INCLUDE(CheckIncludeFiles) +INCLUDE(CheckTypeSize) +INCLUDE(CheckFunctionExists) +INCLUDE(CheckCXXSourceCompiles) +INCLUDE(CheckCSourceCompiles) +INCLUDE(TestBigEndian) +INCLUDE(CheckSymbolExists) +INCLUDE(GetPrerequisites) +INCLUDE(CheckCCompilerFlag) +FIND_PACKAGE(PkgConfig QUIET) + +# A macro to check if a C linker supports a particular flag. +MACRO(CHECK_C_LINKER_FLAG M_FLAG M_RESULT) + SET(T_REQ_FLAG "${CMAKE_REQUIRED_FLAGS}") + SET(CMAKE_REQUIRED_FLAGS "${M_FLAG}") + CHECK_C_SOURCE_COMPILES("int main() {return 0;}" ${M_RESULT}) + SET(CMAKE_REQUIRED_FLAGS "${T_REQ_FLAG}") +ENDMACRO() +message(STATUS "Project will be installed to ${CMAKE_INSTALL_PREFIX}") +if(NOT CMAKE_BUILD_TYPE) +set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) +endif() +message(STATUS "Build type set to ${CMAKE_BUILD_TYPE}") + +# Set variable to define the build type. +INCLUDE(GenerateExportHeader) + +#Global Config + +## +# Default building shared libraries. +# BUILD_SHARED_LIBS is provided by/used by +# CMake directly. +## +OPTION(BUILD_SHARED_LIBS "Configure parLIB as a shared library." ON) +IF(BUILD_SHARED_LIBS) + SET(CMAKE_POSITION_INDEPENDENT_CODE ON) +ENDIF() +OPTION(BUILD_STATIC_LIBS "Configure parLIB as a static library." ON) +#Specifying if we want to build Fortran libraries +option(BUILD_FORT_LIBS "build Fortran libraries" True) + + +# Set some default linux gcc & apple compiler options for +# debug builds. +IF(CMAKE_COMPILER_IS_GNUCC OR APPLE) + # Check to see if -Wl,--no-undefined is supported. +CHECK_C_LINKER_FLAG("-Wl,--no-undefined" LIBTOOL_HAS_NO_UNDEFINED) + +IF(LIBTOOL_HAS_NO_UNDEFINED) + SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -Wl,--no-undefined") +ENDIF() +SET(CMAKE_REQUIRED_FLAGS "${TMP_CMAKE_REQUIRED_FLAGS}") +ENDIF(CMAKE_COMPILER_IS_GNUCC OR APPLE) + + +ADD_DEFINITIONS() +#Fixing installation directories +include(GNUInstallDirs) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) + +set(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries") +set(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for executables") +set(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Installation directory for header files") +if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_CMAKEDIR CMake) +else() + set(DEF_INSTALL_CMAKEDIR share/cmake/${PROJECT_NAME}) + foreach(p LIB BIN INCLUDE CMAKE) + file(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${INSTALL_${p}DIR} _path ) + message(STATUS "Installing ${p} components to ${_path}") + unset(_path) + endforeach() +endif() +set(INSTALL_CMAKEDIR ${DEF_INSTALL_CMAKEDIR} CACHE PATH "Installation directory for CMake files") + + +# Suppress CRT Warnings. +# Only necessary for Windows +IF(MSVC) + ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) +ENDIF() + +## +# Configuration for post-install RPath +# Adapted from http://www.cmake.org/Wiki/CMake_RPATH_handling +## +IF(NOT MSVC AND BUILD_SHARED_LIBS) + # use, i.e. don't skip the full RPATH for the build tree + SET(CMAKE_SKIP_BUILD_RPATH FALSE) + + # when building, don't use the install RPATH already + # (but later on when installing) + SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + + if(APPLE) + set(CMAKE_MACOSX_RPATH ON) + endif(APPLE) + + # add the automatically determined parts of the RPATH + # which point to directories outside the build tree to the install RPATH + SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + + # the RPATH to be used when installing, + # but only if it's not a system directory + LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir) + IF("${isSystemDir}" STREQUAL "-1") + SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + ENDIF("${isSystemDir}" STREQUAL "-1") + +ENDIF() + +## +# End configuration for post-install RPath +## + +# Set the appropriate compiler/architecture for universal OSX binaries. +IF(${CMAKE_SYSTEM_NAME} EQUAL "Darwin") + SET(CMAKE_OSX_ARCHITECTURES i386;x86_64) +ENDIF(${CMAKE_SYSTEM_NAME} EQUAL "Darwin") + +# Macro for replacing '/MD' with '/MT'. +# Used only on Windows, /MD tells VS to use the shared +# CRT libs, MT tells VS to use the static CRT libs. +# +# Taken From: +# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F +# +MACRO(specify_static_crt_flag) + SET(vars + CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL + CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_CXX_FLAGS_RELWITHDEBINFO) + + FOREACH(flag_var ${vars}) + IF(${flag_var} MATCHES "/MD") + STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") + ENDIF() + ENDFOREACH() + + FOREACH(flag_var ${vars}) + MESSAGE(STATUS " '${flag_var}': ${${flag_var}}") + ENDFOREACH() + MESSAGE(STATUS "") +ENDMACRO() + + +# Option to Build DLL +IF(WIN32) + OPTION(ENABLE_DLL "Build a Windows DLL." ${BUILD_SHARED_LIBS}) + IF(ENABLE_DLL) + SET(BUILD_DLL ON CACHE BOOL "") + ADD_DEFINITIONS(-DDLL_PARLIB) + ADD_DEFINITIONS(-DDLL_EXPORT) + ADD_DEFINITIONS(-DUTF8PROC_DLLEXPORT) + ENDIF() +ENDIF() + +#Checks +CHECK_INCLUDE_FILE("stdio.h" HAVE_STDIO_H) +IF(MSVC) + CHECK_INCLUDE_FILE("io.h" HAVE_IO_H) +ENDIF(MSVC) + + +enable_testing() + +# A cmake script to print out information at the end of the configuration step. +MACRO(print_conf_summary) + MESSAGE("") + MESSAGE("") + MESSAGE("Configuration Summary:") + MESSAGE("") + MESSAGE(STATUS "Building Shared Libraries: ${BUILD_SHARED_LIBS}") + MESSAGE(STATUS "Building Static Libraries: ${BUILD_STATIC_LIBS}") + MESSAGE(STATUS "Building Fortran Libraries: ${BUILD_FORT_LIBS}") + MESSAGE("") + MESSAGE("Tests Enabled: ${ENABLE_TESTS}") + MESSAGE("") + IF(CMAKE_PREFIX_PATH) + MESSAGE(STATUS "CMake Prefix Path: ${CMAKE_PREFIX_PATH}") + ENDIF() + MESSAGE(STATUS "CMAKE_LIB_DIR: ${INSTALL_LIBDIR}") + MESSAGE(STATUS "CMAKE_LIB_DIR: ${INSTALL_INCLUDEDIR}") + MESSAGE(STATUS "Build Type: ${CMAKE_BUILD_TYPE}") + MESSAGE(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}") + MESSAGE(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") + IF("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") + MESSAGE(STATUS "CMAKE_C_FLAGS_DEBUG: ${CMAKE_C_FLAGS_DEBUG}") + ENDIF() + IF("${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE") + MESSAGE(STATUS "CMAKE_C_FLAGS_RELEASE: ${CMAKE_C_FLAGS_RELEASE}") + ENDIF() + ENDMACRO(print_conf_summary) + # Create config.h file. +#configure_file("${parLIB_SOURCE_DIR}/config.h.cmake.in" +# "${parLIB_BINARY_DIR}/config.h") +#ADD_DEFINITIONS(-DHAVE_CONFIG_H) +#INCLUDE_DIRECTORIES(${parLIB_BINARY_DIR}) +# End autotools-style checs for config.h + + +#INSTALLATION + + + +#Include main list +#Checking if there is an MPI library +find_package(MPI REQUIRED) +if(MPI_FOUND) + #include(CMakePrintHelpers) + # cmake_print_properties( + # TARGETS MPI::MPI_C MPI::MPI_Fortran + # PROPERTIES INTERFACE_LINK_LIBRARIES ) + #set(CMAKE_C_COMPILE_FLAGS "${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS} -std=gnu11") + #list(REMOVE_DUPLICATES CMAKE_C_COMPILE_FLAGS) + #set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS} -std=gnu11") + #list(REMOVE_DUPLICATES CMAKE_C_COMPILE_FLAGS) + #set(CMAKE_CXX_COMPILE_FLAGS "${CMAKE_CXX_COMPILE_FLAGS} ${MPI_CXX_COMPILE_FLAGS}") + #set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${MPI_CXX_LINK_FLAGS}") + #include_directories(MPI_C_INCLUDE_PATH) + #include_directories(MPI_CXX_INCLUDE_PATH) + message(STATUS "Found MPI") +else() + message(STATUS "MPI NOT FOUND PARLIB WILL NOT BE BUILD") +endif()#Checking if there is an MPI library + +INCLUDE(InstallRequiredSystemLibraries) +add_subdirectory(ParLib.src) + +#testing +if(BUILD_SHARED_LIBS) +add_test(NAME use_test_shared + COMMAND $<TARGET_FILE:parlibc_test_shared> + ) +endif(BUILD_SHARED_LIBS) +if(BUILD_STATIC_LIBS) +add_test(NAME use_test_static + COMMAND $<TARGET_FILE:parlibc_test_static> + ) +endif(BUILD_STATIC_LIBS) +if(BUILD_FORT_LIBS) + if(BUILD_SHARED_LIBS) + add_test(NAME use_test_fort_shared + COMMAND $<TARGET_FILE:parlibf_test_shared> + ) + endif(BUILD_SHARED_LIBS) + if(BUILD_STATIC_LIBS) + add_test(NAME use_test_fort_static + COMMAND $<TARGET_FILE:parlibf_test_static> + ) + endif(BUILD_STATIC_LIBS) +endif(BUILD_FORT_LIBS) + + +include(Ctest) + +## +# Brute force, grab all of the dlls from the dependency directory, +# install them in the binary dir. Grab all of the .libs, put them +# in the libdir. +## +IF(MSVC) + FILE(GLOB COPY_FILES ${CMAKE_PREFIX_PATH}/lib/*.lib) + INSTALL(FILES ${COPY_FILES} + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT dependencies) + + FILE(GLOB COPY_FILES ${CMAKE_PREFIX_PATH}/bin/*.dll) + STRING(REGEX REPLACE "msv[.*].dll" "" COPY_FILES "${COPY_FILES}") + INSTALL(FILES ${COPY_FILES} + DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT dependencies) + +ENDIF() + +print_conf_summary() diff --git a/ParLib.src/CMakeLists.txt b/ParLib.src/CMakeLists.txt new file mode 100644 index 0000000..f6f96ac --- /dev/null +++ b/ParLib.src/CMakeLists.txt @@ -0,0 +1,247 @@ + +add_library(plutils STATIC "") +INCLUDE(plutils/CMakeLists.txt) +if(BUILD_SHARED_LIBS) + add_library(parlibc-shared SHARED "") + target_sources(parlibc-shared + PRIVATE + parlib.c + bexchange.c + transpose.c + PUBLIC + parlib.h) + + target_include_directories(parlibc-shared + PUBLIC + $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}> + $<INSTALL_INTERFACE:${INSTALL_INCLUDEDIR}> + ) + target_link_libraries(parlibc-shared + PRIVATE + plutils + PUBLIC + $<$<BOOL:${MPI_FOUND}>:MPI::MPI_C>) + + set_target_properties(parlibc-shared + PROPERTIES + POSITION_INDEPENDENT_CODE 1 + VISIBILITY_INLINES_HIDDEN 1 + SOVERSION ${PROJECT_VERSION_MAJOR} + OUTPUT_NAME "parlib" + PUBLIC_HEADER "parlib.h" + MACOSX_RPATH ON + ) +endif(BUILD_SHARED_LIBS) + +if(BUILD_STATIC_LIBS) + +add_library(parlibc-static STATIC "") +target_sources(parlibc-static + PRIVATE + parlib.c + bexchange.c + transpose.c + PUBLIC + parlib.h) +set_target_properties(parlibc-static + PROPERTIES + POSITION_INDEPENDENT_CODE 1 + SOVERSION ${PROJECT_VERSION_MAJOR} + ARCHIVE_OUTPUT_NAME "parlib" + PUBLIC_HEADER "parlib.h" + ) +target_link_libraries(parlibc-static + PRIVATE + plutils + PUBLIC + $<$<BOOL:${MPI_FOUND}>:MPI::MPI_C>) +target_include_directories(parlibc-static + PUBLIC + $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}> + $<INSTALL_INTERFACE:${INSTALL_INCLUDEDIR}> + ) +endif(BUILD_STATIC_LIBS) +#if (CMAKE_BUILD_TYPE) +# file(COPY parlib.h +# DESTINATION +# ${CMAKE_BINARY_DIR}/include) +#endif() +#install(TARGETS parlibc-static DESTINATION ${CMAKE_BINARY_DIR}/lib) + + +if( BUILD_FORT_LIBS ) +if(BUILD_STATIC_LIBS) + include(FortranCInterface) + FortranCInterface_VERIFY() + FortranCInterface_HEADER(${CMAKE_CURRENT_SOURCE_DIR}/FC.h MACRO_NAMESPACE "FC_") + message(STATUS "FORTRAN_C_INTEFACE TEST: ${FortranCInterface_VERIFIED_C}") + add_definitions(-DFC_MANGLE=1) + add_library(parlibf-static STATIC "") + target_sources(parlibf-static + PRIVATE + parlibf.c + bexchangef.c + transposef.c + FC.h + PUBLIC + parlibf.h) + + target_link_libraries(parlibf-static + PRIVATE + plutils + PUBLIC + MPI::MPI_C + parlibc-static) + set_target_properties(parlibf-static + PROPERTIES + ARCHIVE_OUTPUT_NAME "parlibf" + PUBLIC_HEADER "parlibf.h" + LINKER_LANGUAGE Fortran + ) + target_include_directories(parlibf-static + PUBLIC + $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}> + $<INSTALL_INTERFACE:${INSTALL_INCLUDEDIR}> + ) +endif(BUILD_STATIC_LIBS) + if(BUILD_SHARED_LIBS) + add_library(parlibf-shared SHARED "") + target_sources(parlibf-shared + PRIVATE + parlibf.c + bexchangef.c + transposef.c + FC.h + PUBLIC + parlibf.h) + + target_link_libraries(parlibf-shared + PRIVATE + plutils + PRIVATE + PUBLIC + MPI::MPI_C + parlibc-shared) + + set_target_properties(parlibf-shared + PROPERTIES + POSITION_INDEPENDENT_CODE 1 + VISIBILITY_INLINES_HIDDEN 1 + SOVERSION ${PROJECT_VERSION_MAJOR} + OUTPUT_NAME "parlibf" + PUBLIC_HEADER "parlibf.h" + MACOSX_RPATH ON + LINKER_LANGUAGE Fortran + ) + + target_include_directories(parlibf-shared + PUBLIC + $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}> + $<INSTALL_INTERFACE:${INSTALL_INCLUDEDIR}> + ) +endif(BUILD_SHARED_LIBS) + +endif(BUILD_FORT_LIBS) + +#~TESTS +if(BUILD_FORT_LIBS) +if(BUILD_SHARED_LIBS) +add_executable(parlibf_test_shared parlibf_test.f90) +target_link_libraries(parlibf_test_shared + parlibf-shared) +endif(BUILD_SHARED_LIBS) +if(BUILD_STATIC_LIBS) + add_executable(parlibf_test_static parlibf_test.f90) + target_link_libraries(parlibf_test_static + parlibf-static) +endif(BUILD_STATIC_LIBS) +endif(BUILD_FORT_LIBS) +if(BUILD_SHARED_LIBS) + add_executable(parlibc_test_shared parlibc-test.c) +target_link_libraries(parlibc_test_shared + parlibc-shared) +endif(BUILD_SHARED_LIBS) +if(BUILD_STATIC_LIBS) + add_executable(parlibc_test_static parlibc-test.c) + target_link_libraries(parlibc_test_static + parlibc-static) +endif(BUILD_STATIC_LIBS) +#Installation +if(BUILD_STATIC_LIBS) +install( + TARGETS + parlibc-static + ARCHIVE + DESTINATION ${INSTALL_LIBDIR} + COMPONENT lib + RUNTIME + DESTINATION ${INSTALL_BINDIR} + COMPONENT bin + LIBRARY + DESTINATION ${INSTALL_LIBDIR} + COMPONENT lib + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDEDIR} + COMPONENT dev +) +endif(BUILD_STATIC_LIBS) +if(BUILD_SHARED_LIBS) +install( + TARGETS + parlibc-shared + ARCHIVE + DESTINATION ${INSTALL_LIBDIR} + COMPONENT lib + RUNTIME + DESTINATION ${INSTALL_BINDIR} + COMPONENT bin + LIBRARY + DESTINATION ${INSTALL_LIBDIR} + COMPONENT lib + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDEDIR} + COMPONENT dev +) +endif(BUILD_SHARED_LIBS) + +if( BUILD_FORT_LIBS ) +if(BUILD_STATIC_LIBS) +install( + TARGETS + parlibf-static + ARCHIVE + DESTINATION ${INSTALL_LIBDIR} + COMPONENT lib + RUNTIME + DESTINATION ${INSTALL_BINDIR} + COMPONENT bin + LIBRARY + DESTINATION ${INSTALL_LIBDIR} + COMPONENT lib + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDEDIR} + COMPONENT dev +) +endif(BUILD_STATIC_LIBS) +if(BUILD_SHARED_LIBS) + install( + TARGETS + parlibf-shared + ARCHIVE + DESTINATION ${INSTALL_LIBDIR} + COMPONENT lib + RUNTIME + DESTINATION ${INSTALL_BINDIR} + COMPONENT bin + LIBRARY + DESTINATION ${INSTALL_LIBDIR} + COMPONENT lib + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDEDIR} + COMPONENT dev + ) +endif(BUILD_SHARED_LIBS) +endif(BUILD_FORT_LIBS) + +#adding man pages +add_subdirectory(man) \ No newline at end of file diff --git a/ParLib.src/README b/ParLib.src/README index 11c9a54..2d00726 100644 --- a/ParLib.src/README +++ b/ParLib.src/README @@ -1,10 +1,13 @@ INM ParLib v2.2 ------------------------------------------------------------------------------- -author: Val Gloukhov +authors: Val Gloukhov Institute of Numerical Mathematics of the Russian Academy of Sciences (gluhoff@inm.ras.ru) + Evgeny Mortikov + Research Computing Center of Lomonosov Moscow State University + latest update: 11/30/2001 ------------------------------------------------------------------------------- diff --git a/ParLib.src/bexchangef.c b/ParLib.src/bexchangef.c index 39e4184..2accdbd 100644 --- a/ParLib.src/bexchangef.c +++ b/ParLib.src/bexchangef.c @@ -1,4 +1,4 @@ -#include <stdlib.h> +#include<stdlib.h> #include "parlib.h" // -------------------------------------------------------------------------- // diff --git a/ParLib.src/man/CMakeLists.txt b/ParLib.src/man/CMakeLists.txt new file mode 100644 index 0000000..69cc8db --- /dev/null +++ b/ParLib.src/man/CMakeLists.txt @@ -0,0 +1,6 @@ +set(MAN_FILES P_BExchange.3 P_BExchange_init.3 P_Transpose.3 P_Transpose_init.3) + +add_custom_target(man ALL DEPENDS ${MAN_FILES}) +message("Building man pages") +INSTALL(FILES ${MAN_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man3) + diff --git a/ParLib.src/parlib.c b/ParLib.src/parlib.c index bf06244..95b564e 100644 --- a/ParLib.src/parlib.c +++ b/ParLib.src/parlib.c @@ -37,7 +37,7 @@ void ParLib_deinit() for (k = 0; k < bexch_hptr; k++) { get_bexch_handle(&bexchange, &exch_mode, k); - P_BExchange_opt_free(bexchange, exch_mode); + P_BExchange_opt_free(bexchange, exch_mode); free(bexchange); } bexch_hptr = 0; @@ -46,8 +46,8 @@ void ParLib_deinit() Transposition *transp; for (k = 0; k < transp_hptr; k++) { get_transp_handle(&transp, &exch_mode, k); - - P_Transpose_opt_free(transp, exch_mode); + + P_Transpose_opt_free(transp, exch_mode); free(transp); } transp_hptr = 0; @@ -61,11 +61,11 @@ void ParLib_deinit() // -------------------------------------------------------------------------- // int save_bexch_handle(BExchange *bexchange, int exch_mode) { - // saving handle - bexch_hlist[bexch_hptr] = bexchange; - bexch_hmode[bexch_hptr] = exch_mode; - bexch_hptr++; - + // saving handle + bexch_hlist[bexch_hptr] = bexchange; + bexch_hmode[bexch_hptr] = exch_mode; + bexch_hptr++; + return bexch_hptr - 1; } @@ -77,11 +77,11 @@ void get_bexch_handle(BExchange** bexchange, int* exch_mode, int exch_id) void remove_bexch_handle(int exch_id) { - int k; - for (k = exch_id; k < bexch_hptr - 1; k++) { - bexch_hlist[k] = bexch_hlist[k + 1]; - bexch_hmode[k] = bexch_hmode[k + 1]; - } + int k; + for (k = exch_id; k < bexch_hptr - 1; k++) { + bexch_hlist[k] = bexch_hlist[k + 1]; + bexch_hmode[k] = bexch_hmode[k + 1]; + } if (bexch_hptr > 0) bexch_hptr--; } // -------------------------------------------------------------------------- // @@ -90,11 +90,11 @@ void remove_bexch_handle(int exch_id) // -------------------------------------------------------------------------- // int save_transp_handle(Transposition *transp, int exch_mode) { - // saving handle - transp_hlist[transp_hptr] = transp; - transp_hmode[transp_hptr] = exch_mode; - transp_hptr++; - + // saving handle + transp_hlist[transp_hptr] = transp; + transp_hmode[transp_hptr] = exch_mode; + transp_hptr++; + return transp_hptr - 1; } @@ -106,11 +106,11 @@ void get_transp_handle(Transposition** transp, int* exch_mode, int exch_id) void remove_transp_handle(int exch_id) { - int k; - for (k = exch_id; k < transp_hptr - 1; k++) { - transp_hlist[k] = transp_hlist[k + 1]; - transp_hmode[k] = transp_hmode[k + 1]; - } + int k; + for (k = exch_id; k < transp_hptr - 1; k++) { + transp_hlist[k] = transp_hlist[k + 1]; + transp_hmode[k] = transp_hmode[k + 1]; + } if (transp_hptr > 0) transp_hptr--; } // -------------------------------------------------------------------------- // diff --git a/ParLib.src/parlib.h b/ParLib.src/parlib.h index 617853d..fc9c964 100644 --- a/ParLib.src/parlib.h +++ b/ParLib.src/parlib.h @@ -4,7 +4,6 @@ #include "plutils.h" - #define IS_MPI_TYPED 0 #define IS_MPI_MANUAL_PACK 1 #define IS_MPI_TYPED_PERSISTENT 2 diff --git a/ParLib.src/parlibc-test.c b/ParLib.src/parlibc-test.c new file mode 100644 index 0000000..eab3e71 --- /dev/null +++ b/ParLib.src/parlibc-test.c @@ -0,0 +1,13 @@ +// +// Created by Andrey Debolskiy on 05.06.2020. +// +#include "parlib.h" +#include <stdio.h> + + +int main() { + ParLib_init(); + ParLib_deinit(); + printf("Parlib Works"); + return 0; +} diff --git a/ParLib.src/parlibf.c b/ParLib.src/parlibf.c index 620ad39..e2be420 100644 --- a/ParLib.src/parlibf.c +++ b/ParLib.src/parlibf.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include "parlib.h" - +#include "FC.h" // ParLib v1.8 initialization // -------------------------------------------------------------------------- // #ifdef FORTRANUNDERSCORE @@ -8,8 +8,9 @@ void parlib_init_() #elif defined(FORTRANDOUBLEUNDERSCORE) void parlib_init__() #else -void parlib_init() +void FC_GLOBAL(parlib_init,parlib_init)() //parlib_init() #endif + { ParLib_init(); } @@ -19,7 +20,7 @@ void parlib_deinit_() #elif defined(FORTRANDOUBLEUNDERSCORE) void parlib_deinit__() #else -void parlib_deinit() +void FC_GLOBAL(parlib_deinit,parlib_deinit)()//parlib_deinit() #endif { ParLib_deinit(); diff --git a/ParLib.src/parlibf.h b/ParLib.src/parlibf.h index f1be357..727d562 100644 --- a/ParLib.src/parlibf.h +++ b/ParLib.src/parlibf.h @@ -1,9 +1,10 @@ - INTEGER HANDLE_SIZE - PARAMETER (HANDLE_SIZE = 2) - - INTEGER MAX_PARLIB_MP_DIMS - PARAMETER (MAX_PARLIB_MP_DIMS = 6) - + + INTEGER HANDLE_SIZE + PARAMETER (HANDLE_SIZE = 2) + + INTEGER MAX_PARLIB_MP_DIMS + PARAMETER (MAX_PARLIB_MP_DIMS = 6) + INTEGER IS_MPI_TYPED PARAMETER (IS_MPI_TYPED = 0) @@ -13,5 +14,5 @@ INTEGER IS_MPI_TYPED_PERSISTENT PARAMETER (IS_MPI_TYPED_PERSISTENT = 2) - INTEGER IS_MPI_MANUAL_PACK_PERSISTENT - PARAMETER (IS_MPI_MANUAL_PACK_PERSISTENT = 3) + INTEGER IS_MPI_MANUAL_PACK_PERSISTENT + PARAMETER (IS_MPI_MANUAL_PACK_PERSISTENT = 3) diff --git a/ParLib.src/parlibf_test.f90 b/ParLib.src/parlibf_test.f90 new file mode 100644 index 0000000..e0a693e --- /dev/null +++ b/ParLib.src/parlibf_test.f90 @@ -0,0 +1,8 @@ +! Created by on 08.06.2020. +#include "parlibf.h" +program parlibf_test + IMPLICIT NONE + call PARLIB_INIT + write(*,*) "Fortran parlib works" + call PARLIB_DEINIT +end program parlibf_test \ No newline at end of file diff --git a/ParLib.src/plutils/CMakeLists.txt b/ParLib.src/plutils/CMakeLists.txt new file mode 100644 index 0000000..6337eae --- /dev/null +++ b/ParLib.src/plutils/CMakeLists.txt @@ -0,0 +1,8 @@ +target_sources(plutils + PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/plutils.c + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/plutils.h + ) +include_directories(plutils + PUBLIC ${CMAKE_CURRENT_LIST_DIR}) \ No newline at end of file diff --git a/ParLib.src/plutils.c b/ParLib.src/plutils/plutils.c similarity index 90% rename from ParLib.src/plutils.c rename to ParLib.src/plutils/plutils.c index 453b4a3..3b1566a 100644 --- a/ParLib.src/plutils.c +++ b/ParLib.src/plutils/plutils.c @@ -3,7 +3,7 @@ #include <stdlib.h> #include <string.h> -// parlib buffers [definition] +// parLIB buffers [definition] // -------------------------------------------------------------------------- // void *plbuf[MAX_PL_BUFS]; int plbuf_size[MAX_PL_BUFS]; @@ -91,7 +91,7 @@ void free_plbuf(void* ptr, int id) // 1D copy // ----------------------------------------------------------------------------------- // -inline void copy_to_buffer_1d(char* _RESTRICT buf, const char* _RESTRICT const a, +static inline void copy_to_buffer_1d(char* _RESTRICT buf, const char* _RESTRICT const a, const int nx) { int i; @@ -103,7 +103,7 @@ inline void copy_to_buffer_1d(char* _RESTRICT buf, const char* _RESTRICT const a memcpy(buf, a, nx * sizeof(char)); } -inline void copy_from_buffer_1d(char* _RESTRICT a, const char* _RESTRICT const buf, +static inline void copy_from_buffer_1d(char* _RESTRICT a, const char* _RESTRICT const buf, const int nx) { int i; @@ -118,7 +118,7 @@ inline void copy_from_buffer_1d(char* _RESTRICT a, const char* _RESTRICT const b // 2D copy // ----------------------------------------------------------------------------------- // -inline void copy_to_buffer_2d(char* _RESTRICT buf, const char* _RESTRICT const a, +static inline void copy_to_buffer_2d(char* _RESTRICT buf, const char* _RESTRICT const a, const int nx, const int ny, const int shx) { @@ -139,7 +139,7 @@ inline void copy_to_buffer_2d(char* _RESTRICT buf, const char* _RESTRICT const a } } -inline void copy_from_buffer_2d(char* _RESTRICT a, const char* _RESTRICT const buf, +static inline void copy_from_buffer_2d(char* _RESTRICT a, const char* _RESTRICT const buf, const int nx, const int ny, const int shx) { @@ -163,7 +163,7 @@ inline void copy_from_buffer_2d(char* _RESTRICT a, const char* _RESTRICT const b // 3D copy // ----------------------------------------------------------------------------------- // -inline void copy_to_buffer_3d(char* _RESTRICT buf, const char* _RESTRICT const a, +static inline void copy_to_buffer_3d(char* _RESTRICT buf, const char* _RESTRICT const a, const int nx, const int ny, const int nz, const int shx, const int shxy) { @@ -192,7 +192,7 @@ inline void copy_to_buffer_3d(char* _RESTRICT buf, const char* _RESTRICT const a } } -inline void copy_from_buffer_3d(char* _RESTRICT a, const char* _RESTRICT const buf, +static inline void copy_from_buffer_3d(char* _RESTRICT a, const char* _RESTRICT const buf, const int nx, const int ny, const int nz, const int shx, const int shxy) { @@ -224,7 +224,7 @@ inline void copy_from_buffer_3d(char* _RESTRICT a, const char* _RESTRICT const b // 4D copy // ----------------------------------------------------------------------------------- // -inline void copy_to_buffer_4d(char* _RESTRICT buf, const char* _RESTRICT const a, +static inline void copy_to_buffer_4d(char* _RESTRICT buf, const char* _RESTRICT const a, const int nx, const int ny, const int nz, const int np, const int shx, const int shxy, const int shxyz) { @@ -269,7 +269,7 @@ inline void copy_to_buffer_4d(char* _RESTRICT buf, const char* _RESTRICT const a } } -inline void copy_from_buffer_4d(char* _RESTRICT a, const char* _RESTRICT const buf, +static inline void copy_from_buffer_4d(char* _RESTRICT a, const char* _RESTRICT const buf, const int nx, const int ny, const int nz, const int np, const int shx, const int shxy, const int shxyz) { @@ -317,7 +317,7 @@ inline void copy_from_buffer_4d(char* _RESTRICT a, const char* _RESTRICT const b // 5D copy // ----------------------------------------------------------------------------------- // -inline void copy_to_buffer_5d(char* _RESTRICT buf, const char* _RESTRICT const a, +static inline void copy_to_buffer_5d(char* _RESTRICT buf, const char* _RESTRICT const a, const int nx, const int ny, const int nz, const int np, const int nq, const int shx, const int shxy, const int shxyz, const int shxyzp) { @@ -380,7 +380,7 @@ inline void copy_to_buffer_5d(char* _RESTRICT buf, const char* _RESTRICT const a } } -inline void copy_from_buffer_5d(char* _RESTRICT a, const char* _RESTRICT const buf, +static inline void copy_from_buffer_5d(char* _RESTRICT a, const char* _RESTRICT const buf, const int nx, const int ny, const int nz, const int np, const int nq, const int shx, const int shxy, const int shxyz, const int shxyzp) { @@ -447,7 +447,7 @@ inline void copy_from_buffer_5d(char* _RESTRICT a, const char* _RESTRICT const b // 6D copy // ----------------------------------------------------------------------------------- // -inline void copy_to_buffer_6d(char* _RESTRICT buf, const char* _RESTRICT const a, +static inline void copy_to_buffer_6d(char* _RESTRICT buf, const char* _RESTRICT const a, const int nx, const int ny, const int nz, const int np, const int nq, const int ns, const int shx, const int shxy, const int shxyz, const int shxyzp, const int shxyzpq) { @@ -494,7 +494,7 @@ inline void copy_to_buffer_6d(char* _RESTRICT buf, const char* _RESTRICT const a } } -inline void copy_from_buffer_6d(char* _RESTRICT a, const char* _RESTRICT const buf, +static inline void copy_from_buffer_6d(char* _RESTRICT a, const char* _RESTRICT const buf, const int nx, const int ny, const int nz, const int np, const int nq, const int ns, const int shx, const int shxy, const int shxyz, const int shxyzp, const int shxyzpq) { diff --git a/ParLib.src/plutils.h b/ParLib.src/plutils/plutils.h similarity index 91% rename from ParLib.src/plutils.h rename to ParLib.src/plutils/plutils.h index 2a493fb..2219efb 100644 --- a/ParLib.src/plutils.h +++ b/ParLib.src/plutils/plutils.h @@ -4,7 +4,7 @@ #define MIN_MEMCPY_BLOCK 256 // minimum block (in bytes) for memcpy copy (magic number) -#define MAX_PL_BUFS 4096 // maximum number of parlib internal buffers +#define MAX_PL_BUFS 4096 // maximum number of parLIB internal buffers // _RESTRICT definition // ------------------------------------------------------------------- // @@ -20,7 +20,7 @@ // ------------------------------------------------------------------- // -// parlib buffers [declaration] +// parLIB buffers [declaration] // -------------------------------------------------------------------------- // extern void *plbuf[MAX_PL_BUFS]; extern int plbuf_size[MAX_PL_BUFS]; -- GitLab