libblas.so无法在python中打开共享项目文件?

时间:2014-11-11 18:22:13

标签: python numpy lapack blas

我是一个完整的新手,所以请原谅我的无知。

我想从这个问题中运行基准测试:

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

代码可以在这里找到: https://github.com/zed/woltan-benchmark/

运行make

我收到以下错误。

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

我猜测它无法找到libblas.so库,但不知道它在哪里?如何检查是否已安装?我正在运行Ubuntu 13.10。

谢谢你

附加信息:

触发main.py中发现的错误的python代码是:

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()

编辑1:

运行locate libblas.so后,我更换了

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

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

不确定这是否正确但现在输出如下:

terminate called after throwing an instance of 'char const*'
Aborted (core dumped)

1 个答案:

答案 0 :(得分:0)

两个错误(OSError和&#34;核心转储&#34;)归因于libblas.somain.py中找不到main.cpp且似乎{{} {1}}应该用在你的情况下。

我已更新the benchmark以使libblas.so.3名称可配置。

在我的系统(Ubuntu 14.04)上:

libblas.so

$ make clean && make

的工作。

$ make clean && make LIBBLAS_SO=libblas.so.3
$ ls -l /usr/lib/libblas.so
... /usr/lib/libblas.so -> /etc/alternatives/libblas.so