Skip to content

Commit 6526377

Browse files
committed
WIP: nagfor/gfortran internal compiler error (ICE)
The following commands reproduce an internal compiler error (ICE) with each of the named compilers and compiler versions: `gfortran` (Homebrew-installed) --------------------------------- * Version 13.2.: `fpm test` * Version 12.3.0: `fpm test --compiler gfortran-12` `nagfor` 7.1 (Build 7143) ------------------------- * `fpm test --compiler nagfor --flag "-fpp -f2018"`
1 parent 86593b2 commit 6526377

File tree

6 files changed

+90
-98
lines changed

6 files changed

+90
-98
lines changed

src/matcha/do_concurrent_s.f90

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pure module subroutine do_concurrent_my_velocities(nsteps, dir, sampled_speeds,
3030

3131
call assert(all([size(my_velocities,1),size(sampled_speeds,2)] == shape(sampled_speeds)), &
3232
"do_concurrent_my_velocities: argument size match")
33-
call assert(all(shape(my_velocities,1)==shape(dir)), "do_concurrent_my_velocities: argument shape match")
33+
call assert(all(size(my_velocities,1)==shape(dir)), "do_concurrent_my_velocities: argument shape match")
3434

3535
do concurrent(step=1:nsteps)
3636
my_velocities(:,step,1) = sampled_speeds(:,step)*dir(:,step,1)
@@ -82,16 +82,14 @@ module subroutine do_concurrent_speeds(history, speeds) bind(C)
8282
x(i,:,:) = positions
8383
end do
8484

85-
associate(t => history%time)
86-
do concurrent(i = 1:npositions-1, j = 1:ncells)
87-
associate( &
88-
u => (x(i+1,j,:) - x(i,j,:))/(t(i+1) - t(i)), &
89-
ij => i + (j-1)*(npositions-1) &
90-
)
91-
speeds(ij) = sqrt(sum([(u(k)**2, k=1,nspacedims)]))
92-
end associate
93-
end do
94-
end associate
85+
do concurrent(i = 1:npositions-1, j = 1:ncells)
86+
associate( &
87+
u => (x(i+1,j,:) - x(i,j,:))/(history(i+1)%time - history(i)%time), &
88+
ij => i + (j-1)*(npositions-1) &
89+
)
90+
speeds(ij) = sqrt(sum([(u(k)**2, k=1,nspacedims)]))
91+
end associate
92+
end do
9593
end associate
9694

9795
end subroutine

src/matcha/output_s.f90

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,26 @@
2424

2525
integer, parameter :: speed=1, freq=2 ! subscripts for speeds and frequencies
2626

27-
associate(npositions => size(history), ncells => history(1)%positions_shape(1))
28-
allocate(speeds(ncells*(npositions-1)))
27+
associate(npositions => size(self%history_))
28+
allocate(speeds(self%my_num_cells()*(npositions-1)))
2929
end associate
3030
call do_concurrent_speeds(t_cell_collection_bind_C_t(self%history_), speeds)
3131

32-
associate(emp_distribution => self%input_%sample_distribution())
32+
block
33+
real(c_double), allocatable :: emp_distribution(:,:)
34+
35+
emp_distribution = self%input_%sample_distribution()
3336
associate(nintervals => size(emp_distribution(:,1)), dvel_half => (emp_distribution(2,speed)-emp_distribution(1,speed))/2.d0)
3437
vel = [emp_distribution(1,speed) - dvel_half, [(emp_distribution(i,speed) + dvel_half, i=1,nintervals)]]
3538
if (allocated(k)) deallocate(k)
36-
allocate(k(nspeeds))
39+
allocate(k(size(speeds)))
3740
call do_concurrent_k(speeds, vel, k)
3841
if(allocated(output_distribution)) deallocate(output_distribution)
3942
allocate(output_distribution(nintervals,2))
40-
call do_concurrent_output_distribution(nintervals, speed, freq, emp_distribution, k, output_distribution)
43+
call do_concurrent_output_distribution(speed, freq, emp_distribution, k, output_distribution)
4144
output_distribution(:,freq) = output_distribution(:,freq)/sum(output_distribution(:,freq))
4245
end associate
43-
end associate
46+
end block
4447

4548
end procedure
4649

src/matcha/subdomain_m.f90

Lines changed: 12 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,36 @@
11
module subdomain_m
2-
use assert_m, only : assert
32
implicit none
43

54
private
65
public :: subdomain_t
7-
public :: operator(.laplacian.)
8-
public :: step
96

107
type subdomain_t
118
private
129
real, allocatable :: s_(:,:,:)
1310
contains
1411
procedure, pass(self) :: define
15-
procedure, pass(rhs) :: multiply
16-
generic :: operator(*) => multiply
17-
generic :: operator(+) => add
18-
generic :: assignment(=) => assign_
1912
procedure dx
2013
procedure dy
2114
procedure dz
2215
procedure values
16+
generic :: operator(*) => multiply
17+
generic :: operator(+) => add
18+
generic :: operator(.laplacian.) => laplacian
19+
generic :: assignment(=) => assign_
20+
procedure, private, pass(rhs) :: multiply
21+
procedure, private :: laplacian
2322
procedure, private :: add
2423
procedure, private :: assign_
2524
end type
2625

27-
interface operator(.laplacian.)
28-
29-
module procedure laplacian
30-
!pure module function laplacian(rhs) result(laplacian_rhs)
31-
! implicit none
32-
! type(subdomain_t), intent(in) :: rhs[*]
33-
! type(subdomain_t) laplacian_rhs
34-
!end function
35-
36-
end interface
37-
3826
interface
3927

28+
pure module function laplacian(rhs) result(laplacian_rhs)
29+
implicit none
30+
class(subdomain_t), intent(in) :: rhs[*]
31+
type(subdomain_t) laplacian_rhs
32+
end function
33+
4034
module subroutine define(side, boundary_val, internal_val, n, self)
4135
implicit none
4236
real, intent(in) :: side, boundary_val, internal_val
@@ -96,62 +90,4 @@ module subroutine assign_(lhs, rhs)
9690

9791
end interface
9892

99-
real dx_, dy_, dz_
100-
integer my_nx, nx, ny, nz, me, num_subdomains, my_internal_west, my_internal_east
101-
102-
contains
103-
104-
pure module function laplacian(rhs) result(laplacian_rhs)
105-
type(subdomain_t), intent(in) :: rhs[*]
106-
type(subdomain_t) laplacian_rhs
107-
108-
integer i, j, k
109-
real, allocatable :: halo_west(:,:), halo_east(:,:)
110-
111-
call assert(allocated(rhs%s_), "subdomain_t%laplacian: allocated(rhs%s_)")
112-
113-
allocate(laplacian_rhs%s_, mold=rhs%s_)
114-
115-
if (me==1) then
116-
halo_west = rhs%s_(1,:,:)
117-
else
118-
halo_west = rhs[me-1]%s_(ubound(rhs[me-1]%s_,1),:,:)
119-
end if
120-
i = my_internal_west
121-
call assert(i+1<=my_nx,"laplacian: westernmost subdomain too small")
122-
do concurrent(j=2:ny-1, k=2:nz-1)
123-
laplacian_rhs%s_(i,j,k) = ( halo_west(j,k ) - 2*rhs%s_(i,j,k) + rhs%s_(i+1,j ,k ))/dx_**2 + &
124-
(rhs%s_(i,j-1,k ) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j+1,k ))/dy_**2 + &
125-
(rhs%s_(i,j ,k-1) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j ,k+1))/dz_**2
126-
end do
127-
128-
do concurrent(i=my_internal_west+1:my_internal_east-1, j=2:ny-1, k=2:nz-1)
129-
laplacian_rhs%s_(i,j,k) = (rhs%s_(i-1,j ,k ) - 2*rhs%s_(i,j,k) + rhs%s_(i+1,j ,k ))/dx_**2 + &
130-
(rhs%s_(i ,j-1,k ) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j+1,k ))/dy_**2 + &
131-
(rhs%s_(i ,j ,k-1) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j ,k+1))/dz_**2
132-
end do
133-
134-
if (me==1) then
135-
halo_east = rhs%s_(1,:,:)
136-
else
137-
halo_east = rhs[me+1]%s_(lbound(rhs[me+1]%s_,1),:,:)
138-
end if
139-
i = my_internal_east
140-
call assert(i-1>0,"laplacian: easternmost subdomain too small")
141-
do concurrent(j=2:ny-1, k=2:nz-1)
142-
laplacian_rhs%s_(i,j,k) = (rhs%s_(i-1,j ,k ) - 2*rhs%s_(i,j,k) + halo_east(j ,k ))/dx_**2 + &
143-
(rhs%s_(i ,j-1,k ) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j+1,k ))/dy_**2 + &
144-
(rhs%s_(i ,j ,k-1) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j ,k+1))/dz_**2
145-
end do
146-
147-
laplacian_rhs%s_(:, 1,:) = 0.
148-
laplacian_rhs%s_(:,ny,:) = 0.
149-
laplacian_rhs%s_(:,:, 1) = 0.
150-
laplacian_rhs%s_(:,:,nz) = 0.
151-
if (me==1) laplacian_rhs%s_(1,:,:) = 0.
152-
if (me==num_subdomains) laplacian_rhs%s_(my_nx,:,:) = 0.
153-
154-
end function
155-
156-
15793
end module

