@@ -5,7 +5,9 @@ program slice
5
5
6
6
type (coarr) :: co
7
7
integer :: nimg, me, z, nx, ny, nz, north, south, mex, mey, mez, coords(3 )
8
- real , allocatable :: bufxz(:, :) ! a plane (2d) slice, normal in the y direction
8
+ integer :: shape2d(2 ), shape3d(3 )
9
+ real , allocatable :: buf3d(:, :, :) ! a plane slice as a rank 3 array with a single transverse layer
10
+ real , allocatable :: buf2d(:, :) ! a plane (2d) slice, normal in the y direction
9
11
10
12
nx = 6
11
13
ny = 4
@@ -17,7 +19,12 @@ program slice
17
19
if (nimg /= 8 ) stop
18
20
19
21
allocate (co % a(nx, ny, nz)[1 :2 , 1 :2 , * ])
20
- allocate (bufxz(nx, nz))
22
+ allocate (buf2d(nx, nz), buf3d(nx, 1 , nz))
23
+
24
+ ! this example should NOT reallocate buf2d nor buf3d
25
+ ! compare shapes before and after syncing
26
+ shape2d = shape (buf2d)
27
+ shape3d = shape (buf3d)
21
28
22
29
co % a = reshape ([(z, z= 1 , nx * ny * nz)], shape (co % a))
23
30
@@ -33,19 +40,34 @@ program slice
33
40
if (north <= 2 ) then
34
41
z = image_index(co % a, [mex, north, mez])
35
42
sync images(z)
36
- bufxz = co % a(1 :nx, 1 , 1 :nz)[mex, north, mez]
37
- co % a(1 :nx, ny, 1 :nz) = bufxz
43
+ ! no reduction on rank
44
+ buf3d = co % a(1 :nx, 1 :1 , 1 :nz)[mex, north, mez]
45
+ co % a(1 :nx, ny:ny, 1 :nz) = buf3d
46
+
47
+ ! reduction along dim 2
48
+ buf2d = co % a(1 :nx, 1 , 1 :nz)[mex, north, mez]
49
+ co % a(1 :nx, ny, 1 :nz) = buf2d
38
50
end if
39
51
if (south >= 1 ) then
40
52
z = image_index(co % a, [mex, south, mez])
41
53
sync images(z)
42
- bufxz = co % a(1 :nx, 1 , 1 :nz)[mex, south, mez]
43
- co % a(1 :nx, ny, 1 :nz) = bufxz
54
+ buf3d = co % a(1 :nx, ny:ny, 1 :nz)[mex, south, mez]
55
+ co % a(1 :nx, 1 :1 , 1 :nz) = buf3d
56
+
57
+ buf2d = co % a(1 :nx, ny, 1 :nz)[mex, south, mez]
58
+ co % a(1 :nx, 1 , 1 :nz) = buf2d
44
59
end if
45
60
sync all
46
61
47
- deallocate (co % a, bufxz)
48
- if (this_image() == 1 ) write (* ,* ) " Test passed."
62
+ deallocate (co % a, buf2d, buf3d)
63
+
64
+ if (any (shape2d /= shape (buf2d)) .or. any (shape3d /= shape (buf3d))) then
65
+ write (* , * ) ' Test failed!'
66
+ error stop 5
67
+ else
68
+ write (* , * ) ' Test passed.'
69
+ end if
70
+
49
71
! Regression would cause error message:
50
72
! Fortran runtime error on image <...>: libcaf_mpi::caf_get_by_ref(): rank out of range.
51
- end program
73
+ end program
0 commit comments