Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Initialisation using SUM

108 views
Skip to first unread message

Arjen Markus

unread,
Jan 27, 2021, 6:53:19 AM1/27/21
to
Hello,
I wonder if the following code is standard-conforming:

integer :: n
integer, parameter :: nelements = 20
!integer ion_end(nelements)
integer, parameter :: iatomic_number(nelements) = [&
1,2,6,7,8,10,11,12,13,14,15,16,17,18,20,22,24,25,26,28]

integer, parameter :: ion_end(nelements) = [&
(sum(iatomic_number(1:n)), n=1,nelements)]

The idea here is to accumulate the numbers in iatomic_number in another parameter array. The construction is accepted by gfortran 10.2.0 but not by Intel Fortran 2018.

Regards,

Arjen

FortranFan

unread,
Jan 27, 2021, 9:22:28 AM1/27/21
to
On Wednesday, January 27, 2021 at 6:53:19 AM UTC-5, arjen.m...@gmail.com wrote:

> ..
> I wonder if the following code is standard-conforming:
>
>.. The construction is accepted .. not by Intel Fortran 2018.
> ..

For whatever it's worth, I think the code conforms whereas Intel Fortran does not. If you're able to, you should try using Intel's latest - effectively FREE too - compiler option with IFORT Classic in their Intel oneAPI toolkit and if you still notice an issue, post the issue at their Community forum:
https://community.intel.com/t5/Intel-Fortran-Compiler/bd-p/fortran-compiler

Coming back to the Fortran standard, it essentially requires a constant expression in the named constant array evaluation. With constant expression, the standard states in section 10.1.12:

""It is an expression in which each operation is intrinsic, and each primary is ..
..
a reference to a standard intrinsic function that is transformational, other than COMMAND_ARGUMENT_COUNT, GET_TEAM, NULL, NUM_IMAGES, TEAM_NUMBER, THIS_IMAGE, TRANSFER, where each argument is a constant expression."

The intrinsic SUM is a transformational function and the expression in the code in the original post meets the requirements of section 10.1.12, to the best I can assert. Hence my thought Intel Fortran is wrong here.

In the interest of disclosure: I've several bug reports open with Intel for a while now along the same lines.

JRR

unread,
Jan 27, 2021, 9:30:17 AM1/27/21
to
Am 27.01.21 um 12:53 schrieb Arjen Markus:
The code is also accepted by NAG, but refused by nVidia, with a similar
message as for ifort:
NVFORTRAN-S-0155-Intrinsic not supported in initialization: sum (bla.f90: 8

>


--
Juergen Reuter
Theoretical Particle Physics
Deutsches Elektronen-Synchrotron (DESY)
Hamburg, Germany

Arjen Markus

unread,
Jan 27, 2021, 11:43:02 AM1/27/21
to
Thank you! I just tried with the Intel oneAPI tool set - Intel Fortran 2021.1 but that gives exactly the same error messages

Regards,

Arjen

James Van Buskirk

unread,
Jan 27, 2021, 7:03:13 PM1/27/21
to
"Arjen Markus" wrote in message
news:ffa856b8-b678-4e2f...@googlegroups.com...

> integer :: n
> integer, parameter :: nelements = 20
> !integer ion_end(nelements)
> integer, parameter :: iatomic_number(nelements) = [&
> 1,2,6,7,8,10,11,12,13,14,15,16,17,18,20,22,24,25,26,28]

> integer, parameter :: ion_end(nelements) = [&
> (sum(iatomic_number(1:n)), n=1,nelements)]

I tried a workaround:

D:\gfortran\clf\sum_init>type dot_init.f90
integer :: n
integer, parameter :: iatomic_number(*) = [&
1,2,6,7,8,10,11,12,13,14,15,16,17,18,20,22,24,25,26,28]

integer, parameter :: ion_end(*) = [&
(dot_product(iatomic_number,eoshift(reshape([integer::], &
shape=shape(iatomic_number),pad=[0]),-n,1)),
n=1,size(iatomic_number))]


write(*,'(*(g0:1x))') ion_end
end
D:\gfortran\clf\sum_init>gfortran dot_init.f90 -odot_init
dot_init.f90:6:37:

(dot_product(iatomic_number,eoshift(reshape([integer::], &
1
Error: transformational intrinsic 'eoshift' at (1) is not permitted in an
initia
lization expression

But it didn't seem to help :(

James Van Buskirk

unread,
Jan 27, 2021, 7:33:03 PM1/27/21
to


"James Van Buskirk" wrote in message news:rusuvs$9of$1...@dont-email.me...

> I tried a workaround:

Another one:

D:\gfortran\clf\sum_init>type no_eoshift.f90
integer :: n
integer, parameter :: iatomic_number(*) = [&
1,2,6,7,8,10,11,12,13,14,15,16,17,18,20,22,24,25,26,28]

integer, parameter :: ion_end(*) = &
[(dot_product(iatomic_number,reshape([(1,i=1,n)], &
shape=shape(iatomic_number),pad=[0])),n=1,size(iatomic_number))]

write(*,'(*(g0:1x))') ion_end
end
D:\gfortran\clf\sum_init>gfortran no_eoshift.f90 -ono_eoshift
no_eoshift.f90:6:44:

[(dot_product(iatomic_number,reshape([(1,i=1,n)], &
1
Error: Invalid character in name at (1)

Still no joy. BTW, what have you got against K?
https://www.youtube.com/watch?v=fmaZdEq-Xzs

Arjen Markus

unread,
Jan 28, 2021, 5:31:23 AM1/28/21
to
On Thursday, January 28, 2021 at 1:33:03 AM UTC+1, James Van Buskirk wrote:

>
> Still no joy. BTW, what have you got against K?
> https://www.youtube.com/watch?v=fmaZdEq-Xzs

Oh, you mean potassium? I thought you were referring to the K combinator and I couldn't quite figure out how that would apply here :) I will ask my friend who came up with this little problem.

Regards,

Arjen
0 new messages