src/matcha/subdomain_s.f90

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
submodule(subdomain_m) subdomain_s
2+
use assert_m, only : assert, intrinsic_array_t
23
use sourcery_m, only : data_partition_t
3-
use intrinsic_array_m, only : intrinsic_array_t
44
implicit none
55

66
type(data_partition_t) data_partition
7-
7+
real dx_, dy_, dz_
8+
integer my_nx, nx, ny, nz, me, num_subdomains, my_internal_west, my_internal_east
89
real, allocatable :: increment(:,:,:)
910

1011
contains
@@ -144,4 +145,56 @@ subroutine apply_boundary_condition(ds)
144145

145146
end procedure
146147

147-
end submodule subdomain_s
148+
pure module function laplacian(rhs) result(laplacian_rhs)
149+
class(subdomain_t), intent(in) :: rhs[*]
150+
type(subdomain_t) laplacian_rhs
151+
152+
integer i, j, k
153+
real, allocatable :: halo_west(:,:), halo_east(:,:)
154+
155+
call assert(allocated(rhs%s_), "subdomain_t%laplacian: allocated(rhs%s_)")
156+
157+
allocate(laplacian_rhs%s_, mold=rhs%s_)
158+
159+
if (me==1) then
160+
halo_west = rhs%s_(1,:,:)
161+
else
162+
halo_west = rhs[me-1]%s_(ubound(rhs[me-1]%s_,1),:,:)
163+
end if
164+
i = my_internal_west
165+
call assert(i+1<=my_nx,"laplacian: westernmost subdomain too small")
166+
do concurrent(j=2:ny-1, k=2:nz-1)
167+
laplacian_rhs%s_(i,j,k) = ( halo_west(j,k ) - 2*rhs%s_(i,j,k) + rhs%s_(i+1,j ,k ))/dx_**2 + &
168+
(rhs%s_(i,j-1,k ) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j+1,k ))/dy_**2 + &
169+
(rhs%s_(i,j ,k-1) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j ,k+1))/dz_**2
170+
end do
171+
172+
do concurrent(i=my_internal_west+1:my_internal_east-1, j=2:ny-1, k=2:nz-1)
173+
laplacian_rhs%s_(i,j,k) = (rhs%s_(i-1,j ,k ) - 2*rhs%s_(i,j,k) + rhs%s_(i+1,j ,k ))/dx_**2 + &
174+
(rhs%s_(i ,j-1,k ) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j+1,k ))/dy_**2 + &
175+
(rhs%s_(i ,j ,k-1) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j ,k+1))/dz_**2
176+
end do
177+
178+
if (me==1) then
179+
halo_east = rhs%s_(1,:,:)
180+
else
181+
halo_east = rhs[me+1]%s_(lbound(rhs[me+1]%s_,1),:,:)
182+
end if
183+
i = my_internal_east
184+
call assert(i-1>0,"laplacian: easternmost subdomain too small")
185+
do concurrent(j=2:ny-1, k=2:nz-1)
186+
laplacian_rhs%s_(i,j,k) = (rhs%s_(i-1,j ,k ) - 2*rhs%s_(i,j,k) + halo_east(j ,k ))/dx_**2 + &
187+
(rhs%s_(i ,j-1,k ) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j+1,k ))/dy_**2 + &
188+
(rhs%s_(i ,j ,k-1) - 2*rhs%s_(i,j,k) + rhs%s_(i ,j ,k+1))/dz_**2
189+
end do
190+
191+
laplacian_rhs%s_(:, 1,:) = 0.
192+
laplacian_rhs%s_(:,ny,:) = 0.
193+
laplacian_rhs%s_(:,:, 1) = 0.
194+
laplacian_rhs%s_(:,:,nz) = 0.
195+
if (me==1) laplacian_rhs%s_(1,:,:) = 0.
196+
if (me==num_subdomains) laplacian_rhs%s_(my_nx,:,:) = 0.
197+
198+
end function
199+
200+
end submodule subdomain_s

