Код: Выделить всё
// computes A * x + b
std::vector multiplyMatrixVector(const std::vector& A, const std::vector& x, const std::vector& b) {
int rows = A.size();
int cols = A[0].size();
// mkl_malloc to allocate aligned data
float* newA = (float*)mkl_malloc(rows * cols * sizeof(float), 64);
float* newX = (float*)mkl_malloc(cols * sizeof(float), 64); std::memcpy(newX, &x[0], cols * sizeof(float));
float* newB = (float*)mkl_malloc(rows * sizeof(float), 64); std::memcpy(newB, &b[0], rows * sizeof(float));
for (int i = 0; i < rows; ++i) {
std::memcpy(&newA[i * cols], &A[i][0], cols * sizeof(float));
}
cblas_sgemv(CblasRowMajor, CblasNoTrans, rows, cols, 1.0f, newA, cols, newX, 1, 1.0f, newB, 1);
std::vector result(newB, newB + rows);
mkl_free(newA);
mkl_free(newX);
mkl_free(newB);
return result;
}
Код: Выделить всё
std::vector A(N, std::vector(N, 1.0f));
std::vector x(N, 1.0f);
std::vector b(N, 0.5f);
std::vector result = multiplyMatrixVector(A, x, b);
[img]https://i.sstatic.net /19LKFci3.png[/img]
По-видимому, произошла ошибка при освобождении, поскольку ошибка исходит от mkl_serv_mkl_free, но я понятия не имею, что ее вызывает. Тот факт, что мой код работает до N = 128, говорит мне, что, вероятно, проблема не в моем коде, а в чем-то еще в моей системе. Для справки: у меня процессор Intel Core i5-2400, и я использую Windows 10. Кто-нибудь знает, что может быть причиной этого или что я могу попытаться сделать, чтобы это исправить?
Подробнее здесь: https://stackoverflow.com/questions/790 ... g-matrices