cblas_dgemm - 仅当(beta)是二的幂时才有效

发布于 2024-09-24 06:04:19 字数 405 浏览 16 评论 0原文

我完全被难住了。我有一个用 c 编写的相当大的递归程序,它调用 cblas_dgemm()。结果由正确运行的程序独立验证。

C = alpha*A*B + beta*C 

在使用随机矩阵和所有可能的参数组合进行重复测试时,只有当 abs(beta) = 2^n (1,2,4,8..) 时,程序才会给出正确答案。任何值都适用于 alpha。任何其他正/负、奇/偶的 beta 值在 10-30% 的时间内给出正确的黑白答案。

我使用的是Ubuntu 10.04,GCC 4.4.x,我尝试过系统安装blas/cblas/atlas以及手动编译的atlas。

任何提示或建议将不胜感激。我对潜伏在这个网站上的非常慷慨(而且聪明)的人们感到惊讶。

预先感谢大家,

拉斯

I am totally stumped. I have a fairly large recursive program written in c that calls cblas_dgemm(). The result is verified independently by a program that works correctly.

C = alpha*A*B + beta*C 

On repeated tests using random matrices and all possible combination of parameters the program gives correct answer ONLY if abs(beta) = 2^n (1,2,4,8..). Any value works for alpha. Any other positive/negative, odd/even value for beta gives correct answer b/w 10-30% of the time.

I am using Ubuntu 10.04, GCC 4.4.x, I have tried system installed blas/cblas/atlas as well as manually compiled atlas.

Any hints or suggestions would be greatly appreciated. I am amazed at the wonderfully generous (and smart) folks lurking at this site.

Thanking you all in advance,

Russ

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞳孔里扚悲伤 2024-10-01 06:04:19

两个完全不相关的错误共同产生了一幅虚幻的画面。这让我在错误的地方寻找问题。

(1) 调用 dgemm 的函数逻辑存在简单错误。如果我没有追寻错误的问题,本来很容易解决。

(2)我的双重比较函数:AlmostEqual2sComplement()的双重版本(http: //www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm)使用了错误大小的整数 - 在某些罕见的情况下导致错误的 TRUE。这是我第一次被这个错误咬到!

再次感谢您在尝试调试程序时使用科学方法的有用建议。

拉斯

Two completely unrelated errors conspired to produce an illusive picture. It made me look for problems in the wrong place.

(1) There was a simple error in the logic of the function calling dgemm. Would have been easily fixed if I was not chasing the wrong problem.

(2) My double-compare function: double version of AlmostEqual2sComplement() (http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm) used incorrect sized integer - resulting in an incorrect TRUE under certain rare circumstances. This was the first time the error bit me!

Thanks again for the useful suggestion of using the scientific method when trying to debug a program.

Russ

情愿 2024-10-01 06:04:19

是的,一个完整的例子会很方便。这是我使用 GSL 的 sgemm 变体的一个旧示例;应该很容易修复为 double 。请尝试看看这是否给出了 GSL 手册中显示的结果:

/* from the gsl info documentation in node 'gsl cblas examples' */
/* compile via 'gcc -o $file $file.c -lgslcblas' */
/* edd 15 Nov 2003 */ 

#include <stdio.h>      
#include <gsl/gsl_cblas.h> 

int   
main (void)    
{     
  int lda = 3; 
  float A[] = { 0.11, 0.12, 0.13,  
                0.21, 0.22, 0.23 };  
  int ldb = 2;                      
  float B[] = { 1011, 1012,  
                1021, 1022,                                                      
                1031, 1032 }; 
  int ldc = 2; 
  float C[] = { 0.00, 0.00,  
                0.00, 0.00 };     
  /* Compute C = A B */ 
  cblas_sgemm (CblasRowMajor,  
               CblasNoTrans, CblasNoTrans, 2, 2, 3,  
               1.0, A, lda, B, ldb, 0.0, C, ldc);  
  printf ("[ %g, %g\n", C[0], C[1]);         
  printf ("  %g, %g ]\n", C[2], C[3]);   

  return 0;    
}          

Yes, a full example would be handy. Here is an old example I had hanging around using GSL's sgemm variant; should be easy to fix to double. Please try and see if this gives the result shown in the GSL manual:

/* from the gsl info documentation in node 'gsl cblas examples' */
/* compile via 'gcc -o $file $file.c -lgslcblas' */
/* edd 15 Nov 2003 */ 

#include <stdio.h>      
#include <gsl/gsl_cblas.h> 

int   
main (void)    
{     
  int lda = 3; 
  float A[] = { 0.11, 0.12, 0.13,  
                0.21, 0.22, 0.23 };  
  int ldb = 2;                      
  float B[] = { 1011, 1012,  
                1021, 1022,                                                      
                1031, 1032 }; 
  int ldc = 2; 
  float C[] = { 0.00, 0.00,  
                0.00, 0.00 };     
  /* Compute C = A B */ 
  cblas_sgemm (CblasRowMajor,  
               CblasNoTrans, CblasNoTrans, 2, 2, 3,  
               1.0, A, lda, B, ldb, 0.0, C, ldc);  
  printf ("[ %g, %g\n", C[0], C[1]);         
  printf ("  %g, %g ]\n", C[2], C[3]);   

  return 0;    
}          
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文