debug OpenBLAS library 和 应用示例

1. 构建openblas lib

git clone [email protected]:OpenMathLib/OpenBLAS.git

cd OpenBLAS/
如果要安装在自定义文件夹中,可以修改 PREFIX 的定义:

PREFIX = /opt/OpenBLAS
修改成
PREFIX = ../local/

然后构建:
make -j
make install

如果要构建 debug 版本的openblas,则可以在  Makefile.rule中,修改如下 大约在244行:


# Build Debug version
# DEBUG = 1
修改为
# Build Debug version
DEBUG = 1

debug OpenBLAS library 和 应用示例_第1张图片

然后在执行构建指令:
make -j
make install

2. 调试openblas 示例


2.1 示例1,LU分解

//hello_LAPACK_sgetrf.c

//#include 
#include 
#include 

int main() {
    int n = 3; // Dimension of the matrix
    float A[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 10.0}; // Input matrix
    int lda = n; // Leading dimension of A
    int ipiv[n]; // Array to store pivot indices
    int info; // Output variable for error info

    // Call the LAPACK sgetrf function for LU decomposition
    sgetrf_(&n, &n, A, &lda, ipiv, &info);

    if (info == 0) {
        printf("LU decomposition successful!\n");
        // Print the decomposed matrix A
        printf("Decomposed matrix A:\n");
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                printf("%f ", A[i + j*n]);
            }
            printf("\n");
        }
        printf("ipiv=\n");
        for(int i=0; i

运行效果及matlab验证:

debug OpenBLAS library 和 应用示例_第2张图片

2.2 示例2 QR分解

hello_qrf.c
#include 
#include 

int min(int m, int n){  return m

运行效果及 matlab 验证:

debug OpenBLAS library 和 应用示例_第3张图片

Makefile:

INC =  -I ../local/include
#LD_FLAGS = -L../local/lib -lopenblas
#LD_FLAGS = /home/hipper/ex_openblas/tmp_/local/lib/libopenblas_skylakexp-r0.3.26.dev.so
EXE := hello_LAPACK_sgetrf hello_qrf

all: $(EXE)

hello_qrf: hello_qrf.o
hello_LAPACK_sgetrf: hello_LAPACK_sgetrf.o

%.o: %.c
        gcc -g $< -c -o $@ $(INC)

%: %.o /home/hipper/ex_openblas/tmp_/local/lib/libopenblas_skylakexp-r0.3.26.dev.a
        gcc -g $^    -o $@ $(LD_FLAGS) -lm -lgfortran

#$(LD_FLAGS)

.PHONY: clean
clean:
        -rm -rf $(EXE) *.o

调试效果:

debug OpenBLAS library 和 应用示例_第4张图片


这里使用的是静态库
也可以使用动态库

你可能感兴趣的:(并行计算,hpc)