2

I'm a complete newbie with regards to this so please excuse my ignorance.

I wanted to run the benchmark from this question:

Benchmarking (python vs. c++ using BLAS) and (numpy)

The code can be found here: https://github.com/zed/woltan-benchmark/

after running make I get the following error.

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    _blaslib = ctypes.cdll.LoadLibrary("libblas.so")
  File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libblas.so: cannot open shared object file: No such file or directory
make: *** [Test.csv] Error 1

I'm guessing that it can't find the libblas.so library, but no idea where it is? How can I check if it's installed? I'm running Ubuntu 13.10.

Thanks you

ADDITIONAL INFO:

The python code triggering the error found in main.py is:

import ctypes
from ctypes import byref, c_char, c_int, c_float
import numpy
import os
import subprocess
import timeit

_blaslib = ctypes.cdll.LoadLibrary("libblas.so")

def Mul(m1, m2, i, r):

    no_trans = c_char("n")
    n = c_int(i)
    one = c_float(1.0)
    zero = c_float(0.0)

    _blaslib.sgemm_(byref(no_trans), byref(no_trans), byref(n), byref(n), byref(n), byref(one), m1.ctypes.data_as(ctypes.c_void_p), byref(n), 
                                                                                                m2.ctypes.data_as(ctypes.c_void_p), byref(n), byref(zero),
                                                                                                r.ctypes.data_as(ctypes.c_void_p), byref(n))

if __name__ == '__main__':

    rNumpy = []
    rBlas = []

    p = subprocess.Popen("./bench {0}".format(str([x for x in range(5, 501, 5)])[1:-1]), shell = True)
    os.waitpid(p.pid, 0)

    for i in range(20, 501, 20):
        m1 = numpy.random.rand(i,i).astype(numpy.float32)
        m2 = numpy.random.rand(i,i).astype(numpy.float32)

        tNumpy = timeit.Timer("numpy.dot(m1, m2)", "import numpy; from __main__ import m1, m2")
        rNumpy.append((i, tNumpy.repeat(20, 1)))

        r = numpy.zeros((i,i), numpy.float32)
        tBlas = timeit.Timer("Mul(m1, m2, i, r)", "import numpy; from __main__ import i, m1, m2, r, Mul")
        rBlas.append((i, tBlas.repeat(20, 1)))
        print i

    f = open("Test.csv", "w")

    for (i, n), (j, b) in zip(rNumpy, rBlas):
        f.write("{0} {1} {2} {3} ".format(i, sum(n)/len(n), min(n), max(n)))
        f.write("{0} {1} {2} {3}\n".format(j, sum(b)/len(b), min(b), max(b)))

    f.close()

EDIT 1:

After running locate libblas.so I replaced

_blaslib = ctypes.cdll.LoadLibrary("libblas.so")

with

_blaslib = ctypes.cdll.LoadLibrary("/usr/lib/libblas/libblas/libblas.so.3")

not sure if this is correct but it now the output looks like:

terminate called after throwing an instance of 'char const*'
Aborted (core dumped)
5
  • Under linux, you use the locate command, ie: locate libblas.so Commented Nov 11, 2014 at 18:23
  • One more thing, it looks like you may not have BLAS installed. Do apt-cache search libblas Commented Nov 11, 2014 at 18:27
  • thanks for that. I got a number of them eg /usr/lib/libblas.so.3, /usr/lib/libblas.so.3.0 Commented Nov 11, 2014 at 18:28
  • is there something specific you want me to output from the apt-cache search command, it gave me a very long list of things... of which some are libblas-dev, libopenblas-base Commented Nov 11, 2014 at 18:29
  • Make sure the path is in your loader search path. Commented Nov 11, 2014 at 18:30

1 Answer 1

0

Both errors (OSError and "core dumped") are due to libblas.so is not found in main.py and main.cpp correspondingly and it seems libblas.so.3 should be used in your case.

I've updated the benchmark to make libblas.so name configurable.

On my system (Ubuntu 14.04) both:

$ make clean && make

and

$ make clean && make LIBBLAS_SO=libblas.so.3

work.

$ ls -l /usr/lib/libblas.so
... /usr/lib/libblas.so -> /etc/alternatives/libblas.so
$ update-alternatives --display libblas.so
libblas.so - auto mode
  link currently points to /usr/lib/openblas-base/libblas.so
/usr/lib/libblas/libblas.so - priority 10
  slave libblas.a: /usr/lib/libblas/libblas.a
/usr/lib/openblas-base/libblas.so - priority 40
  slave libblas.a: /usr/lib/openblas-base/libblas.a
Current 'best' version is '/usr/lib/openblas-base/libblas.so'.
Sign up to request clarification or add additional context in comments.

Comments

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.