Skip to content

Commit 7b6da6a

Browse files
committed
Merge branches 'issue-485-stdize-c-lib', 'neok-m4700/issue-488' and 'issue-493'
3 parents 78c8031 + 9872186 + 18dc333 commit 7b6da6a

File tree

6 files changed

+135
-18
lines changed

6 files changed

+135
-18
lines changed

CMakeLists.txt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -586,18 +586,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
586586
#---------------------------------------------------------------------------------------
587587
# Define macro for adding CAF tests, and ensuring proper flags are passed to MPI runtime
588588
#---------------------------------------------------------------------------------------
589-
590-
# Determine if we're using Open MPI
591-
cmake_host_system_information(RESULT N_CPU QUERY NUMBER_OF_LOGICAL_CORES)
592-
cmake_host_system_information(RESULT HOST_NAME QUERY HOSTNAME)
593-
execute_process(COMMAND ${MPIEXEC} --version
594-
OUTPUT_VARIABLE mpi_version_out)
595-
if (mpi_version_out MATCHES "[Oo]pen[ -][Mm][Pp][Ii]")
596-
message( STATUS "OpenMPI detected")
597-
set ( openmpi true )
598-
# Write out a host file because OMPI's mpiexec is dumb
599-
file(APPEND ${CMAKE_BINARY_DIR}/hostfile "${HOST_NAME} slots=${N_CPU}\n")
600-
endif ()
589+
# Test for OpenMPI moved to src/mpi/CMakeLists.txt and passed back up through set(... PARENT_SCOPE)
601590
function(add_caf_test name num_caf_img test_target)
602591
# Function to add MPI tests.
603592
if(TARGET ${test_target})
@@ -627,7 +616,11 @@ function(add_caf_test name num_caf_img test_target)
627616
endif()
628617
endif()
629618
set(test_parameters -np ${num_caf_img} ${test_parameters})
630-
add_test(NAME ${name} COMMAND "bash" "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/cafrun" ${test_parameters} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_target}")
619+
if(DEFINED ARGN)
620+
add_test(NAME ${name} COMMAND "bash" "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/cafrun" ${test_parameters} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_target}" ${ARGN})
621+
else()
622+
add_test(NAME ${name} COMMAND "bash" "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/cafrun" ${test_parameters} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_target}")
623+
endif()
631624
set_property(TEST ${name} PROPERTY PASS_REGULAR_EXPRESSION "Test passed.")
632625
endfunction(add_caf_test)
633626

@@ -774,6 +767,10 @@ if(opencoarrays_aware_compiler)
774767
add_caf_test(co_reduce-factorial-int8 4 co_reduce-factorial-int8)
775768
add_caf_test(co_reduce-factorial-int64 4 co_reduce-factorial-int64)
776769

770+
# issues reported by @neok-m4700
771+
add_caf_test(issue-488-multi-dim-cobounds-true 8 issue-488-multi-dim-cobounds true)
772+
add_caf_test(issue-488-multi-dim-cobounds-false 8 issue-488-multi-dim-cobounds false)
773+
777774
# IMAGE FAIL tests
778775
if(NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0)
779776
if(CAF_ENABLE_FAILED_IMAGES)

src/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ foreach(directory ${directories_to_build})
33
add_subdirectory(${directory})
44
endforeach()
55

6+
set(N_CPU ${N_CPU} PARENT_SCOPE)
7+
set(HOSTNAME ${HOSTNAME} PARENT_SCOPE)
8+
9+
if(openmpi)
10+
set(openmpi ${openmpi} PARENT_SCOPE)
11+
endif()
12+
613
install( FILES libcaf.h libcaf-gfortran-descriptor.h
714
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
815
)

src/mpi/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ if (NOT MPI_C_FOUND)
88
include_directories(BEFORE ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH})
99
endif()
1010

11+
#----------------------------------
12+
# Determine if we're using Open MPI
13+
#----------------------------------
14+
cmake_host_system_information(RESULT N_CPU QUERY NUMBER_OF_LOGICAL_CORES)
15+
set(N_CPU ${N_CPU} PARENT_SCOPE)
16+
cmake_host_system_information(RESULT HOST_NAME QUERY HOSTNAME)
17+
set(HOSTNAME ${HOSTNAME} PARENT_SCOPE)
18+
execute_process(COMMAND ${MPIEXEC} --version
19+
OUTPUT_VARIABLE mpi_version_out)
20+
if (mpi_version_out MATCHES "[Oo]pen[ -][Mm][Pp][Ii]")
21+
message( STATUS "OpenMPI detected")
22+
set ( openmpi true PARENT_SCOPE)
23+
# Write out a host file because OMPI's mpiexec is dumb
24+
file(APPEND ${CMAKE_BINARY_DIR}/hostfile "${HOST_NAME} slots=${N_CPU}\n")
25+
endif ()
26+
1127
if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU")
1228
set(gfortran_compiler true)
1329
elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Cray")
@@ -103,7 +119,7 @@ set(CMAKE_REQUIRED_INCLUDES ${old_cmake_required_includes})
103119
set(CMAKE_REQUIRED_FLAGS ${old_cmake_required_flags})
104120
set(CMAKE_REQUIRED_LIBRARIES ${old_cmake_required_libraries})
105121

106-
if(MPI_HAS_FAULT_TOL_EXT)
122+
if(MPI_HAS_FAULT_TOL_EXT) # AND (NOT openmpi))
107123
option(CAF_ENABLE_FAILED_IMAGES "Enable failed images support" TRUE)
108124
else()
109125
set(CAF_ENABLE_FAILED_IMAGES FALSE CACHE BOOL "Enable failed images support" FORCE)

