Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash while building a sym tridiagonal eigmax #2267

Closed
alanedelman opened this issue Feb 11, 2013 · 5 comments
Closed

crash while building a sym tridiagonal eigmax #2267

alanedelman opened this issue Feb 11, 2013 · 5 comments

Comments

@alanedelman
Copy link
Contributor

Writing my first lapack interface. Not sure if I have all the pointers right, etc., but
anyway as long as code just crashes, it's hard to debug. I may try this on a
mac later today, but if anyone can just help me sooner, that would be great.
Here's the exact code:

const liblapack = Base.liblapack_name
import Base.BlasInt

## (ST) Symmetric tridiagonal - maxeig
for (stebz, elty) in
    ((:dstebz_,:Float64),
     (:sstebz_,:Float32))
    @eval begin
        function stebz!(dv::Vector{$elty}, ev::Vector{$elty})
            n = length(dv)
            if length(ev) != (n-1) throw(LapackDimMisMatch("stebz!")) end
            z=Array($elty,1)
            z[1]=0.0    #just to be sure
            m=Array(BlasInt,1)
            nsplit =Array(BlasInt,1)
            w  = Array($elty, n)
            iblock = Array(BlasInt,n)
            isplit = Array(BlasInt,n)
            work = Array($elty, 4*n)
            iwork = Array(BlasInt,3*n)
            info = Array(BlasInt, 1)
            ccall(($(string(stebz)),liblapack), Void,
                  (Ptr{Uint8},Ptr{Uint8},
                   Ptr{BlasInt},Ptr{BlasInt},Ptr{BlasInt},Ptr{BlasInt},Ptr{BlasInt},
                   Ptr{$elty},Ptr{$elty},Ptr{$elty},
                   Ptr{BlasInt},Ptr{BlasInt},
                   Ptr{$elty},Ptr{BlasInt},Ptr{$elty},Ptr{BlasInt},Ptr{BlasInt}),
                   'I','B',
                   &n,0,0,&n,&n,
                   z,dv,ev,
                   m, nsplit,
                   w, iblock,work,iwork,info)
            if info[1] != 0 throw(LapackException(info[1])) end
            w
        end
    end
end
@JeffBezanson
Copy link
Member

According to http://www.netlib.org/lapack/double/dstebz.f, the fourth and fifth arguments are float, not integer, and all scalars passed to fortran functions need &, including constants.

@andreasnoack
Copy link
Member

Also, the isplit argument was missing in ccall. This one works for me

const liblapack = Base.liblapack_name
import Base.BlasInt

for (stebz, elty) in ((:dstebz_,:Float64),
                      (:sstebz_,:Float32))
    @eval begin
        function stebz!(dv::Vector{$elty}, ev::Vector{$elty})
            n = length(dv)
            if length(ev) != (n-1) throw(LapackDimMisMatch("stebz!")) end
            z = 0.0 #just to be sure
            m = Array(BlasInt,1)
            nsplit = Array(BlasInt,1)
            w = Array($elty, n)
            iblock = Array(BlasInt,n)
            isplit = Array(BlasInt,n)
            work = Array($elty, 4*n)
            iwork = Array(BlasInt,3*n)
            info = Array(BlasInt, 1)
            ccall(($(string(stebz)),liblapack), Void,
                (Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{$elty},
                Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
                Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt},
                Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
                Ptr{BlasInt}, Ptr{BlasInt}),
                &'I', &'B', &n, &0.0, 
                &0.0, &n, &n, &z, 
                dv, ev, m, nsplit,
                w, iblock, isplit, work, 
                iwork, info)
                if info[1] != 0 throw(LapackException(info[1])) end
            w
        end
    end
end

@alanedelman
Copy link
Contributor Author

cool! guess i was close.

@alanedelman
Copy link
Contributor Author

THANK YOU BOTH SO MUCH! I can do a 100,000 eigmax in 100 msecs
while a 20,000 eigvals already rakes 18 seconds (factor of 200 more time!)

Something to look into is the different answers slightly numerically. The eigenvalue I'm testing
is ill-conditioned, and not the one I'll need for my real application, so perhaps it falls into the
usual backward error analysis situations.

@ViralBShah
Copy link
Member

We should probably implement fcall as discussed in #2167. Is there anything we can do to avoid a crash in such situations?

Also, after the 0.1 freeze is lifted, let's get stebz in. Closing, since this immediate issue is fixed.

IanButterworth pushed a commit that referenced this issue Jun 4, 2024
Stdlib: Pkg
URL: https://github.com/JuliaLang/Pkg.jl.git
Stdlib branch: master
Julia branch: master
Old commit: ed7a8dca8
New commit: 4e43058c2
Julia version: 1.12.0-DEV
Pkg version: 1.12.0
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Pkg.jl@ed7a8dc...4e43058

```
$ git log --oneline ed7a8dca8..4e43058c2
4e43058c2 Merge pull request #3887 from carlobaldassi/validate_versions
bc7c3207d abort querying more pacakge for hint auto complete (#3913)
a4016aed2 precompile repl switch (#3910)
a48c9c645 Fixed glitch in the manual (#3912)
d875aa213 Add timeout and new tests for resolver
aeb55f7f0 run artifact selection code with minimal compilation (#3899)
0180a0105 avoid doing some checks if the package will not be showed in status output (#3897)
c6c7ed502 improve precompilation for `st` in the Pkg REPL (#3893)
bffd0633c Add version validation during Graph simplification
c2ad07003 Fix padding in resolve's log journal printing
3eb86d29f Revert #2267, with better log message
acdbb727e Small extra check in Graph's check_consistency
1d446c224 Fix small bug in Graph constructor
3efc3cbff Fix show method for VersionSpecs
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants