我试图从SBCL调用BLAS ddot例程。
基于:
我想出了以下脚本:
rails s -b 0.0.0.0
但是,以下脚本:
(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*)
任何提示?
答案 0 :(得分:4)
找到它。感谢布拉格查理大学的Miroslav Urbanek的暗示。
-(define-alien-routine ("ddot_" ddot) void
+(define-alien-routine ("ddot_" ddot) 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)
+ (let ((n (length dx)))
+ (sb-sys:with-pinned-objects (dx dy)
ddot例程旨在返回double,而不是void。而结果变量是无用的。事情是如此明显在之后你意识到了它们:-)
答案 1 :(得分:3)