I am trying to use the LAPACK_sgesv function from the MKL to solve a linear system, which is part of a much larger problem. Now, as an example, this produces the correct answer:
int size = 4 float a[16] = {1, 1, 1 , 1, -2, -1, 1, 2, 4, 1, 1, 4, -8, -1, 1, 8}; // matrix A of Ax = B float b[4] = { 0, 1, 0, 0 }; // vector B of Ax = B int p[4] = { 0, 0, 0, 0 }; // array to store pivot indices LAPACKE_sgesv(LAPACK_ROW_MAJOR, size, 1, a, size, p, b, 1); for (auto& element : b) std::cout << "\n"<< element;
The output is correct, and this behaves without errors. However, the main problem I have is that this function does not seem to work nicely with std::vectors:
int size = 4 std::vector<float> A = { 1, 1, 1, 1, -2, -1, 1, 2, 4, 1, 1, 4, -8, -1, 1, 8 }; std::vector<float> B = { 0, 1, 0, 0 }; std::vector<int> P = { 0, 0, 0, 0 }; LAPACKE_sgesv(LAPACK_ROW_MAJOR, size, 1, &A[0], size, &P[0], &B[0], 1); for (auto& element : b) std::cout << "\n"<< element;
The output I get is simply 0, 1, 0, 0, which is the unmodified output vector which the answer is suppose to be written to. The LAPACK returns zero, suggesting it executed successfully... Any ideas as to how to get it to work with vector? In my real use of this function in a larger calculation, I need to use resizeable contiguous containers, not arrays.
Thread Topic:
Help Me