src/matcha/t_cell_collection_m.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ pure module function construct(positions, time) result(t_cell_collection)
4242

4343
interface t_cell_collection_bind_C_t
4444

45-
elemental module function construct_bind_C(t_cell_collection) result(t_cell_collection_bind_C)
45+
impure elemental module function construct_bind_C(t_cell_collection) result(t_cell_collection_bind_C)
4646
!! Result is bind(C) representation of the data inside a t_cell_collection_t object
47+
!! This function is impure because it invokes c_loc. Fortran 2023 compliance will allow this function to be pure.
4748
implicit none
4849
type(t_cell_collection_t), intent(in), target :: t_cell_collection
4950
type(t_cell_collection_bind_C_t) t_cell_collection_bind_C
@@ -60,7 +61,6 @@ pure module function positions(self) result(my_positions)
6061
double precision, allocatable :: my_positions(:,:)
6162
end function
6263

63-
6464
elemental module function time(self) result(my_time)
6565
!! Return the t_cell_collection_t object's time stamp
6666
implicit none

src/matcha_s.f90 renamed to src/matcha_s.F90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
associate(me => this_image())
3333
associate(my_num_cells => data_partition%last(me) - data_partition%first(me) + 1)
3434

35+
#ifndef NAGFOR
3536
call random_init(repeatable=.true., image_distinct=.true.)
37+
#endif
3638

3739
allocate(random_positions(my_num_cells,ndim))
3840
call random_number(random_positions)

0 commit comments

Comments
 (0)