Skip to content

Commit 361224c

Browse files
committed
[Issue-422] Finalize alloc_comp_get_convert_nums and start on test for
alloc_comp_send_convert_nums.
1 parent 1a3d48e commit 361224c

File tree

5 files changed

+610
-73
lines changed

5 files changed

+610
-73
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,8 @@ if(opencoarrays_aware_compiler)
650650
add_caf_test(async_comp_alloc_2 2 async_comp_alloc_2)
651651
add_caf_test(comp_allocated_1 2 comp_allocated_1)
652652
add_caf_test(comp_allocated_2 2 comp_allocated_2)
653+
add_caf_test(alloc_comp_get_convert_nums 2 alloc_comp_get_convert_nums)
654+
add_caf_test(alloc_comp_send_convert_nums 2 alloc_comp_send_convert_nums)
653655
endif()
654656

655657

@@ -684,7 +686,6 @@ if(opencoarrays_aware_compiler)
684686
add_caf_test(get_with_offset_1d 2 get_with_offset_1d)
685687
add_caf_test(whole_get_array 2 whole_get_array)
686688
add_caf_test(strided_get 2 strided_get)
687-
add_caf_test(alloc_comp_get_convert_nums 2 alloc_comp_get_convert_nums)
688689

689690
# Pure send tests
690691
add_caf_test(send_array 2 send_array)

src/mpi/mpi_caf.c

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
5858
/* Define GFC_CAF_CHECK to enable run-time checking. */
5959
/* #define GFC_CAF_CHECK 1 */
6060

61+
#define GCC_GE_7
6162

