这是我之前的问题的延伸,但我是分开问的,因为我真的很沮丧,所以请不要低估它!
问题:与密集矩阵的相同cblas_sgemm调用相比,cblas_sgemm调用背后的原因可能是使用大量零的矩阵花费更少的时间?
我知道gemv是为矩阵向量乘法而设计的,但是为什么我不能使用gemm进行向量矩阵乘法,如果花费的时间更少,特别是对于稀疏矩阵
下面给出了简短的代表性代码.它要求输入一个值,然后使用该值填充向量.然后它用其索引替换每个第32个值.因此,如果我们输入'0',那么我们得到一个稀疏向量,但对于其他值,我们得到一个密集向量.
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <cblas.h>
using namespace std;
int main()
{
const int m = 5000;
timespec blas_start, blas_end;
long totalnsec; //total nano sec
double totalsec, totaltime;
int i, j;
float *A = new float[m]; // 1 x m
float *B = new float[m*m]; // m x m
float *C = new float[m]; // 1 x m
float input;
cout << "Enter a value to populate the …
Run Code Online (Sandbox Code Playgroud)