Skip to content

Commit 55a3cbe

Browse files
authored
Merge pull request #465 from sourceryinstitute/issue-461-and-issue-457
Fix Issue 461 and issue 457
2 parents 1bafc88 + f8d3c26 commit 55a3cbe

File tree

12 files changed

+177
-37
lines changed

12 files changed

+177
-37
lines changed

CMakeLists.txt

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,22 @@ function(check_script_style script_full_path)
500500
endif()
501501
endfunction()
502502

503+
#------------------------------------------------------------------------------
504+
# Add custom properties on targets for controling number of images during tests
505+
#------------------------------------------------------------------------------
506+
define_property(TARGET
507+
PROPERTY MIN_IMAGES
508+
BRIEF_DOCS "Minimum allowable images for the test <integer>"
509+
FULL_DOCS "Property to mark executable targets run as tests that they require at least <MIN_IMAGES> images to run"
510+
)
511+
512+
define_property(TARGET
513+
PROPERTY POWER_2_IMGS
514+
BRIEF_DOCS "True if test must be run with a power of 2 images (T/F)"
515+
FULL_DOCS "Property to mark executable targets run as tests that they require 2^n images."
516+
)
517+
518+
503519
#-------------------------------
504520
# Recurse into the src directory
505521
#-------------------------------
@@ -566,20 +582,32 @@ endif ()
566582
include( ProcessorCount )
567583
ProcessorCount(N_CPU)
568584
function(add_caf_test name num_caf_img test_target)
569-
# Function to add MPI tests.
570-
if ( ((N_CPU LESS num_caf_img) OR (N_CPU EQUAL 0)) )
571-
message(STATUS "Test ${name} is oversubscribed: ${num_caf_img} CAF images requested with ${N_CPU} system processor available.")
572-
if ( openmpi )
573-
if ( N_CPU LESS 2 )
574-
set( num_caf_img 2 )
575-
endif()
576-
set (test_parameters --oversubscribe)
577-
message( STATUS "Open-MPI back end detected, passing --oversubscribe for oversubscribed test, ${name}, with ${num_caf_img} ranks/images." )
578-
endif()
579-
endif()
580-
set(test_parameters -np ${num_caf_img} ${test_parameters})
581-
add_test(NAME ${name} COMMAND "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/cafrun" ${test_parameters} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_target}")
582-
set_property(TEST ${name} PROPERTY PASS_REGULAR_EXPRESSION "Test passed.")
585+
# Function to add MPI tests.
586+
if(TARGET ${test_target})
587+
get_target_property(min_test_imgs ${test_target} MIN_IMAGES)
588+
elseif(TARGET build_${test_target})
589+
get_target_property(min_test_imgs build_${test_target} MIN_IMAGES)
590+
endif()
591+
if(min_test_imgs)
592+
if(num_caf_img LESS min_test_imgs)
593+
message( FATAL_ERROR "Test ${name} requires ${min_test_imgs} but was only given ${num_caf_images}" )
594+
endif()
595+
endif()
596+
if ( ((N_CPU LESS num_caf_img) OR (N_CPU EQUAL 0)) )
597+
message(STATUS "Test ${name} is oversubscribed: ${num_caf_img} CAF images requested with ${N_CPU} system processor available.")
598+
if ( openmpi )
599+
if (min_test_imgs)
600+
set( num_caf_img ${min_test_imgs} )
601+
elseif ( N_CPU LESS 2 )
602+
set( num_caf_img 2 )
603+
endif()
604+
set (test_parameters --oversubscribe)
605+
message( STATUS "Open-MPI back end detected, passing --oversubscribe for oversubscribed test, ${name}, with ${num_caf_img} ranks/images." )
606+
endif()
607+
endif()
608+
set(test_parameters -np ${num_caf_img} ${test_parameters})
609+
add_test(NAME ${name} COMMAND "bash" "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/cafrun" ${test_parameters} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_target}")
610+
set_property(TEST ${name} PROPERTY PASS_REGULAR_EXPRESSION "Test passed.")
583611
endfunction(add_caf_test)
584612

585613
#--------------

prerequisites/install-functions/build_opencoarrays.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ build_opencoarrays()
1313
if [[ -z ${MPIFC:-} || -z ${MPICC:-} ]]; then
1414
emergency "build_opencoarrays.sh: empty \${MPIFC}=${MPIFC:-} or \${MPICC}=${MPICC:-}"
1515
fi
16-
MPIFC_show=($($MPIFC -show))
17-
MPICC_show=($($MPICC -show))
16+
MPIFC_show=($("$MPIFC" -show))
17+
MPICC_show=($("$MPICC" -show))
1818
if [[ "${MPIFC_show[0]}" != *gfortran* || "${MPICC_show[0]}" != *gcc* ]]; then
1919
emergency "build_opencoarrays.sh: MPI doesn't wrap gfortran/gcc: \${MPIFC_show}=${MPIFC_show[*]}, \${MPICC_show}=${MPICC_show[*]}"
2020
fi

