0

compiled a program with 'call segesv()' to solve system of 3 Equates in 3 Vars and that works fine so I know I'm linked to Blas and Lapack however, 'call SASUM' also compiles (I pass a vector of numbers to SASUM) but cannot see the results I must use X=SASUM without the fortran 'call' syntax and I cannot do it, tried multiple things I found in forums but none of them compile. Please help!

      IMPLICIT NONE  !(type, external)
    !  INTRINSIC MOD
   ! USE liblapack
     
   ! =================================================
   ! declarations, notice single precision
   ! =================================================
      REAL :: A(3,3), b(3)
      !REAL(kind=kind(1.d0)), EXTERNAL::SASUM
      !REAL(kind=kind(1.d0)), EXTERNAL::SGESV
      INTEGER :: C(1:12),N 
      INTEGER ::  i, j, pivot(3), ok
      INTEGER(8) X, XX, XXX
      INTEGER(8) Y,YY, YYY
      INTEGER(8) Z, ZZ, ZZZ
      INTEGER(8) ANSWER1,ANSWER2,ANSWER3
      INTEGER(8) D,E
      
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  !  receive user input
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    write (*,*) "Solves 3 by 3 system, assuming varibles 'X' 'Y' 'Z' enter coefficient for X in 1st equation"
    read (*,*) X
    write (*,*) "enter coefficient for Y in 1st equation"  
    read (*,*) Y
    write (*,*) "enter coefficient for Z in 1st equation"
    read (*,*) Z
    write (*,*) "enter coefficient for X in 2nd equation"
    read (*,*) XX
    write (*,*) "enter coefficient for Y in 2nd equation"
    read (*,*) YY
    write (*,*) "enter coefficient for Z in 2nd equation"
    read (*,*) ZZ
    write (*,*) "enter coefficient for X in 3rd equation"
    read (*,*) XXX
    write (*,*) "enter coefficient for Y in 3rd equation"
    read (*,*) YYY
    write (*,*) "enter coefficient for Z in 3rd equation"
    read (*,*) ZZZ
    write (*,*) "enter answer of 1st equation"
    read (*,*) ANSWER1
    write (*,*) "enter answer of 2nd equation"
    read (*,*) ANSWER2 
    write (*,*) "enter answer of 3rd equation"
    read (*,*) ANSWER3
    
   ! =================================================
   ! define matrix A
   ! =================================================
      A(1,1)=X; A(1,2)=Y; A(1,3)=Z
      A(2,1)=XX; A(2,2)=YY; A(2,3)=ZZ
      A(3,1)=XXX; A(3,2)=YYY; A(3,3)=ZZZ

   ! =================================================
   ! define vector b, make b a matrix and you can solve multiple
   ! equations with the same A but different b
   ! =================================================
      b(1)=ANSWER1; b(2)=ANSWER2; b(3)=ANSWER3

      write (*,*) "this is A before 'segesv'"
      print*, A
      write (*,*) "b was loaded with answers to equations"
      print*, b
   ! =================================================
   ! find the solution using the LAPACK routine SGESV
   ! =================================================
      call SGESV(3, 1, A, 3, pivot, b, 3, ok)
   ! =================================================
   !
   ! parameters in the order as they appear in the function call:
   !    - 3= order of matrix A, 
   !    - 1= number of right hand sides (b)
   !    - A= matrix A,
   !    - 3= leading dimension of A
   !    - pivot= array that records pivoting, 
   !    - b= result vector b on entry, solution x on exit, 
   !    - 3= leading dimension of b
   !    - ok= return value  
   ! =================================================

   ! =================================================
   ! print the solution vector 
   ! =================================================
      
     write (*,*) "after 'sgesv' A is now inverted"
      print *, A
     write(*,*) "b is now loaded with the solutions to X,Y and Z"
      print *, b
     write (*,*) "X=",b(1)
     write (*,*) "Y=",b(2) 
      write(*,*) "Z=",b(3)
      
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      !C(1:12)=1 2 3 4 5 6 7 8 9 10 11 12
      C(1)=1
      C(2)=-2
      C(3)=0
      C(4)=-4
      C(5)=5
      C(6)=0
      C(7)=7
      C(8)=-8
      C(9)=0
      C(10)=-10
      C(11)=11
      C(12)=0
      N=1
    FORALL (I=1:N) A(I, I) = 1
    write(*,*) "C=", C
    E=1
    
    write(*,*) "SASUM="
   ! E=SASUM(4,C,2)
    write(*,*) "C after SASUM"
    write(*,*) C
    write(*,*) "E after SASUM"
    write(*,*) E
      
