Skip to content

Commit 6017b71

Browse files
committed
Sending data to this_image() lead doing a memmove even when
that was unsuitable, because size, rank, type, a.s.o. did not match. This patch directs all data sends to the convert routine, which does scalar to array and type/kind conversion correctly.
1 parent 5f09984 commit 6017b71

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/runtime-libraries/mpi/mpi_caf.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,25 +2026,30 @@ copy_char_to_self(void *src, int src_type, int src_size, int src_kind,
20262026

20272027
static void
20282028
copy_to_self(gfc_descriptor_t *src, int src_kind,
2029-
gfc_descriptor_t *dest, int dst_kind, size_t size, int *stat)
2029+
gfc_descriptor_t *dst, int dst_kind, size_t elem_size, int *stat)
20302030
{
2031+
const int src_size = GFC_DESCRIPTOR_SIZE(src),
2032+
dst_size = GFC_DESCRIPTOR_SIZE(dst);
2033+
const int src_type = GFC_DESCRIPTOR_TYPE(src),
2034+
dst_type = GFC_DESCRIPTOR_TYPE(dst);
2035+
const int src_rank = GFC_DESCRIPTOR_RANK(src),
2036+
dst_rank = GFC_DESCRIPTOR_RANK(dst);
20312037
#ifdef GFC_CAF_CHECK
2032-
if (GFC_DESCRIPTOR_TYPE(dest) == BT_CHARACTER
2033-
|| GFC_DESCRIPTOR_TYPE(src) == BT_CHARACTER)
2038+
if (dst_type == BT_CHARACTER || src_type == BT_CHARACTER)
20342039
caf_runtime_error("internal error: copy_to_self() for char types called.");
20352040
#endif
20362041
/* The address of dest passed by the compiler points on the right
2037-
* memory location. No offset summation is needed. */
2038-
if (dst_kind == src_kind)
2039-
memmove(dest->base_addr, src->base_addr, size * GFC_DESCRIPTOR_SIZE(dest));
2042+
* memory location. No offset summation is needed. Use the convert with
2043+
* strides when src is a scalar. */
2044+
if (dst_kind == src_kind && dst_size == src_size && dst_type == src_type
2045+
&& src_rank == dst_rank)
2046+
memmove(dst->base_addr, src->base_addr, elem_size * dst_size);
20402047
else
20412048
/* When the rank is 0 then a scalar is copied to a vector and the stride
20422049
* is zero. */
2043-
convert_with_strides(dest->base_addr, GFC_DESCRIPTOR_TYPE(dest), dst_kind,
2044-
GFC_DESCRIPTOR_SIZE(dest), src->base_addr,
2045-
GFC_DESCRIPTOR_TYPE(src), src_kind,
2046-
(GFC_DESCRIPTOR_RANK(src) > 0)
2047-
? GFC_DESCRIPTOR_SIZE(src) : 0, size, stat);
2050+
convert_with_strides(dst->base_addr, dst_type, dst_kind,
2051+
dst_size, src->base_addr, src_type, src_kind,
2052+
src_rank > 0 ? src_size : 0, elem_size, stat);
20482053
}
20492054

20502055
/* token: The token of the array to be written to.

src/tests/unit/send-get/send_convert_nums.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ program send_convert_nums
364364
& call print_and_register( 'send strided int kind=1 to kind=1 self failed.')
365365

366366
co_int_k4 = -1
367-
co_int_k4(::2)[1] = int_k4
367+
co_int_k4(::2)[1] = int_k4(1:3)
368368
print *, co_int_k4
369369
if (any(co_int_k4 /= [int_k4(1), -1, int_k4(2), -1, int_k4(3)])) &
370370
call print_and_register( 'send strided int kind=4 to kind=4 self failed.')

0 commit comments

Comments
 (0)