Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Beginner
6 Views

An issue in Intel Parallel Studio XE 2018(beat)

Jump to solution
 
When I use a array in a function with fortran,if i use teo array at a statement,sometimes it doesn't.
function f
integer,intent(in)::n
    real(rkind)::f(n,n)
    real(rkind),intent(in)::a(n,n)
    integer::i,j
    real(rkind)::b(n,n),c(n),d


    do j=2,n
        do i=1,j-1
            d=b(i,j)/b(j,j)
            b(i,:)=b(i,:)-d*b(j,:)    
            f(i,:)=f(i,:)-d*f(j,:) !This code Works properly
        end do
    end do

do j=2,n
        do i=1,j-1
            b(i,:)=b(i,:)-b(i,j)/b(j,j)*b(j,:)   
            f(i,:)=f(i,:)-d*f(j,:)  !This code doesn't work
        end do
    end do

    end function f

 

0 Kudos

Accepted Solutions
Highlighted
New Contributor I
6 Views

In your code, the value of b

Jump to solution

In your code, the value of b(I,j)/b(j,j) is not the same on line 47 as on line 46 because you change b(I,j) on line 46.

You're using d on lines 20 and 21, which is the same on both lines.

View solution in original post

0 Kudos
4 Replies
Highlighted
New Contributor II
6 Views

Can we assume the arrays b

Jump to solution

Can we assume the arrays b and f are local variables?

You dont show any initialization for b or f so they could have any value.

Exactly what do you mean by it working or not working?

Please supply a self contained example we could compile.

0 Kudos
Highlighted
Beginner
6 Views

This is the code,in this code

Jump to solution

This is the code,in this code,variable 'b' and 'c' should have the same value,but it dosen't.And the correct one should be 'b'. Function 'f1' and 'f2' just have one statement which is different,and I have note that place.The different statement should have same effect,but they are not now.(my English is poor,If I have some wrong in my reply ,plseae forgive me)

      module test
    contains
    function f1(a,n)
    integer,intent(in)::n
    real(16)::f1(n,n)
    real(16),intent(in)::a(n,n)
    integer::i,j,m
    real(16)::b(n,n),c(n),d

    b=a
    f1=0
    do i=1,n
        f1(i,i)=1
    end do



    do j=1,n
        do i=j+1,n  
            d=b(i,j)/b(j,j)
            b(i,j:)=b(i,j:)-d*b(j,j:)      !different place
            f1(i,:)=f1(i,:)-d*f1(j,:)
        end do
    end do
    end function f1



    function f2(a,n)
    integer,intent(in)::n
    real(16)::f2(n,n)
    real(16),intent(in)::a(n,n)
    integer::i,j,m
    real(16)::b(n,n),c(n),d

    b=a
    f2=0
    do i=1,n
        f2(i,i)=1
    end do



    do j=1,n
        do i=j+1,n
            b(i,j:)=b(i,j:)-b(i,j)/b(j,j)*b(j,j:)      !different place,and just replace 'd'with'b(i,j)/b(j,j)'
            f2(i,:)=f2(i,:)-b(i,j)/b(j,j)*f2(j,:)
        end do
    end do
    end function f2
    end module test
    
    
    
    
    
    
    
    program main
    use test
    implicit none
    integer,parameter::n=3
    real(16)::x(n),y(n),a(n,n),b(n,n),c(n,n)
    a=reshape([2,4,-2,1,1,2,1,0,1],[3,3])
    b=f1(a,n)
    c=f2(a,n)
    write(*,*)b
    write(*,*)
    write(*,*)
    write(*,*)
    write(*,*)
    write(*,*)
    write(*,*)c
    read(*,*)
    end program main

 

 

0 Kudos
Highlighted
Valued Contributor III
6 Views

I ran your example and B /= C

Jump to solution

I ran your example and B /= C.  A changed the function f1 and f2 to subroutines. The results are exactly the same.

I changed real(16) to real(8). The results are the same.

I  think the logic of calculation in the loops is incorrect. I don't think this is a compiler problem.

0 Kudos
Highlighted
New Contributor I
7 Views

In your code, the value of b

Jump to solution

In your code, the value of b(I,j)/b(j,j) is not the same on line 47 as on line 46 because you change b(I,j) on line 46.

You're using d on lines 20 and 21, which is the same on both lines.

View solution in original post

0 Kudos