Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28345 Discussions

can't assign the value to an array

lauhwa
Novice
694 Views

cd1, cdo and cd2 are array with 2 elements. while i want to assign cd2 by 

cd2 = cdo - cd1

cd2 got an empty value as the video shows, it means I even can't write the value, when I run 

write(*,*)cd2

It will be empty.

However 

If i run 

do i=1,2
cd2(i) = cdo(i) - cd1(i)
enddo

It works fine.

 

The compiler is 

Intel® Fortran Compiler Classic for applications running on Intel(R) 64, version 2021.9.0 Package ID: w_oneAPI_2023.1.0.46319

and the CPU is Ryzen 9 6900.

0 Kudos
1 Solution
lauhwa
Novice
641 Views

I checked the above code, i find I assign a array of shape of 3 to a array of shape of 2. This operation leaded to the failure.

View solution in original post

0 Kudos
3 Replies
andrew_4619
Honored Contributor II
649 Views

Well the video doesn't show it has being empty it has very small values.  We cannot tell  what the result should be from the video as far as I can tell.  That array operation is so basic to Fortran code the 100's of us on this site would be all screaming about it if that didn't work! So we can only assuming you are interpreting things incorrectly or that something bizarre is happing.  I would suggest on the line before setting cd2 =0.0 and run your debug case again to see if things are clearer.  Do you have any level of optimisation on? That is not good with debug builds. Another cause could be memory corruption due to some faulty code elsewhere in the program.   We would normally say make a small complete test program that shows the problem but I would bet big money that you won't be able to replicate the problem in the small code or that you see the problem cause during doing it. We all suffer 'code blindness'  from time to time where we are looking so hard we do not see the obvious problem.

0 Kudos
lauhwa
Novice
642 Views

I checked the above code, i find I assign a array of shape of 3 to a array of shape of 2. This operation leaded to the failure.

0 Kudos
gib
New Contributor II
556 Views

You could say:

Cd2(1:2) = cd0(1:2) - cd1(1:2)

0 Kudos
Reply