【发布时间】:2015-07-16 10:46:33
【问题描述】:
我正在尝试从 SBCL 调用 BLAS ddot 例程。
基于:
- ddot 文档 (http://www.netlib.org/lapack/explore-html/d5/df6/ddot_8f.html),
- 它的源代码(http://www.netlib.org/lapack/explore-html/d5/df6/ddot_8f_source.html),
- 一些额外的提示 (https://orion.math.iastate.edu/docs/cmlib/blas/ddot),
- 调用 dgemm 例程的工作示例 (Matrix-multiplication using BLAS from Common Lisp)
我想出了以下脚本:
(load-shared-object "libblas.so.3")
(declaim (inline ddot))
(define-alien-routine ("ddot_" ddot) void
(n int :copy)
(dx (* double))
(incx int :copy)
(dy (* double))
(incy int :copy))
(defun pointer (array)
(sap-alien (sb-sys:vector-sap (array-storage-vector array)) (* double)))
(defun dot (dx dy)
(unless (= (length dx) (length dy))
(error "Vectors length does not match"))
(let ((n (length dx))
(result 0.0d0))
(sb-sys:with-pinned-objects (dx dy result)
(ddot n (pointer dx) 1 (pointer dy) 1))))
但是,下面的脚本:
(defvar *a* (make-array 4 :initial-element 1.0d0 :element-type 'double-float))
(defvar *b* (make-array 4 :initial-element 2.0d0 :element-type 'double-float))
(dot *a* *b*)
产生以下错误:
arithmetic error FLOATING-POINT-INVALID-OPERATION signalled
[Condition of type FLOATING-POINT-INVALID-OPERATION]
有什么提示吗?
【问题讨论】:
标签: common-lisp blas sbcl dot-product