这是我的第一个问题:)
我想它并没有达到应有的水平,但这是我正在努力的目标,很高兴得到某人对此的看法。
我目前正在基于 Linux 的环境中使用 LAPACK ,对此我感到非常困惑。我正在尝试使用 C++ ,但我也可以使用和Python 进行编码。首先,我没有HPC的权限,我正在连接到学校的服务器,因此在软件方面我没有足够的灵活性。
我可以编写和编译任何其他需要非常基本的包含内容的C++代码,例如字符串等。但是,我找不到能够包含必要的内容或与LAPACK项目链接的方法。
例如:
Understanding LAPACK calls in C++ with a simple example
//LAPACK test code
//compile with: g++ main.cpp -llapack -lblas -o testprog
#include <iostream>
#include <vector>
using namespace std;
extern "C" void dgetrf_(int* dim1, int* dim2, double* a, int* lda, int* ipiv, int* info);
extern "C" void dgetrs_(char *TRANS, int *N, int *NRHS, double *A, int *LDA, int *IPIV, double *B, int *LDB, int *INFO );
int main()
{
char trans = 'N';
int dim = 2;
int nrhs = 1;
int LDA = dim;
int LDB = dim;
int info;
vector<double> a, b;
a.push_back(1);
a.push_back(1);
a.push_back(1);
a.push_back(-1);
b.push_back(2);
b.push_back(0);
int ipiv[3];
dgetrf_(&dim, &dim, &*a.begin(), &LDA, ipiv, &info);
dgetrs_(&trans, &dim, &nrhs, & *a.begin(), &LDA, ipiv, & *b.begin(), &LDB, &info);
std::cout << "solution is:";
std::cout << "[" << b[0] << ", " << b[1] << ", " << "]" << std::endl;
std::cout << "Info = " << info << std::endl;
return(0);
}
这个论点与我要解决的问题非常接近,即使用LAPACK解决基本系统。当我尝试使用该代码时,这是我面临的错误:
g++ main.cpp -llapack -lblas -o testprog
/cta/capps/lapack/3.9.0/lib/../lib/liblapack.a(xerbla.f.o): In function `xerbla_':
xerbla.f:(.text+0x49): undefined reference to `_gfortran_st_write'
xerbla.f:(.text+0x54): undefined reference to `_gfortran_string_len_trim'
xerbla.f:(.text+0x69): undefined reference to `_gfortran_transfer_character_write'
xerbla.f:(.text+0x79): undefined reference to `_gfortran_transfer_integer_write'
xerbla.f:(.text+0x81): undefined reference to `_gfortran_st_write_done'
xerbla.f:(.text+0x8a): undefined reference to `_gfortran_stop_string'
collect2: error: ld returned 1 exit status
我确实需要一些建议或资源来理解LAPACK背后的逻辑并将其与C++链接。
提前致谢...
最佳答案
LAPACK用fortran编写。链接错误表明您的LAPACK版本是使用gfortran编译的,它具有一个帮助程序(运行时)库。要扩展其他注释,您需要链接此运行时库以提供缺少的功能。尝试将-lgfortran添加到链接行中(在-lblas之后),但在-o之前。希望有帮助。
关于c++ - 使用C++在基于LINUX的环境中使用LAPACK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61087894/