6263
#ifndef EXTRA_DEBUG_OUTPUT
6364
#define dprint(...)
@@ -1069,15 +1070,19 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
10691070
{
10701071
/* Create or allocate a slave token. */
10711072
mpi_caf_slave_token_t *slave_token;
1073+
#ifdef EXTRA_DEBUG_OUTPUT
10721074
MPI_Aint mpi_address;
1075+
#endif
10731076
CAF_Win_unlock_all (global_dynamic_win);
10741077
if (type == CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY)
10751078
{
10761079
*token = calloc (1, sizeof(mpi_caf_slave_token_t));
10771080
slave_token = (mpi_caf_slave_token_t *)(*token);
10781081
MPI_Win_attach (global_dynamic_win, *token,
10791082
sizeof (mpi_caf_slave_token_t));
1083+
#ifdef EXTRA_DEBUG_OUTPUT
10801084
MPI_Get_address(*token, &mpi_address);
1085+
#endif
10811086
dprint ("%d/%d: Attach slave token %p (mpi-address: %p) to global_dynamic_window = %p\n",
10821087
caf_this_image, caf_num_images, slave_token, mpi_address,
10831088
global_dynamic_win);
@@ -1096,14 +1101,18 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
10961101
mem = malloc (actual_size);
10971102
slave_token->memptr = mem;
10981103
ierr = MPI_Win_attach (global_dynamic_win, mem, actual_size);
1104+
#ifdef EXTRA_DEBUG_OUTPUT
10991105
MPI_Get_address(mem, &mpi_address);
1100-
dprint ("%d/%d: Attach mem %p (mpi-address: %p) to global_dynamic_window = %p on slave_token %p, ierr: %d\n",
1106+
#endif
1107+
dprint ("%d/%d: Attach mem %p (mpi-address: %p) to global_dynamic_window = %p on slave_token %p, size %d, ierr: %d\n",
11011108
caf_this_image, caf_num_images, mem, mpi_address,
1102-
global_dynamic_win, slave_token, ierr);
1109+
global_dynamic_win, slave_token, actual_size, ierr);
11031110
if (desc != NULL && GFC_DESCRIPTOR_RANK (desc) != 0)
11041111
{
11051112
slave_token->desc = desc;
1113+
#ifdef EXTRA_DEBUG_OUTPUT
11061114
MPI_Get_address (desc, &mpi_address);
1115+
#endif
11071116
dprint ("%d/%d: Attached descriptor %p (mpi-address: %p) to global_dynamic_window %p at address %p, ierr = %d.\n",
11081117
caf_this_image, caf_num_images, desc, mpi_address,
11091118
global_dynamic_win, &slave_token->desc, ierr);
@@ -3773,19 +3782,20 @@ get_data (void *ds, mpi_caf_token_t *token, MPI_Aint offset, int dst_type,
37733782
{
37743783
size_t k;
37753784
MPI_Win win = token == NULL ? global_dynamic_win : token->memptr_win;
3785+
#ifdef EXTRA_DEBUG_OUTPUT
3786+
if (token)
3787+
dprint ("%d/%d: %s() %p = win(%d): %p -> offset: %d of size %d -> %d, dst type %d(%d), src type %d(%d)\n",
3788+
caf_this_image, caf_num_images, __FUNCTION__, ds, win, (image_index + 1),
3789+
offset, src_size, dst_size, dst_type, dst_kind, src_type, src_kind);
3790+
else
3791+
dprint ("%d/%d: %s() %p = global_win(%d) offset: %d (%p) of size %d -> %d, dst type %d(%d), src type %d(%d)\n",
3792+
caf_this_image, caf_num_images, __FUNCTION__, ds, (image_index + 1),
3793+
offset, offset, src_size, dst_size, dst_type, dst_kind, src_type,
3794+
src_kind);
3795+
#endif
37763796
if (dst_type == src_type && dst_kind == src_kind)
37773797
{
37783798
size_t sz = (dst_size > src_size ? src_size : dst_size) * num;
3779-
#ifdef EXTRA_DEBUG_OUTPUT
3780-
if (token)
3781-
dprint ("%d/%d: %s() %p = win: %p -> offset: %d of size %d bytes\n",
3782-
caf_this_image, caf_num_images, __FUNCTION__, ds, win,
3783-
offset, sz);
3784-
else
3785-
dprint ("%d/%d: %s() %p = global_win offset: %d of size %d bytes\n",
3786-
caf_this_image, caf_num_images, __FUNCTION__, ds,
3787-
offset, sz);
3788-
#endif
37893799
MPI_Get (ds, sz, MPI_BYTE, image_index, offset, sz, MPI_BYTE,
37903800
win);
37913801
if ((dst_type == BT_CHARACTER || src_type == BT_CHARACTER)
@@ -3804,6 +3814,8 @@ get_data (void *ds, mpi_caf_token_t *token, MPI_Aint offset, int dst_type,
38043814
void *srh = alloca (src_size);
38053815
MPI_Get (srh, src_size, MPI_BYTE, image_index, offset,
38063816
src_size, MPI_BYTE, win);
3817+
/* Get of the data needs to be finished before converting the data. */
3818+
MPI_Win_flush (image_index, win);
38073819
assign_char1_from_char4 (dst_size, src_size, ds, srh);
38083820
}
38093821
else if (dst_type == BT_CHARACTER)
@@ -3812,14 +3824,23 @@ get_data (void *ds, mpi_caf_token_t *token, MPI_Aint offset, int dst_type,
38123824
void *srh = alloca (src_size);
38133825
MPI_Get (srh, src_size, MPI_BYTE, image_index, offset,
38143826
src_size, MPI_BYTE, win);
3827+
/* Get of the data needs to be finished before converting the data. */
3828+
MPI_Win_flush (image_index, win);
38153829
assign_char4_from_char1 (dst_size, src_size, ds, srh);
38163830
}
38173831
else
38183832
{
38193833
/* Get the required amount of memory on the stack. */
38203834
void *srh = alloca (src_size * num);
3821-
MPI_Get (srh, src_size * num, MPI_BYTE, image_index, offset,
3822-
src_size * num, MPI_BYTE, win);
3835+
dprint ("%d/%d: %s() type/kind convert %d items: type %d(%d) -> type %d(%d), local buffer: %p\n",
3836+
caf_this_image, caf_num_images, __FUNCTION__, num,
3837+
src_type, src_kind, dst_type, dst_kind, srh);
3838+
int ierr = MPI_Get (srh, src_size * num, MPI_BYTE, image_index, offset,
3839+
src_size * num, MPI_BYTE, win);
3840+
/* Get of the data needs to be finished before converting the data. */
3841+
MPI_Win_flush (image_index, win);
3842+
dprint ("%d/%d: %s() srh[0] = %d, ierr = %d\n", caf_this_image, caf_num_images,
3843+
__FUNCTION__, (int)((char *)srh)[0], ierr);
38233844
for (k = 0; k < num; ++k)
38243845
{
38253846
convert_type (ds, dst_type, dst_kind, srh, src_type, src_kind, stat);
@@ -3896,6 +3917,8 @@ get_for_ref (caf_reference_t *ref, size_t *i, size_t dst_index,
38963917
switch (ref->type)
38973918
{
38983919
case CAF_REF_COMPONENT:
3920+
dprint ("%d/%d: %s() caf_offset = %d\n", caf_this_image, caf_num_images,
3921+
__FUNCTION__, ref->u.c.caf_token_offset);
38993922
if (ref->u.c.caf_token_offset > 0)
39003923
{
39013924
sr_byte_offset += ref->u.c.offset;
@@ -3909,8 +3932,8 @@ get_for_ref (caf_reference_t *ref, size_t *i, size_t dst_index,
39093932
else
39103933
{
39113934
MPI_Get (&sr, stdptr_size, MPI_BYTE, image_index,
3912-
MPI_Aint_add ((MPI_Aint)sr, sr_byte_offset),
3913-
stdptr_size, MPI_BYTE, global_dynamic_win);
3935+
sr_byte_offset, stdptr_size, MPI_BYTE,
3936+
mpi_token->memptr_win);
39143937
sr_global = true;
39153938
}
39163939
sr_byte_offset = 0;
@@ -3919,14 +3942,14 @@ get_for_ref (caf_reference_t *ref, size_t *i, size_t dst_index,
39193942
sr_byte_offset += ref->u.c.offset;
39203943
if (sr_global)
39213944
get_data (ds, NULL, MPI_Aint_add ((MPI_Aint)sr, sr_byte_offset),
3922-
GFC_DESCRIPTOR_TYPE (dst), GFC_DESCRIPTOR_TYPE (dst),
3923-
dst_kind, src_kind, dst_size, ref->item_size, 1, stat,
3924-
image_index);
3945+
GFC_DESCRIPTOR_TYPE (dst), GFC_DESCRIPTOR_TYPE (dst),
3946+
dst_kind, src_kind, dst_size, ref->item_size, 1, stat,
3947+
image_index);
39253948
else
39263949
get_data (ds, mpi_token, sr_byte_offset,
3927-
GFC_DESCRIPTOR_TYPE (dst), GFC_DESCRIPTOR_TYPE (src),
3928-
dst_kind, src_kind, dst_size, ref->item_size, 1, stat,
3929-
image_index);
3950+
GFC_DESCRIPTOR_TYPE (dst), GFC_DESCRIPTOR_TYPE (src),
3951+
dst_kind, src_kind, dst_size, ref->item_size, 1, stat,
3952+
image_index);
39303953
++(*i);
39313954
return;
39323955
case CAF_REF_STATIC_ARRAY:
@@ -3937,18 +3960,18 @@ get_for_ref (caf_reference_t *ref, size_t *i, size_t dst_index,
39373960
{
39383961
if (sr_global)
39393962
get_data (ds + dst_index * dst_size, NULL,
3940-
MPI_Aint_add ((MPI_Aint)sr, sr_byte_offset),
3941-
GFC_DESCRIPTOR_TYPE (dst),
3942-
src_type == -1 ? GFC_DESCRIPTOR_TYPE (src) : src_type,
3943-
dst_kind, src_kind, dst_size, ref->item_size, num,
3944-
stat, image_index);
3963+
MPI_Aint_add ((MPI_Aint)sr, sr_byte_offset),
3964+
GFC_DESCRIPTOR_TYPE (dst),
3965+
src_type == -1 ? GFC_DESCRIPTOR_TYPE (src) : src_type,
3966+
dst_kind, src_kind, dst_size, ref->item_size, num,
3967+
stat, image_index);
39453968
else
39463969
{
39473970
get_data (ds + dst_index * dst_size, mpi_token,
3948-
sr_byte_offset, GFC_DESCRIPTOR_TYPE (dst),
3949-
src_type == -1 ? GFC_DESCRIPTOR_TYPE (src) : src_type,
3950-
dst_kind, src_kind, dst_size, ref->item_size, num,
3951-
stat, image_index);
3971+
sr_byte_offset, GFC_DESCRIPTOR_TYPE (dst),
3972+
src_type == -1 ? GFC_DESCRIPTOR_TYPE (src) : src_type,
3973+
dst_kind, src_kind, dst_size, ref->item_size, num,
3974+
stat, image_index);
39523975
}
39533976
*i += num;
39543977
return;
@@ -4334,8 +4357,8 @@ PREFIX (get_by_ref) (caf_token_t token, int image_index,
43344357
CAF_Win_lock (MPI_LOCK_SHARED, remote_image, mpi_token->memptr_win);
43354358
while (riter)
43364359
{
4337-
dprint ("%d/%d: %s() offset = %d, remote_mem = %p\n", caf_this_image,
4338-
caf_num_images, __FUNCTION__, data_offset, remote_memptr);
4360+
dprint ("%d/%d: %s() offset = %d, remote_mem = %p, access_data(global_win) = %d\n", caf_this_image,
4361+
caf_num_images, __FUNCTION__, data_offset, remote_memptr, access_data_through_global_win);
43394362
switch (riter->type)
43404363
{
43414364
case CAF_REF_COMPONENT:
@@ -4357,6 +4380,8 @@ PREFIX (get_by_ref) (caf_token_t token, int image_index,
43574380
data_offset += riter->u.c.offset;
43584381
MPI_Get (&remote_memptr, stdptr_size, MPI_BYTE, remote_image,
43594382
data_offset, stdptr_size, MPI_BYTE, mpi_token->memptr_win);
4383+
dprint ("%d/%d: %s() get(custom_token %p), offset = %d, res. remote_mem = %p\n", caf_this_image,
4384+
caf_num_images, __FUNCTION__, mpi_token->memptr_win, data_offset, remote_memptr);
43604385
/* All future access is through the global dynamic window. */
43614386
access_data_through_global_win = true;
43624387
}
@@ -4845,15 +4870,15 @@ put_data (mpi_caf_token_t *token, MPI_Aint offset, void *sr, int dst_type,
48454870
{
48464871
/* Get the required amount of memory on the stack. */
48474872
void *dsh = alloca (dst_size);
4848-
assign_char1_from_char4 (dst_size, src_size, sr, dsh);
4873+
assign_char1_from_char4 (dst_size, src_size, dsh, sr);
48494874
MPI_Put (dsh, dst_size, MPI_BYTE, image_index, offset,
48504875
dst_size, MPI_BYTE, win);
48514876
}
48524877
else if (dst_type == BT_CHARACTER)
48534878
{
48544879
/* Get the required amount of memory on the stack. */
48554880
void *dsh = alloca (dst_size);
4856-
assign_char4_from_char1 (dst_size, src_size, sr, dsh);
4881+
assign_char4_from_char1 (dst_size, src_size, dsh, sr);
48574882
MPI_Put (dsh, dst_size, MPI_BYTE, image_index, offset,
48584883
dst_size, MPI_BYTE, win);
48594884
}
@@ -4864,11 +4889,12 @@ put_data (mpi_caf_token_t *token, MPI_Aint offset, void *sr, int dst_type,
48644889
for (k = 0; k < num; ++k)
48654890
{
48664891
convert_type (dsh, dst_type, dst_kind, sr, src_type, src_kind, stat);
4867-
sr += dst_size;
4868-
dsh += src_size;
4892+
dsh += dst_size;
4893+
sr += src_size;
48694894
}
48704895
MPI_Put (dsh, dst_size * num, MPI_BYTE, image_index, offset,
48714896
dst_size * num, MPI_BYTE, win);
4897+
MPI_Win_flush (image_index, win);
48724898
}
48734899
}
48744900

@@ -4926,7 +4952,7 @@ send_by_ref (caf_reference_t *ref, size_t *i, size_t src_index,
49264952
dst_byte_offset += ref->u.c.offset;
49274953
if (sr_global)
49284954
put_data (NULL, MPI_Aint_add ((MPI_Aint)ds, dst_byte_offset), sr,
4929-
GFC_DESCRIPTOR_TYPE (dst), GFC_DESCRIPTOR_TYPE (dst),
4955+
GFC_DESCRIPTOR_TYPE (src), GFC_DESCRIPTOR_TYPE (src),
49304956
dst_kind, src_kind, src_size, ref->item_size, 1, stat,
49314957
image_index);
49324958
else

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ caf_compile_executable(get_with_offset_1d get_with_offset_1d.f90)
1111
caf_compile_executable(whole_get_array whole_get_array.f90)
1212
caf_compile_executable(strided_get strided_get.f90)
1313
caf_compile_executable(get_with_vector_index get_with_vector_index.f90)
14-
caf_compile_executable(alloc_comp_get_convert_nums alloc_comp_get_convert_nums.f90)
1514

1615
## Pure send() tests
1716
caf_compile_executable(send_array send_array_test.f90)
@@ -28,6 +27,8 @@ set_target_properties(build_strided_sendget
2827
if (gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.3.0))
2928
caf_compile_executable(sendget_convert_nums sendget_convert_nums.f90)
3029
caf_compile_executable(send_convert_nums send_convert_nums.f90)
30+
caf_compile_executable(alloc_comp_get_convert_nums alloc_comp_get_convert_nums.f90)
31+
caf_compile_executable(alloc_comp_send_convert_nums alloc_comp_send_convert_nums.f90)
3132
elseif((CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
3233
message( AUTHOR_WARNING
3334
"Skipping building the following tests due to GFortran < 7.3.0 lack of compatibility:

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

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -301,44 +301,32 @@ program get_convert_nums
301301

302302
! Transfer to other image now.
303303
sync all
304-
obj%int_k4 = -1
305-
obj%int_k1 = INT(-1, 1)
306-
obj%real_k8 = -1.0
307-
obj%real_k4 = REAL(-1.0, 4)
308-
sync all
309-
310-
311-
312-
! this is testing send and not get!!!!!!
313-
314-
315-
316-
if (me == 1) then
317-
obj[2]%int_k4(::2) = [ 15, 13, 11]
318-
319-
obj[2]%int_k1(::2) = [INT(-15, 1), INT(-13, 1), INT(-11, 1)]
320-
321-
obj[2]%real_k8(::2) = [REAL(1.3, 8), REAL(1.5, 8), REAL(1.7, 8)]
322-
323-
obj[2]%real_k4(::2) = [REAL(1.3, 4), REAL(1.5, 4), REAL(1.7, 4)]
324-
end if
304+
int_k4 = -1
305+
int_k1 = INT(-1, 1)
306+
real_k8 = -1.0
307+
real_k4 = REAL(-1.0, 4)
325308

326309
sync all
327-
if (me == 2) then
328-
print *, obj%int_k4
329-
if (any(obj%int_k4 /= [15, -1, 13, -1, 11])) error stop 'strided send int kind=4 to kind=4 to image 2 failed.'
310+
if (me == 1) then
311+
int_k4(1:3) = obj[2]%int_k4(::2)
312+
print *, int_k4
313+
if (any(int_k4 /= [obj%int_k4(1), obj%int_k4(3), obj%int_k4(5), -1, -1])) &
314+
& error stop 'strided get int kind=4 to kind=4 to image 2 failed.'
330315

331-
print *, obj%int_k1
332-
if (any(obj%int_k1 /= [INT(-15, 1), INT(-1, 1), INT(-13, 1), INT(-1, 1), INT(-11, 1)])) &
333-
& error stop 'strided send int kind=1 to kind=1 to image 2 failed.'
316+
int_k1(3:5) = obj[2]%int_k1(::2)
317+
print *, int_k1
318+
if (any(int_k1 /= [INT(-1, 1), INT(-1, 1), obj%int_k1(1), obj%int_k1(3), obj%int_k1(5)])) &
319+
& error stop 'strided get int kind=1 to kind=1 to image 2 failed.'
334320

335-
print *, obj%real_k8
336-
if (any(abs(obj%real_k8 - [1.3, -1.0, 1.5, -1.0, 1.7]) > tolerance8)) &
337-
& error stop 'strided send real kind=8 to kind=8 to image 2 failed.'
321+
real_k8(1:3) = obj[2]%real_k8(::2)
322+
print *, real_k8
323+
if (any(abs(real_k8 - [obj%real_k8(1), obj%real_k8(3), obj%real_k8(5), REAL(-1.0, 8), REAL(-1.0, 8)]) > tolerance8)) &
324+
& error stop 'strided get real kind=8 to kind=8 to image 2 failed.'
338325

339-
print *, obj%real_k4
340-
if (any(abs(obj%real_k4 - [REAL(1.3, 4), REAL(-1.0, 4), REAL(1.5, 4), REAL(-1.0, 4), REAL(1.7, 4)]) > tolerance4)) &
341-
& error stop 'strided send real kind=4 to kind=4 to image 2 failed.'
326+
real_k4(3:5) = obj[2]%real_k4(::2)
327+
print *, real_k4
328+
if (any(abs(real_k4 - [-1.0, -1.0, obj%real_k4(1), obj%real_k4(3), obj%real_k4(5)]) > tolerance4)) &
329+
& error stop 'strided get real kind=4 to kind=4 to image 2 failed.'
342330
end if
343331

344332
! now with strides and kind conversion

0 commit comments

Comments
 (0)