Skip to content

Commit 755518a

Browse files
author
neok-m4700
committed
fix ncontig
1 parent bc97a3b commit 755518a

File tree

6 files changed

+77
-31
lines changed

6 files changed

+77
-31
lines changed

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@ if(opencoarrays_aware_compiler)
763763
# Fixed GCC 7 regressions, should run on GCC 6 and 7
764764
add_caf_test(static_event_post_issue_293 3 static_event_post_issue_293)
765765

766-
add_caf_test(issue-493-coindex-slice 8 issue-493-coindex-slice) # Contributed by @neok-m4700 in #493
767766

768767
# These co_reduce (#172, fixed by PR #332, addl discussion in PR
769768
# #331) tests are for bugs not regressions. Should be fixed in all
@@ -773,9 +772,11 @@ if(opencoarrays_aware_compiler)
773772
add_caf_test(co_reduce-factorial-int64 4 co_reduce-factorial-int64)
774773

775774
# issues reported by @neok-m4700
776-
add_caf_test(issue-488-multi-dim-cobounds-true 8 issue-488-multi-dim-cobounds true)
777-
add_caf_test(issue-488-multi-dim-cobounds-false 8 issue-488-multi-dim-cobounds false)
778-
add_caf_test(issue-503-multidim-array-broadcast 2 issue-503-multidim-array-broadcast)
775+
add_caf_test(coindex-slice 8 coindex-slice)
776+
add_caf_test(multi-dim-cobounds-true 8 multi-dim-cobounds true)
777+
add_caf_test(multi-dim-cobounds-false 8 multi-dim-cobounds false)
778+
add_caf_test(multidim-array-broadcast 2 multidim-array-broadcast)
779+
add_caf_test(non-contig-red-ndarray 2 non-contig-red-ndarray)
779780

780781
# IMAGE FAIL tests
781782
if(NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0)