src/mpi/mpi_caf.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4627,8 +4627,9 @@ PREFIX (get_by_ref) (caf_token_t token, int image_index,
46274627
}
46284628
}
46294629

4630-
/* Only increase the dim counter, when in an array ref. */
4631-
if (in_array_ref && dst_cur_dim < dst_rank)
4630+
/* Only increase the dim counter, when in an array ref, and
4631+
MODE != CAF_ARR_REF_SINGLE (delta == 1) see caf_array_ref_t. */
4632+
if (in_array_ref && dst_cur_dim < dst_rank && delta != 1)
46324633
++dst_cur_dim;
46334634
}
46344635
size *= (ptrdiff_t)delta;
@@ -4775,8 +4776,9 @@ PREFIX (get_by_ref) (caf_token_t token, int image_index,
47754776
dst->dim[dst_cur_dim]._stride = size;
47764777
}
47774778
}
4778-
/* Only increase the dim counter, when in an array ref. */
4779-
if (in_array_ref && dst_cur_dim < dst_rank)
4779+
/* Only increase the dim counter, when in an array ref, and
4780+
MODE != CAF_ARR_REF_SINGLE (delta == 1) see caf_array_ref_t. */
4781+
if (in_array_ref && dst_cur_dim < dst_rank && delta != 1)
47804782
++dst_cur_dim;
47814783
}
47824784
size *= (ptrdiff_t)delta;

src/tests/regression/reported/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ caf_compile_executable(source-alloc-sync issue-243-source-allocation-no-sync.f90
55
caf_compile_executable(convert-before-put issue-292-convert-type-before-put.f90)
66
caf_compile_executable(issue-422-send issue-422-send.F90)
77
caf_compile_executable(issue-422-send-get issue-422-send-get.F90)
8+
caf_compile_executable(issue-488-multi-dim-cobounds issue-488-multi-dim-cobounds.f90)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
program main
2+
!! OpenCoarrays issue #488 MWE
3+
!! ===========================
4+
!!
5+
!! https://github.com/sourceryinstitute/OpenCoarrays/issues/488
6+
!!
7+
!! Running with 8 images, scattering from rank 1 fails when using a coarray
8+
!! in a derived type, whereas we observe no issue with pure coarrays.
9+
!!
10+
!! Should be run with 8 images as follows:
11+
!! cafrun -np 8 ./a.out false
12+
!! cafrun -np 8 ./a.out true
13+
implicit none
14+
15+
type co_arr
16+
real, allocatable :: a(:, :)[:, :]
17+
end type
18+
19+
type(co_arr) :: co1 ! derived type with coarray
20+
real, allocatable :: co2(:, :)[:, :] ! pure coarray
21+
real, allocatable :: glob(:, :), buf2d(:, :)
22+
integer, parameter :: nx = 2, ny = 3 ! local chunk, same over all images
23+
integer :: me, nimg, mx, my, i, j, k
24+
character(len = *), parameter :: tab = char(9), nl = char(10)
25+
character(len = 10) :: arg
26+
logical :: switch, test_passed
27+
28+
test_passed = .false.
29+
call get_command_argument(1, arg)
30+
read (arg, '(L)') switch
31+
32+
me = this_image()
33+
nimg = num_images()
34+
mx = nimg / 2 ! 2d grid distribution
35+
my = nimg / mx
36+
37+
if (nimg /= 8) then
38+
stop 'example for 8 images'
39+
end if
40+
41+
allocate(co1 % a(nx, ny)[mx, *])
42+
allocate(co2(nx, ny)[mx, *])
43+
allocate(buf2d(nx, ny), glob(mx * nx, my * ny))
44+
45+
if (me == 1) print *, 'global size', [(mx * nx), (my * ny)], nl, 'local size', [nx, ny]
46+
47+
! call random_number(glob)
48+
glob = reshape([(i, i = 1, (mx * nx) * (my * ny))], shape(glob))
49+
50+
sync all ! separate segments
51+
if (me == 1) then
52+
! scatter glob from root (1st image)
53+
54+
! local to local
55+
co1 % a = glob(:nx, :ny)
56+
co2 = glob(:nx, :ny)
57+
58+
! loop over all other images
59+
do i = 1, mx
60+
do j = 1, my
61+
k = image_index(co2, [i, j])
62+
if (k /= 1) then
63+
buf2d = glob((i - 1) * nx + 1:i * nx, (j - 1) * ny + 1:j * ny) ! send buffer
64+
! print *, 'filling up image #', k, '[', [i, j], ']', nl, tab, '==>', buf2d, nl
65+
if (switch) then
66+
co1 % a(:nx, :ny)[i, j] = buf2d ! <= failure
67+
else
68+
co2(:nx, :ny)[i, j] = buf2d ! ok
69+
end if
70+
end if
71+
end do
72+
end do
73+
end if
74+
sync all
75+
76+
! output local arrays after scattering
77+
! print *, me, 'co1', co1 % a, nl, me, 'co2', co2
78+
79+
! collect results on rank 1
80+
call co_sum(co1 % a, result_image = 1)
81+
call co_sum(co2, result_image = 1)
82+
83+
sync all
84+
test_passed = abs(sum(glob) - sum(merge(co1 % a, co2, switch))) < epsilon(0.)
85+
if (me == 1) then
86+
print *, 'all close ?', test_passed
87+
if(test_passed) then
88+
write(*,*) 'Test passed.'
89+
else
90+
write(*,*) 'Test failed!'
91+
endif
92+
end if
93+
deallocate(co1 % a, co2, glob)
94+
end program

0 commit comments

Comments
 (0)