2

几天前我在 AMD 开发者论坛上问过这个问题,但没有得到答案。也许这里有人有一些见识。
http://devgurus.amd.com/thread/167492

我在 Ubuntu 12.04 上的 Opteron 6348 处理器上运行 ACML 版本 5.3.1、libacml_mp 和 gfortran_fma4。

如果我第一次调用 dpotrf(cholesky 分解),调用 dsyev(特征分解)的性能会显着降低(10 倍以上)。为什么会发生这种情况对我来说毫无意义。也许我需要清除某种缓存或类似的东西。

这是一个重现该问题的简单 C 程序。

#include <stdio.h>
#include <stdlib.h>
#include <acml.h>
#include <time.h>

int main(void) {
  double * x = malloc(1000000 * sizeof(double));
  double * y = malloc(1000000 * sizeof(double));
  double * eig0 = malloc(1000000 * sizeof(double));
  double * eig1 = malloc(1000000 * sizeof(double));
  double * eigw = malloc(1000 * sizeof(double));
  double * chol = malloc(1000000 * sizeof(double));

  clock_t t0,t1;
  int info;
  int i;

  // generate a random matrix
  for(i = 0; i<1000000; ++i){
    x[i] = rand() / (double) RAND_MAX;
  }

  // compute y = xx^T so that y is symmetric positive definite
  dgemm('N','T',1000,1000,1000,1,x,1000,x,1000,0,y,1000);

  // make a copy of y for cholesky and eigen decompositions
  for(i = 0; i<1000000; ++i){
    chol[i] = y[i];
    eig0[i] = y[i];
    eig1[i] = y[i];
  }

  // first eigenvalue test
  t0 = clock();
  dsyev('V','U',1000,eig0,1000,eigw,&info);
  t1 = clock();
  printf("Eigen decomposition time: %d\n", (t1-t0)/1000);

  // cholesky
  dpotrf('U',1000,chol,1000,&info);

  // second eigenvalue test, after cholesky
  t0 = clock();
  dsyev('V','U',1000,eig1,1000,eigw,&info);
  t1 = clock();
  printf("Eigen decomposition time: %d\n", (t1-t0)/1000);
}

这是输出:

Eigen decomposition time: 8120
Eigen decomposition time: 95140

如果我注释掉 dpotrf 行,那么它可以正常工作:

Eigen decomposition time: 8150
Eigen decomposition time: 8210
4

0 回答 0