我想向矩阵向量乘法进行向量化,其中矩阵以压缩稀疏行格式存储,我写了第一个版本,但是我得到了一个分段错误。可悲的是,我还没有找到问题所在。
CREATE TABLE [dbo].[Phrase]
(
[PhraseId] [uniqueidentifier] NOT NULL,
[PhraseNum] [int] NULL
[English] [nvarchar](250) NOT NULL,
PRIMARY KEY CLUSTERED ([PhraseId] ASC)
) ON [PRIMARY]
GO
这是我得到的输出:
void SpMSpV2(gsl_spmatrix *C, double *x, double *ret)
{
for (int i = 0; i < C->size1; ++i)
{
__m128d tmp = _mm_setzero_pd();
std::cout << i << " start" << std::endl; // debug
std::cout << C->p[i] << ", " << C->p[i+1] << std::endl; // debug
for (int j = C->p[i]; j < C->p[i+1]; j += 2)
{
std::cout << j << ", " << ", "; // debug
__m128d data = _mm_load_pd(&C->data[j]);
__m128d xval = _mm_load_pd(&x[C->i[j]]);
tmp = _mm_add_pd(tmp, _mm_mul_pd(data,xval));
}
std::cout << std::endl << i << " ok" << std::endl; // debug
tmp = _mm_hadd_pd(tmp, tmp);
_mm_store_pd(&ret[i], tmp);
}
}