src/mpi/mpi_caf.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6787,7 +6787,7 @@ internal_co_reduce (MPI_Op op, gfc_descriptor_t *source, int result_image, int *
67876787
MPI_Datatype datatype = get_MPI_datatype (source, src_len);
67886788

67896789
size = 1;
6790-
for (j = 0; j < rank; j++)
6790+
for (j = 0; j < rank; ++j)
67916791
{
67926792
ptrdiff_t dimextent = source->dim[j]._ubound
67936793
- source->dim[j].lower_bound + 1;
@@ -6812,21 +6812,18 @@ internal_co_reduce (MPI_Op op, gfc_descriptor_t *source, int result_image, int *
68126812
goto co_reduce_cleanup;
68136813
}
68146814

6815-
for (i = 0; i < size; i++)
6815+
for (i = 0; i < size; ++i)
68166816
{
68176817
ptrdiff_t array_offset_sr = 0;
6818-
ptrdiff_t stride = 1;
6818+
ptrdiff_t tot_ext = 1;
68196819
ptrdiff_t extent = 1;
6820-
for (j = 0; j < GFC_DESCRIPTOR_RANK (source)-1; j++)
6820+
for (j = 0; j < rank-1; ++j)
68216821
{
6822-
array_offset_sr += ((i / (extent*stride))
6823-
% (source->dim[j]._ubound
6824-
- source->dim[j].lower_bound + 1))
6825-
* source->dim[j]._stride;
68266822
extent = (source->dim[j]._ubound - source->dim[j].lower_bound + 1);
6827-
stride = source->dim[j]._stride;
6823+
array_offset_sr += ((i / tot_ext) % extent) * source->dim[j]._stride;
6824+
tot_ext *= extent;
68286825
}
6829-
array_offset_sr += (i / extent) * source->dim[rank-1]._stride;
6826+
array_offset_sr += (i / tot_ext) * source->dim[rank-1]._stride;
68306827
void *sr = (void *)((char *) source->base_addr
68316828
+ array_offset_sr*GFC_DESCRIPTOR_SIZE (source));
68326829
if (result_image == 0)
@@ -6880,10 +6877,9 @@ PREFIX (co_broadcast) (gfc_descriptor_t *a, int source_image, int *stat, char *e
68806877
MPI_Datatype datatype = get_MPI_datatype (a, 0);
68816878

68826879
size = 1;
6883-
for (j = 0; j < rank; j++)
6880+
for (j = 0; j < rank; ++j)
68846881
{
6885-
ptrdiff_t dimextent = a->dim[j]._ubound
6886-
- a->dim[j].lower_bound + 1;
6882+
ptrdiff_t dimextent = a->dim[j]._ubound - a->dim[j].lower_bound + 1;
68876883
if (dimextent < 0)
68886884
dimextent = 0;
68896885
size *= dimextent;
@@ -6915,21 +6911,18 @@ PREFIX (co_broadcast) (gfc_descriptor_t *a, int source_image, int *stat, char *e
69156911
caf_runtime_error ("Co_broadcast of character arrays not yet supported\n");
69166912
}
69176913

6918-
for (i = 0; i < size; i++)
6914+
for (i = 0; i < size; ++i)
69196915
{
69206916
ptrdiff_t array_offset_sr = 0;
6921-
ptrdiff_t stride = 1;
6917+
ptrdiff_t tot_ext = 1;
69226918
ptrdiff_t extent = 1;
6923-
for (j = 0; j < GFC_DESCRIPTOR_RANK (a)-1; j++)
6919+
for (j = 0; j < rank-1; ++j)
69246920
{
6925-
array_offset_sr += ((i / (extent*stride))
6926-
% (a->dim[j]._ubound
6927-
- a->dim[j].lower_bound + 1))
6928-
* a->dim[j]._stride;
69296921
extent = (a->dim[j]._ubound - a->dim[j].lower_bound + 1);
6930-
stride = a->dim[j]._stride;
6922+
array_offset_sr += ((i / tot_ext) % extent) * a->dim[j]._stride;
6923+
tot_ext *= extent;
69316924
}
6932-
array_offset_sr += (i / (extent * stride)) * a->dim[rank-1]._stride;
6925+
array_offset_sr += (i / tot_ext) * a->dim[rank-1]._stride;
69336926
void *sr = (void *)((char *) a->base_addr
69346927
+ array_offset_sr*GFC_DESCRIPTOR_SIZE (a));
69356928

src/tests/regression/open/issue-422-send.f90

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tests/regression/open/issue-422-sendget.f90

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tests/regression/reported/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ caf_compile_executable(co_reduce-factorial-int8 issue-172-wrong-co_reduce-int8.f
33
caf_compile_executable(co_reduce-factorial-int64 issue-172-wrong-co_reduce-int64.f90)
44
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)
6-
caf_compile_executable(issue-493-coindex-slice issue-493-coindex-slice.f90)
76
caf_compile_executable(issue-422-send issue-422-send.F90)
87
caf_compile_executable(issue-422-send-get issue-422-send-get.F90)
9-
caf_compile_executable(issue-488-multi-dim-cobounds issue-488-multi-dim-cobounds.f90)
10-
caf_compile_executable(issue-503-multidim-array-broadcast issue-503-multidim-array-broadcast.f90)
8+
caf_compile_executable(multi-dim-cobounds issue-488-multi-dim-cobounds.f90)
9+
caf_compile_executable(coindex-slice issue-493-coindex-slice.f90)
10+
caf_compile_executable(multidim-array-broadcast issue-503-multidim-array-broadcast.f90)
11+
caf_compile_executable(non-contig-red-ndarray issue-503-non-contig-red-ndarray.f90)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
program main
2+
real, allocatable, dimension(:, :, :, :) :: arr, arr_copy
3+
integer :: i, me, nimg
4+
real :: redc, sumc, sumnc, rednc
5+
real :: eps = epsilon(0.)
6+
logical :: failc, failnc
7+
8+
allocate(arr(9, 20, 3, 18))
9+
10+
me = this_image()
11+
nimg = num_images()
12+
13+
if (me == 1) then
14+
arr = reshape([(i, i=1, size(arr))], shape(arr))
15+
end if
16+
17+
call co_broadcast(arr, source_image=1)
18+
arr_copy = arr
19+
20+
print *, '==> CONTIGUOUS <=='
21+
sumc = sum(arr)
22+
redc = sumc
23+
call co_sum(redc)
24+
print *, 'sumc=', sumc
25+
print *, 'excpected: nimg * sumc=', nimg * sumc
26+
print *, 'got: redc=', redc
27+
28+
failc = abs(redc - nimg * sumc) > eps
29+
30+
print *, '==> NON CONTIGUOUS <=='
31+
sumnc = sum(arr(::3, ::2, :, ::5))
32+
33+
call co_sum(arr_copy)
34+
call co_sum(arr(::3, ::2, :, ::5))
35+
36+
rednc = sum(arr(::3, ::2, :, ::5))
37+
print *, 'sumnc=', sumnc
38+
print *, 'expected (nimg * sumnc)=', nimg * sumnc
39+
print *, 'expected=', sum(arr_copy(::3, ::2, :, ::5))
40+
print *, 'got: rednc=', rednc
41+
42+
failnc = abs(rednc - nimg * sumnc) > eps
43+
44+
sync all
45+
46+
if (failc .or. failnc) then
47+
write(*, *) 'Test failed!'
48+
error stop 5
49+
else
50+
write(*, *) 'Test passed.'
51+
end if
52+
deallocate(arr)
53+
end program

0 commit comments

Comments
 (0)