Skip to content

cannot find blas/lapack #112

Description

@rveltz

Hi,

I am building a wrapper for multifario.sourceforge.io/. So far, every works pretty well, I am impressed by the bindings generated by the package!

However, I have an example file from multifario that I can compile with

gcc ComputeSphereSub.c -o ComputeSphereSub -std=c99 -Wl,-no_compact_unwind -I/Users/me/Downloads/work/multifario-v1.0/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/Headers/ -L/Users/me/Downloads/work/multifario-v1.0/lib -L/opt/homebrew/Cellar/gcc/12.2.0/lib/gcc/current/ -lgfortran -lquadmath -lm -lblas -llapack -lsh -lexpcmp -lautof2c -lauto2000 -lmf

and it works when I run ComputeSphereSub

I have translated the same code (from ComputeSphereSub.c) and use the same import

c"-std=c99 -Wl -I/Users/me/Downloads/work/multifario-v1.0/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/Headers/ -L/Users/me/Downloads/work/multifario-v1.0/lib -L/opt/homebrew/Cellar/gcc/12.2.0/lib/gcc/current/ -lgfortran -lquadmath -lm -lblas -llapack -lsh -lexpcmp -lautof2c -lauto2000 -lmf"

but when running the Julia code, I get the error

Error: no BLAS/LAPACK library loaded!

Am I missing something?