prerequisites/install-functions/find_or_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ find_or_install()
212212

213213
# Check consistency of MPIFC, if set, and user-specified Fortran compiler
214214
if [[ ! -z ${MPIFC:-} && ! -z "${arg_f:-}" ]]; then
215-
MPIFC_wraps=$(${MPIFC} --version)
215+
MPIFC_wraps=$("${MPIFC}" --version)
216216
compiler=$(${arg_f} --version)
217217
if [[ "${MPIFC_wraps}" != "${compiler}" ]]; then
218218
emergency "Specified MPI ${MPIFC_wraps} wraps a compiler other than the specified Fortran compiler ${compiler}"

src/extensions/caf.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ cmd="${__base}"
122122
# mac OS doesn't have readlink -f, so need to crawl symlinks manually.
123123
# See: https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
124124
current_dir="${PWD}"
125-
cd "${__dir}"
125+
cd "${__dir}" || exit 5
126126
target_file="${__file}"
127127
max_iter=1000
128128
iter=0
129129
while [[ -L "${target_file}" ]]; do
130130
target_file="$(readlink "${target_file}")"
131-
cd "$(dirname "${target_file}")"
131+
cd "$(dirname "${target_file}")" || exit 5
132132
target_file="$(basename "${target_file}")"
133133
if ((++iter >= max_iter)); then
134134
echo "Failed to compute OpenCoarrays instalation prefix!" >&2
@@ -142,7 +142,7 @@ cd "${__dir}"
142142
# shellcheck disable=SC2034
143143
prefix="${true_dir%/bin}"
144144
# echo "Install prefix is ${prefix}" # for debugging
145-
cd "${current_dir}"
145+
cd "${current_dir}" || exit 5
146146
# echo "Current directory is $(pwd)"
147147
# echo "This script is in ${__dir}"
148148

src/extensions/cafrun.in

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434
# 2. The environment variable "FC" is used to determine the identity fo the Fortran compiler/linker.
3535
# 3. If "FC" is empty, a default value of "mpifort" is used.
3636

37+
# Exit on error. Append "|| true" if you expect an error.
38+
set -o errexit
39+
# Exit on error inside any functions or subshells.
40+
set -o errtrace
41+
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
42+
set -o nounset
43+
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
44+
set -o pipefail
45+
# Turn on traces, useful while debugging but commented out by default
46+
# set -o xtrace
47+
3748

3849
#---------------------
3950
# Configured variables
@@ -44,8 +55,8 @@
4455
#
4556

4657
caf_version='@CAF_VERSION@'
47-
CAFRUN='@MPIEXEC@'
48-
if [[ ${CAFRUN} == @*@ ]]; then
58+
CAFRUN="@MPIEXEC@"
59+
if [[ "${CAFRUN}" == @*@ ]]; then
4960
CAFRUN=mpiexec
5061
fi
5162
have_failed_img=@HAVE_FAILED_IMG@
@@ -56,17 +67,82 @@ numproc_flag='@MPIEXEC_NUMPROC_FLAG@'
5667
if [[ ${numproc_flag} == @*@ ]]; then
5768
numproc_flag='-np'
5869
fi
59-
preflags='@MPIEXEC_PREFLAGS@'
60-
if [[ ${preflags} == @*@ ]]; then
70+
preflags="@MPIEXEC_PREFLAGS@"
71+
if [[ "${preflags}" == @*@ ]]; then
6172
unset preflags
6273
fi
63-
postflags='@MPIEXEC_POSTFLAGS@'
64-
if [[ ${postflags} == @*@ ]]; then
74+
postflags="@MPIEXEC_POSTFLAGS@"
75+
if [[ "${postflags}" == @*@ ]]; then
6576
unset postflags
6677
fi
78+
#-------------------------
79+
# End configured variables
80+
#-------------------------
81+
82+
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
83+
__i_am_main_script="0" # false
84+
85+
# shellcheck disable=SC2154
86+
if [[ "${__usage+x}" ]]; then
87+
if [[ "${BASH_SOURCE[1]}" == "${0}" ]]; then
88+
__i_am_main_script="1" # true
89+
fi
90+
__caf_tmp_source_idx=1
91+
fi
92+
else
93+
# shellcheck disable=SC2034
94+
__i_am_main_script="1" # true
95+
fi
96+
97+
# Set magic variables for current file, directory, os, etc.
98+
__dir="$(cd "$(dirname "${BASH_SOURCE[${__caf_tmp_source_idx:-0}]}")" && pwd)"
99+
__file="${__dir}/$(basename "${BASH_SOURCE[${__caf_tmp_source_idx:-0}]}")"
100+
# shellcheck disable=SC2034
101+
__base="$(basename "${__file}")"
102+
cmd="${__base}"
103+
104+
# Set installation prefix. Compute this dynamically assuming this script is in a bin/ subdir
105+
# Dereference symbolic links and canonicalize (i.e., abs path) prefix in case stow, homebrew, etc being used
106+
# mac OS doesn't have readlink -f, so need to crawl symlinks manually.
107+
# See: https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
108+
current_dir="${PWD}"
109+
cd "${__dir}" || exit 5
110+
target_file="${__file}"
111+
max_iter=1000
112+
iter=0
113+
while [[ -L "${target_file}" ]]; do
114+
target_file="$(readlink "${target_file}")"
115+
cd "$(dirname "${target_file}")" || exit 5
116+
target_file="$(basename "${target_file}")"
117+
if ((++iter >= max_iter)); then
118+
echo "Failed to compute OpenCoarrays instalation prefix!" >&2
119+
echo "Likely cause: circular symlink cycles." >&2
120+
echo "Aborting!" >&2
121+
exit 200
122+
fi
123+
done
124+
true_dir="$(pwd -P)"
125+
true_dir="${true_dir%/}"
126+
# shellcheck disable=SC2034
127+
prefix="${true_dir%/bin}"
128+
# echo "Install prefix is ${prefix}" # for debugging
129+
cd "${current_dir}" || exit 5
130+
# echo "Current directory is $(pwd)"
131+
# echo "This script is in ${__dir}"
132+
133+
# Error tracing
134+
# requires `set -o errtrace`
135+
__caf_err_report() {
136+
local error_code
137+
error_code=${?}
138+
echo "Error in ${__file} in function ${1} on line ${2}. Please report this error at http://bit.ly/OpenCoarrays-new-issue" >&2
139+
exit ${error_code}
140+
}
141+
# Always provide an error backtrace
142+
trap '__caf_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
143+
67144

68145
usage() {
69-
cmd="$(basename "${0}")"
70146
echo ""
71147
echo " ${cmd} - Coarray Fortran executable launcher for OpenCoarrays"
72148
echo ""
@@ -75,7 +151,7 @@ usage() {
75151
echo " Options:"
76152
echo " --help, -h Show this help message"
77153
echo " --version, -v, -V Report version and copyright information"
78-
echo " --wraps, -w, Report the name of the wrapped compiler"
154+
echo " --wraps, -w, Report info about the wrapped MPI launcher"
79155
echo " -np <N>, Number of images, N, to execute, N must be a positive integer"
80156
echo " --reenable-auto-cleanup Turn off failed images support (if library support is present)"
81157
echo " This option re-enables MPI auto cleanup, which is disabled by"
@@ -84,6 +160,9 @@ usage() {
84160
echo " failed image support is present, OpenCoarrays triggers cleanup"
85161
echo " explicitly when a failed/stopped image is encountered in an"
86162
echo " image control statement without a \`stat=\` clause."
163+
ehco " --show, -s, Show the command that the wrapper will execute. You can pass"
164+
echo " this as the first argument and then the additional arguments"
165+
echo " that you're planning to pass to perform a dry run."
87166
echo ""
88167
echo " Example usage:"
89168
echo ""

src/mpi/CMakeLists.txt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ CHECK_SYMBOL_EXISTS(SIGKILL "signal.h" HAVE_SIGKILL)
4949
if(NOT HAVE_SIGKILL) # try -D_POSIX, needed for mingw-w64, maybe others, see #435
5050
# https://github.com/sourceryinstitute/OpenCoarrays/issues/435#issuecomment-323592433
5151
list( APPEND CMAKE_REQUIRED_DEFINITIONS -D_POSIX)
52-
CHECK_SYMBOL_EXISTS(SIGKILL "signal.h" HAVE_SIGKILL)
53-
if(HAVE_SIGKILL)
52+
CHECK_SYMBOL_EXISTS(SIGKILL "signal.h" HAVE_SIGKILL2)
53+
if(HAVE_SIGKILL2)
54+
set(HAVE_SIGKILL ${HAVE_SIGKILL2})
5455
add_definitions(-D_POSIX)
5556
endif()
5657
endif()
@@ -115,11 +116,18 @@ endif()
115116
#---------------------------------------------------
116117
# Windows Intel MPI compatibility, see GH issue #435
117118
#---------------------------------------------------
118-
CHECK_SYMBOL_EXISTS(I_MPI_VERSION mpi.h HAVE_Intel_MPI)
119+
set(old_cmake_required_includes "${CMAKE_REQUIRED_INCLUDES}")
120+
if(CMAKE_REQUIRED_INCLUDES)
121+
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${MPI_C_INCLUDE_PATH})
122+
else()
123+
set(CMAKE_REQUIRED_INCLUDES ${MPI_C_INCLUDE_PATH})
124+
endif()
125+
CHECK_INCLUDE_FILES("mpi.h" HAVE_MPI_H)
126+
CHECK_SYMBOL_EXISTS(I_MPI_VERSION "mpi.h" HAVE_Intel_MPI)
119127
if(HAVE_Intel_MPI AND WIN32)
120128
add_definitions(-DUSE_GCC)
121129
endif()
122-
130+
set(CMAKE_REQUIRED_INCLUDES ${old_cmake_required_includes})
123131

124132
add_library(opencoarrays_mod OBJECT ../extensions/opencoarrays.F90)
125133
set_target_properties(opencoarrays_mod
@@ -148,10 +156,12 @@ set_target_properties ( caf_mpi
148156
)
149157

150158
# Create a symlink in the include dir
151-
add_custom_command(TARGET caf_mpi
152-
POST_BUILD
153-
COMMAND ${CMAKE_COMMAND} -E create_symlink "./${mod_dir_tail}/opencoarrays.mod" "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/opencoarrays.mod"
154-
COMMENT "Creating symlink ${CMAKE_INSTALL_INCLUDEDIR}/opencoarrays.mod --> ${CMAKE_INSTALL_INCLUDEDIR}/${mod_dir_tail}/opencoarrays.mod")
159+
if(UNIX)
160+
add_custom_command(TARGET caf_mpi
161+
POST_BUILD
162+
COMMAND ${CMAKE_COMMAND} -E create_symlink "./${mod_dir_tail}/opencoarrays.mod" "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/opencoarrays.mod"
163+
COMMENT "Creating symlink ${CMAKE_INSTALL_INCLUDEDIR}/opencoarrays.mod --> ${CMAKE_INSTALL_INCLUDEDIR}/${mod_dir_tail}/opencoarrays.mod")
164+
endif()
155165

156166
install(DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
157167
FILES_MATCHING PATTERN "*.mod")

src/tests/unit/events/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
caf_compile_executable(allocatable_p2p_event_post allocatable_p2p_event_post.f90)
2+
set_target_properties(build_allocatable_p2p_event_post
3+
PROPERTIES MIN_IMAGES 4
4+
)
25
caf_compile_executable(static_event_post_issue_293 static_event_post_issue_293.f90)
6+
set_target_properties(build_static_event_post_issue_293
7+
PROPERTIES MIN_IMAGES 3
8+
)

src/tests/unit/fail_images/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ caf_compile_executable(image_fail_and_status_test_1 image_fail_and_status_test_1
1010
caf_compile_executable(image_fail_and_get_test_1 image_fail_and_get_test_1.f90)
1111
caf_compile_executable(image_fail_and_failed_images_test_1 image_fail_and_failed_images_test_1.f90)
1212
caf_compile_executable(image_fail_and_stopped_images_test_1 image_fail_and_stopped_images_test_1.f90)
13+
set_target_properties(build_image_fail_test_1
14+
build_image_fail_and_sync_test_1
15+
build_image_fail_and_sync_test_2
16+
build_image_fail_and_sync_test_3
17+
build_image_fail_and_status_test_1
18+
build_image_fail_and_get_test_1
19+
build_image_fail_and_failed_images_test_1
20+
build_image_fail_and_stopped_images_test_1
21+
PROPERTIES MIN_IMAGES 3)

src/tests/unit/init_register/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
caf_compile_executable(initialize_mpi initialize_mpi.F90)
22
caf_compile_executable(register register.f90)
3+
set_target_properties(build_register
4+
PROPERTIES MIN_IMAGES 2)
35
caf_compile_executable(register_vector register_vector.f90)
46
caf_compile_executable(register_alloc_vector register_alloc_vector.f90)
57
caf_compile_executable(allocate_as_barrier allocate_as_barrier.f90)
68
caf_compile_executable(allocate_as_barrier_proc allocate_as_barrier_proc.f90)
79

810
if (gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0))
911
caf_compile_executable(async_comp_alloc async_comp_alloc.f90)
12+
set_target_properties(build_async_comp_alloc
13+
PROPERTIES MIN_IMAGES 2)
1014
caf_compile_executable(async_comp_alloc_2 async_comp_alloc_2.f90)
1115
caf_compile_executable(register_alloc_comp_1 register_alloc_comp_1.f90)
1216
caf_compile_executable(register_alloc_comp_2 register_alloc_comp_2.f90)

src/tests/unit/send-get/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ caf_compile_executable(get_with_offset_1d get_with_offset_1d.f90)
99
caf_compile_executable(whole_get_array whole_get_array.f90)
1010
caf_compile_executable(strided_get strided_get.f90)
1111
caf_compile_executable(strided_sendget strided_sendget.f90)
12+
set_target_properties(build_strided_sendget
13+
PROPERTIES MIN_IMAGES 3)

0 commit comments

Comments
 (0)