!have yet to figure out reshape for a 3X3

 !implicit none (type, external)
 !external :: sgesv
 !real     :: a(3, 3)  ! Matrix A.
 !real     :: b(3)     ! Vector b/x.
 !real     :: pivot(3) ! Pivot indices (list of swap operations).
 !integer  :: rc       ! Return code.
 !
 !a = reshape([ 2., 3., 1., 1. ], [ 2, 2 ])
 !b = [ 5., 6. ]
 !
 !call sgesv(2, 1, a, 2, pivot, b, 2, rc)
 !
 !if (rc /= 0) then
 !    print '(a, i0)', 'Error: ', rc
 !    stop
 !end if
 !
 !print '("Solution (x1, x2): ", f0.4, ", ", f0.4)', b
      
      
      

      !use onemkl_blas_omp_offload_lp64
     ! use mkl_blas.fi

         
   
      
      
      !IMPLICIT NONE
      !INTEGER, PARAMETER :: N=100
      !REAL, DIMENSION (N) :: XRAY,Y1RAY,Y2RAY
      !REAL, PARAMETER :: PI=3.1415926
      !REAL :: FPI,STEP,X
      !INTEGER::I,IC
      ! !external :: sgesv
      !real     :: a(2, 2)  ! Matrix A.
      !real     :: b(2)     ! Vector b/x.
      !real     :: pivot(2) ! Pivot indices (list of swap operations).
      !integer  :: rc       ! Return code.
      !
      !
      !FPI=PI/180.
      !STEP=360./(N-1)
      !
      !DO I=1,N
      !  XRAY(I)=(I-1)*STEP
      !  X=XRAY(I)*FPI
      !  Y1RAY(I)=SIN(X)
      !  Y2RAY(I)=COS(X)
      !END DO
      !
      !write (*,*) X
      !
      !CALL METAFL('CONS')  !evidently only the disifl libs are fortran
      !CALL DISINI()
      !CALL PAGERA()
      !CALL COMPLX()
      !CALL AXSPOS(450,1800)
      !CALL AXSLEN(2200,1200)
      !
      !CALL NAME('X-axis','X')
      !CALL NAME('Y-axis','Y')
      !
      !CALL LABDIG(-1,'X')
      !CALL TICKS(10,'XY')
      !
      !CALL TITLIN('Demonstration of CURVE',1)
      !CALL TITLIN('SIN(X), COS(X)',3)
      !
      !IC=INTRGB(0.95,0.95,0.95)
      !CALL AXSBGD(IC)
      !
      !CALL GRAF(0.,360.,0.,90.,-1.,1.,-1.,0.5)
      !CALL SETRGB(0.7,0.7,0.7)
      !CALL GRID(1,1)
      !
      !CALL COLOR('FORE')
      !CALL TITLE()
      !
      !CALL COLOR('RED')
      !CALL CURVE(XRAY,Y1RAY,N)
      !CALL COLOR('GREEN')
      !CALL CURVE(XRAY,Y2RAY,N)
      !CALL DISFIN()
      !CALL F07AAF()
   

  
     

      END PROGRAM EXA_1


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : I4 => INT32, DP => REAL64
9
  • Cross posted to community.intel.com/t5/GPU-Compute-Software/… Be aware it is not very nice because you get an answer on one site and then typicalky peple spend effort to answer your questiin on the other site when you do not need it any more. Commented Oct 13, 2023 at 6:22
  • You did not really told us what this SASUM is and where does it come from. I will link its manual page netlib.org/lapack/explore-html/df/d28/… However, I cannot understand your problem. What exactly happens when you use E=SASUM(4,C,2)? Error messages? What exactly is the output of the compiler and of the run? Commented Oct 13, 2023 at 6:27
  • 1
    What exactly have you tried? You are aware SASUM is the "single precision" routine? As such the commented out declaration of it is not correct. And in general removing declarations of the objects you use is not a good way to try and fix problems Commented Oct 13, 2023 at 6:55
  • Also note using explicit kinds such as ( 8 ) is bad practice. It is not portable, the value you choose might not be supported by a compiler, and if it is might not do what you expect. See stackoverflow.com/questions/838310/fortran-90-kind-parameter Commented Oct 13, 2023 at 6:59
  • 2
    SASUM expects a default real array as argument, and returns a default real result. You are using it with an integer C array as argument, and are declaring the result as double precision. So of course it won't work as expected. Commented Oct 13, 2023 at 10:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.