Activity

  1. krrutkow commented on Oct 14, 2022

    @krrutkow
    Member

    It seems that (on my system anyways) multifario is somewhat improperly configured. The libMF references symbols from libSH, but it is not linked to it and assumes the user of the libraries links to them both. The problem this causes for Julia is that it is not linked to the libraries, it loads them dynamically, and the default behavior is to keep dynamically loaded libraries from accessing each other.

    So a quick fix I did was to make a single library to link all of the multifario libraries together, like the gcc command does:

    gcc -g -O -I./include -DNOMFSIMPLEX -DMFALLOWVERBOSE -DMANIFOLD -DHAVE_AUTO -g -O2 -shared -o libmultifario.so -L./lib lib/.libs/libMF.so lib/.libs/libExpCmp.so lib/.libs/libSH.so lib/.libs/libauto2000.so lib/.libs/libautof2c.so -llapack -lblas -L/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0 -L/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../.. -lgfortran -lquadmath -lm -ltiff -Wl,-rpath -Wl,$PWD/multifario-v1.0/usr/lib
    

    Which is essentially the command used to build ComputeSphereSub (found by running make), but using -shared -o libmultifario.so in place of -o bin/.libs/ComputeSphereSub Examples/ComputeSphereSub.o in that command.

    This 1 library can then be used, something like this:

    julia> module libmultifario
           using CBinding
           c`-I $(pwd())/multifario-v1.0/include -L $(pwd())/multifario-v1.0 -lmultifario`
           const c"FILE" = Cvoid
    
           # headers included from ComputeSphereSub.c
           c"""
           #include <MFAtlas.h>
           #include <MFNRegion.h>
           #include <MFNVector.h>
           #include <MFFortran.h>
           #include <MFMultifariosMethod.h>
           """ji
           end

    There are many warnings about functions defined in the header files that are not actually in the libraries though, but it seems that implementing the ComputeSphereSub code in Julia is possible:

    julia> e=libmultifario.MFCreateErrorHandler()
    CBinding.Cptr{Main.libmultifario.var"c\"struct MFErrorHandlerSt\""}(0x0000000001ec49d0)

    At no point did I encounter an issue with BLAS/LAPACK as you mentioned though, so perhaps this alternative approach mitigates that issue for you.

  2. rveltz commented on Oct 14, 2022

    @rveltz
    Author

    Thanks a lot for the explanations! I still have the same issue (julia 1.8 apple M1). The last line output the lapack error

    c"""
    #include <MFFortran.h>
    #include <multifarioConfig.h>
    #include <MFAtlas.h>
    #include <MFNRegion.h>
    #include <MFNVector.h>
    #include <math.h>
    #include <MFFortran.h>
    #include <MFMultifariosMethod.h>
    """ji
    
    function F(n, z, m, f, data, e)
        f[1]= z[1]^2 + z[2]^2 + z[3]^2 - 1.
        nothing
    end
    
    function dF(n, z, m, df, data, e)
        df[0+1* 0+1]= 2*z[0+1]
        df[0+1* 1+1]= 2*z[1+1]
        df[0+1* 2+1]= 2*z[2+1]
        nothing
    end
    
    function ddF(n, z, m, ddf, data, e)
        ddf[0+1*(0+3*0)+1]= 2
        ddf[0+1*(1+3*0)+1]= 0
        ddf[0+1*(2+3*0)+1]= 0
    
        ddf[0+1*(0+3*1)+1]= 0
        ddf[0+1*(1+3*1)+1]= 2
        ddf[0+1*(2+3*1)+1]= 0
    
        ddf[0+1*(0+3*2)+1]= 0
        ddf[0+1*(1+3*2)+1]= 0
        ddf[0+1*(2+3*2)+1]= 2
        nothing
    end
    
    function DrawSphere( v,u,d, e)
      if(u==C_NULL||v==C_NULL)
        return Int32(3)
      end
    
      u[0+1] = MFNV_C(v,0,e)
      u[1+1] = MFNV_C(v,1,e)
      u[2+1] = MFNV_C(v,2,e)
    
      return Int32(0)
    end
    
    e = MFCreateErrorHandler()
    n = 3
    k = 2
    M = MFIMFCreateAlgebraicSubroutine(n, k, F, dF, ddF, C_NULL, e)
    
    MFIMFSetProjectForDraw(M, DrawSphere, e)
    
    u0 = [MFIMFVectorFactory(M, e) for _ = 1:2]
    
    Omega = MFNRegionCreateHyperCube(n, 1.1, e)
    
    u0[1] = MFIMFVectorFactory(M, e)
    for j=0:n-1
        MFNVSetC(u0[1], j, 0., e)
    end
    MFNVSetC(u0[1], 1, 1., e)
    
    u0[2]=MFIMFVectorFactory(M, e)
    for j=0:n-1
        MFNVSetC(u0[2], j, 0., e)
    end
    MFNVSetC(u0[2], 2, 1., e)
    
    H = MFCreateMultifariosMethod(e)
    MFMultifarioSetRealParameter(H, "epsilon", .01, e)
    MFMultifarioSetIntegerParameter(H, "maxCharts", 100, e)
    MFMultifarioSetIntegerParameter(H, "verbose", 1, e)
    MFMultifarioSetIntegerParameter(H, "page", 1, e)
    MFMultifarioSetIntegerParameter(H, "dumpToPlotFile", 1, e)
    MFMultifarioSetIntegerParameter(H, "dumpToCenterFile", 1, e)
    MFMultifarioSetFilename(H, "SphereSub", e)
    
    S = MFComputeAtlasMultiple(H, M, Omega, 2, u0, e)
  3. krrutkow commented on Oct 14, 2022

    @krrutkow
    Member

    Well, unfortunately what you posted runs fine on my Linux system with Julia 1.8.2... Only thought I have is to just verify that your aggregate library links to some BLAS/LAPACK libraries. It might look something like this (run in a shell):

    ldd multifario-v1.0/libmultifario.so 
            linux-vdso.so.1 (0x00007ffdc1791000)
            libMF.so.0 => multifario-v1.0/usr/lib/libMF.so.0 (0x00007f709b8fa000)
            libExpCmp.so.0 => multifario-v1.0/usr/lib/libExpCmp.so.0 (0x00007f709b8ea000)
            libSH.so.0 => multifario-v1.0/usr/lib/libSH.so.0 (0x00007f709b8d7000)
            libauto2000.so.0 => multifario-v1.0/usr/lib/libauto2000.so.0 (0x00007f709b886000)
            libautof2c.so.0 => multifario-v1.0/usr/lib/libautof2c.so.0 (0x00007f709b881000)
            liblapack.so.3 => /usr/lib/liblapack.so.3 (0x00007f709b16d000)
            libopenblas.so.3 => /usr/lib/libopenblas.so.3 (0x00007f7099db8000)
            libgfortran.so.5 => /usr/lib/libgfortran.so.5 (0x00007f7099afd000)
            libquadmath.so.0 => /usr/lib/libquadmath.so.0 (0x00007f7099ab2000)
            libm.so.6 => /usr/lib/libm.so.6 (0x00007f70999ca000)
            libtiff.so.5 => /usr/lib/libtiff.so.5 (0x00007f7099936000)
            libc.so.6 => /usr/lib/libc.so.6 (0x00007f709972c000)
            libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f7099711000)
            libgomp.so.1 => /usr/lib/libgomp.so.1 (0x00007f70996cc000)
            /usr/lib64/ld-linux-x86-64.so.2 (0x00007f709b9ca000)
            libzstd.so.1 => /usr/lib/libzstd.so.1 (0x00007f709961d000)
            liblzma.so.5 => /usr/lib/liblzma.so.5 (0x00007f70995f4000)
            libjpeg.so.8 => /usr/lib/libjpeg.so.8 (0x00007f7099573000)
            libz.so.1 => /usr/lib/libz.so.1 (0x00007f7099559000)
            libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f7099554000)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions