@@ -1103,17 +1103,30 @@ eval(:(
11031103 @test all (Array (A2) .== Array (A2_ref))
11041104 end ;
11051105 @testset " @parallel <kernel> (2D, memopt, stencilranges=(0:0,-1:1,0:0))" begin
1106- A2 = @zeros (nxy... )
1107- B = @zeros (nxy... )
1108- A2_ref = @zeros (nxy... )
1109- copy! (B, [ix + (iy - 1 ) * size (B, 1 ) for ix= 1 : size (B, 1 ), iy= 1 : size (B, 2 )]. ^ 3 )
1110- @parallel ndims= 2 memopt= true optvars= B loopdim= 2 function d2_memopt_kernel! (A2, B)
1111- @inn (A2) = FiniteDifferences2D. @d2_yi (B)
1112- return
1106+ # Use a dedicated caller module so @within and @inn come from the 2-D finite-difference macro set.
1107+ d2_memopt_kernel_ctx = @eval module $ (gensym (:d2_memopt_kernel_ctx ))
1108+ using ParallelStencil
1109+ using ParallelStencil. FiniteDifferences2D
1110+
1111+ @init_parallel_stencil ($ package, $ FloatDefault, 2 , nonconst_metadata= true )
1112+
1113+ const nxy = (32 , 8 )
1114+ A2 = @zeros (nxy... )
1115+ B = @zeros (nxy... )
1116+ A2_ref = @zeros (nxy... )
1117+ copy! (B, [ix + (iy - 1 ) * size (B, 1 ) for ix= 1 : size (B, 1 ), iy= 1 : size (B, 2 )]. ^ 3 )
1118+
1119+ @parallel ndims= 2 memopt= true optvars= B loopdim= 2 function d2_memopt_kernel! (A2, B)
1120+ @inn (A2) = @d2_yi (B)
1121+ return
1122+ end
1123+
1124+ @parallel d2_memopt_kernel! (A2, B)
1125+ A2_ref[2 : end - 1 , 2 : end - 1 ] .= B[2 : end - 1 , 3 : end ] .- 2 * B[2 : end - 1 , 2 : end - 1 ] .+ B[2 : end - 1 , 1 : end - 2 ]
1126+
1127+ const ok = all (Array (A2) .== Array (A2_ref))
11131128 end
1114- @parallel d2_memopt_kernel! (A2, B)
1115- A2_ref[2 : end - 1 , 2 : end - 1 ] .= B[2 : end - 1 , 3 : end ] .- 2 * B[2 : end - 1 , 2 : end - 1 ] .+ B[2 : end - 1 , 1 : end - 2 ]
1116- @test all (Array (A2) .== Array (A2_ref))
1129+ @test getfield (d2_memopt_kernel_ctx, :ok )
11171130 end ;
11181131 @testset " @parallel_indices <kernel> (2D, memopt, optvars=A)" begin
11191132 A = @zeros (nxy... )
0 commit comments