Skip to content

BLAS/LAPACK routine 'DLASCL' gave error code -4 #2

Closed

Description

@davedgd

Thanks for putting this package together -- it's nice to have easy control over BLAS in Fedora!

I've run into an issue with it however. While I was able to replicate the R-bloggers example, I ran into an issue running the sample code from this StackOverflow post.

Specifically, running this code produces an error (m is set to 1000 here instead of 10000 as in the StackOverflow original since it errors quickly):

# Singular Value Decomposition
m <- 1000
n <- 2000
A <- matrix (runif (m*n),m,n)
system.time (S <- svd (A,nu=0,nv=0))

Within RStudio, I received:

BLAS/LAPACK routine 'DLASCL' gave error code -4

Similarly, I ran into issues running this from the terminal. I tried this with intel-mkl-2020.0-088, the 2019.5 version, as well as the most recent oneAPI (although admittedly for the latter I didn't test it fully).

The expected result should be a relatively quick calculation -- at least it is on macOS and Windows.

Activity

  1. Enchufa2 commented on Mar 18, 2021

    @Enchufa2
    Owner

    Could you paste the output from sessionInfo(), please? Also, does it fail with a specific backend? Did you use the CRAN package or did you install flexiblas from the system repositories? I have R-flexiblas installed from the system repositories in Fedora 33 and I cannot reproduce the error (with 10000).

  2. davedgd commented on Mar 18, 2021

    @davedgd
    Author

    @Enchufa2: thanks for the quick reply!

    To clarify, I used the system repositories and tried OpenBLAS and MKL (intel-mkl-2020.0-088) following your R-bloggers guides, which worked perfectly for the benchmark example in the post. The code in the issue works with the default Fedora 33 OpenBLAS backend but fails when switching the backend to MKL. All of this was done with a fresh, fully-updated Fedora install.

    I will post my sessionInfo() next time I’m at the computer along with some screenshots. Hopefully I can help replicate this.

  3. davedgd commented on Mar 18, 2021

    @davedgd
    Author

    Here is the sessionInfo:

    > sessionInfo()
    R version 4.0.4 (2021-02-15)
    Platform: x86_64-redhat-linux-gnu (64-bit)
    Running under: Fedora 33 (Cinnamon)
    
    Matrix products: default
    BLAS/LAPACK: /usr/lib64/libflexiblas.so.3.0
    
    locale:
     [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
     [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
     [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
     [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
     [9] LC_ADDRESS=C               LC_TELEPHONE=C            
    [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
    
    attached base packages:
    [1] stats     graphics  grDevices utils     datasets 
    [6] methods   base     
    
    other attached packages:
    [1] flexiblas_3.0.0
    
    loaded via a namespace (and not attached):
    [1] compiler_4.0.4 tools_4.0.4   

    I've also attached screenshots showing 1) everything working fine with OpenBLAS; 2) the MKL error; and 3) sessionInfo:

    Fine with OpenBLAS
    OpenBLAS

    Error with MKL
    MKL

    sessionInfo
    sessionInfo

  4. davedgd commented on Mar 18, 2021

    @davedgd
    Author

    Sorry, one more screenshot showing how everything is oddly fine with the R-bloggers code:

    RBloggers

  5. Enchufa2 commented on Mar 18, 2021

    @Enchufa2
    Owner

    Thanks for all the details. Strange, indeed. Let's summon @grisuthedragon here, maybe this rings a bell to him.

  6. grisuthedragon commented on Mar 18, 2021

    @grisuthedragon

    Never use the MKL_RT interface. That is more (or less) dangerous. The problem is that the mkl_rt.so contains an interface with a flexible ABI controlled by some environment variables and in this way its interface is not reblas compatible. This causes most of the errors I think. For example one can change the width of an integer and the threading model via environment variables and API calls.

    The solution would be to create custumized MKL interfaces using the mklbuilder Makefile. Can you try this?
    Details are there: mpimd-csc/flexiblas#13

    The .so file created with this tool is refblas compatible and thus can be loaded as you did it.

    @Enchufa2 yes it ringed a bell ;-)

  7. davedgd commented on Mar 18, 2021

    @davedgd
    Author

    @grisuthedragon: Yes, perfect! This solution works. I used the following code from your example, but modified for a parallel version:

    make libintel64 export=blas_example_list interface=lp64 parallel=gnu threading=parallel name=flexiblas_mkl_parallel
    

    I am now seeing performance approaching what I should get for MKL (using the MKL_DEBUG_CPU_TYPE=5 workaround for Ryzen):

    > flexiblas_list_loaded()
    [1] "OPENBLAS-OPENMP"                                
    [2] "/home/daved/Downloads/flexiblas_mkl_parallel.so"
    > 
    > flexiblas_switch(2)
    > flexiblas_current_backend()
    [1] "/home/daved/Downloads/flexiblas_mkl_parallel.so"
    > 
    > flexiblas_set_num_threads(16)
    > 
    > m <- 10000
    > n <- 2000
    > A <- matrix (runif (m*n),m,n)
    > system.time (S <- svd (A,nu=0,nv=0))
       user  system elapsed 
     15.487   0.181   2.294 
    > 
    > flexiblas_get_num_threads()
    [1] 1

    Which compares favorably with OpenBLAS when set equal to the number of physical cores (e.g., 16 for my 3950X):

    > flexiblas_list_loaded()
    [1] "OPENBLAS-OPENMP"                                
    [2] "/home/daved/Downloads/flexiblas_mkl_parallel.so"
    > 
    > flexiblas_switch(1)
    > flexiblas_current_backend()
    [1] "OPENBLAS-OPENMP"
    > 
    > flexiblas_set_num_threads(16)
    > 
    > m <- 10000
    > n <- 2000
    > A <- matrix (runif (m*n),m,n)
    > system.time (S <- svd (A,nu=0,nv=0))
       user  system elapsed 
     28.464   3.108   2.869 
    > 
    > flexiblas_get_num_threads()
    [1] 16

    The only lingering (and separate) issue here is that flexiblas_get_num_threads does not seem to work when using this customized MKL interface, but this can be solved via export commands.

    Thank you!

  8. Enchufa2 commented on Mar 18, 2021

    @Enchufa2
    Owner

    Nice! I should update the post then with these instructions... My bad. :)

  9. davedgd commented on Mar 18, 2021

    @davedgd
    Author

    No worries! =) I never would have found this easy MKL solution if not for your post (first result in Google atm). Thanks again to both of you!

  10. Enchufa2 commented on Mar 18, 2021

    @Enchufa2
    Owner

    Let me keep this open to remind me to update the post. ;-)

  11. grisuthedragon commented on Mar 18, 2021

    @grisuthedragon

    In the next release (whenever I developed enough new stuff), we include a more extended verision of the text in mpimd-csc/flexiblas#13 including the way to add the MKL.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions