<commit_before>include(CheckFunctionExists)
include(CheckCSourceCompiles)

find_package(MPI)
if(NOT MPI_C_FOUND)
  message(FATAL_ERROR "MPI C compiler was not found and is required")
endif()
include_directories(${MPI_C_INCLUDE_PATH})
set(EXTRA_FLAGS "${EXTRA_FLAGS} ${MPI_C_COMPILE_FLAGS}")

# Issue an error if a buggy version of OpenMPI is detected
# ========================================================
include(LibFindMacros)
set(MPI_INCLUDE_DIR ${MPI_C_INCLUDE_PATH}) # forces this dir to be checked 1st?
libfind_header(MPI MPI_HEADER_DIR "mpi.h")
if(NOT MPI_HEADER_DIR)
  message(FATAL_ERROR 
    "Could not find mpi.h using MPI_C_INCLUDE_PATH=${MPI_C_INCLUDE_PATH}")
endif()
if(NOT EXISTS "${MPI_HEADER_DIR}/mpi.h")
  message(FATAL_ERROR "mpi.h was not located within ${MPI_HEADER_DIR}")
endif()
# There does not seem to be a way to capture just the version number itself, 
# and so the following capture the entire line and then search and replace to
# get the version number capture
file(STRINGS "${MPI_HEADER_DIR}/mpi.h" MPI_HEADER)
string(REGEX MATCH "#define[\r\n\t ]+OMPI_MAJOR_VERSION[\r\n\t ]+[0-9]+"
  OMPI_MAJOR_VERSION "${MPI_HEADER}")
string(REGEX MATCH "#define[\r\n\t ]+OMPI_MINOR_VERSION[\r\n\t ]+[0-9]+"
  OMPI_MINOR_VERSION "${MPI_HEADER}")
string(REGEX MATCH "#define[\r\n\t ]+OMPI_RELEASE_VERSION[\r\n\t ]+[0-9]+"
  OMPI_RELEASE_VERSION "${MPI_HEADER}")
if(OMPI_MAJOR_VERSION AND OMPI_MINOR_VERSION AND OMPI_RELEASE_VERSION)
  string(REGEX REPLACE "#define[\r\n\t ]+OMPI_MAJOR_VERSION[\t\n\t ]+([0-9]+)" "\\1" OMPI_MAJOR_VERSION "${OMPI_MAJOR_VERSION}")
  string(REGEX REPLACE "#define[\r\n\t ]+OMPI_MINOR_VERSION[\t\n\t ]+([0-9]+)" "\\1" OMPI_MINOR_VERSION "${OMPI_MINOR_VERSION}")
  string(REGEX REPLACE "#define[\r\n\t ]+OMPI_RELEASE_VERSION[\t\n\t ]+([0-9]+)" "\\1" OMPI_RELEASE_VERSION "${OMPI_RELEASE_VERSION}")
  message("Detected OpenMPI ${OMPI_MAJOR_VERSION}.${OMPI_MINOR_VERSION}.${OMPI_RELEASE_VERSION}")
  # Die if OpenMPI version is 1.8.x with x <= 3
  if(OMPI_MAJOR_VERSION STREQUAL "1" AND OMPI_MINOR_VERSION STREQUAL "8")
    if(OMPI_RELEASE_VERSION STREQUAL "1" OR
       OMPI_RELEASE_VERSION STREQUAL "2" OR
       OMPI_RELEASE_VERSION STREQUAL "3")
      message(FATAL_ERROR "OpenMPI versions 1.8.${OMPI_RELEASE_VERSION} contains insurmountable bugs in MPI_Comm_dup and MPI_Comm_free (please upgrade to 1.8.4)")
    endif()
  endif()
endif()

# Ensure that we have MPI1 by looking for MPI_Reduce_scatter
# ==========================================================
set(CMAKE_REQUIRED_FLAGS "${MPI_C_COMPILE_FLAGS} ${MPI_LINK_FLAGS}")
set(CMAKE_REQUIRED_INCLUDES ${MPI_C_INCLUDE_PATH})
set(CMAKE_REQUIRED_LIBRARIES ${MPI_C_LIBRARIES})
check_function_exists(MPI_Reduce_scatter EL_HAVE_MPI_REDUCE_SCATTER)
if(NOT EL_HAVE_MPI_REDUCE_SCATTER)
  message(FATAL_ERROR "Could not find MPI_Reduce_scatter")
endif()

# Ensure that we have MPI2 by looking for MPI_Type_create_struct
# ==============================================================
check_function_exists(MPI_Type_create_struct EL_HAVE_MPI_TYPE_CREATE_STRUCT)
if(NOT EL_HAVE_MPI_TYPE_CREATE_STRUCT)
  message(FATAL_ERROR "Could not find MPI_Type_create_struct")
endif()

# Ensure that we have MPI_[UNSIGNED_]LONG_LONG if compiling with 64-bit integers
# ==============================================================================
set(MPI_LONG_LONG_CODE
    "#include \"mpi.h\"
     int main( int argc, char* argv[] )
     {
         MPI_Init( &argc, &argv );
         MPI_Datatype lli = MPI_LONG_LONG_INT;
         MPI_Datatype llu = MPI_UNSIGNED_LONG_LONG;
         MPI_Finalize();
         return 0;
     }")<commit_msg>Removing false warning about early versions of OpenMPI (which were due to it being less robust to freeing and immediately recreating MPI_Comm's potentially changing the communicator handle)<commit_after>include(CheckFunctionExists)
include(CheckCSourceCompiles)

find_package(MPI)
if(NOT MPI_C_FOUND)
  message(FATAL_ERROR "MPI C compiler was not found and is required")
endif()
include_directories(${MPI_C_INCLUDE_PATH})
set(EXTRA_FLAGS "${EXTRA_FLAGS} ${MPI_C_COMPILE_FLAGS}")

# Ensure that we have MPI1 by looking for MPI_Reduce_scatter
# ==========================================================
set(CMAKE_REQUIRED_FLAGS "${MPI_C_COMPILE_FLAGS} ${MPI_LINK_FLAGS}")
set(CMAKE_REQUIRED_INCLUDES ${MPI_C_INCLUDE_PATH})
set(CMAKE_REQUIRED_LIBRARIES ${MPI_C_LIBRARIES})
check_function_exists(MPI_Reduce_scatter EL_HAVE_MPI_REDUCE_SCATTER)
if(NOT EL_HAVE_MPI_REDUCE_SCATTER)
  message(FATAL_ERROR "Could not find MPI_Reduce_scatter")
endif()

# Ensure that we have MPI2 by looking for MPI_Type_create_struct
# ==============================================================
check_function_exists(MPI_Type_create_struct EL_HAVE_MPI_TYPE_CREATE_STRUCT)
if(NOT EL_HAVE_MPI_TYPE_CREATE_STRUCT)
  message(FATAL_ERROR "Could not find MPI_Type_create_struct")
endif()

# Ensure that we have MPI_[UNSIGNED_]LONG_LONG if compiling with 64-bit integers
# ==============================================================================
set(MPI_LONG_LONG_CODE
    "#include \"mpi.h\"
     int main( int argc, char* argv[] )
     {
         MPI_Init( &argc, &argv );
         MPI_Datatype lli = MPI_LONG_LONG_INT;
         MPI_Datatype llu = MPI_UNSIGNED_LONG_LONG;
         MPI_Finalize();
         return 0;
     }")
{'fraction_non_alphanumeric': 0.1822105460686808, 'fraction_numerical': 0.007318446237568024, 'mean_word_length': 6.464985994397759, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1163948', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1882, 'n_words': 398}