• openblas下载安装与使用


    openblas下载

    openblas安装

    直接执行

    git clone https://github.com/xianyi/OpenBLAS.git
    cd OpenBLAS
    make
    make PREFIX=/path/to/your/installation install
    

    openblas使用

    将相应的头文件及库文件考到相应的位置

    cp ~/software/openblas/include/* ./include/
    cp ~/software/openblas/lib/libopenblas.a ./lib/
    

    cmake文件如下:

    cmake_minimum_required (VERSION 2.6)
    project (TEST)
    
    set (TEST_VERSION 0.1)
     
    set(CMAKE_BUILD_TYPE "Debug")
    set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb -DDEBUG")
    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
      
    set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin)
    
    aux_source_directory(${PROJECT_SOURCE_DIR}/src DIR_SRC)
     
    include_directories(${PROJECT_SOURCE_DIR}/src)
    
    include_directories(${PROJECT_SOURCE_DIR}/include)
    
    link_directories(${PROJECT_SOURCE_DIR}/lib)
    add_executable(main ${DIR_SRC})
    
    target_link_libraries(main libopenblas.a)
    target_link_libraries(main -lm)
    target_link_libraries(main -lpthread)
    

    注意最后多连接了两个库:

    target_link_libraries(main -lm)
    target_link_libraries(main -lpthread)
    

    测试程序如下:

    #include <cblas.h>
    #include <stdio.h>
    
    void main() {
    
        int i = 0;
        double A[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};         
        double B[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};  
        double C[9] = {.5,.5,.5,.5,.5,.5,.5,.5,.5}; 
    
        int M = 3; // row of A and C
        int N = 3; // col of B and C
        int K = 2; // col of A and row of B
    
        double alpha = 1.0;
        double beta = 0.0;
    
        cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, M, N, K, alpha, A, K, B, N, beta, C, N);
    
        for (i = 0; i < 9; i++) {
            printf("%lf ", C[i]);
        }
        printf("
    ");
    }
    

    保存为main.c,放在文件夹src中,执行

    mkdir build
    cd build
    cmake ..
    make
    

    生成执行文件在文件夹bin中。

    接口说明

    /usr/bin/ld: 找不到 -lopenblas
    

    则要在openblas的lib文件夹中找到libopenblas.a执行

    sudo cp ./lib/libopenblas.a /usr/local/lib/
    
  • 相关阅读:
    [CF 803G]- Periodic RMQ Problem 动态开点线段树 或 离线
    [2018CCPC吉林赛区(重现赛)- 感谢北华大学] 补题记录 躁起来
    【EDU68 E】 Count The Rectangles 数据结构算几何
    【HDU5409】CRB and Graph 边双联通 子树最值
    【CF1137C】 Museums Tour 拆点+缩点
    【HDU6035】 Colorful Tree
    【Edu 67】 补题记录
    五月月赛 寻宝 exkmp + 主席树
    ZOJ
    CF 551 D.Serval and Rooted Tree 树形DP
  • 原文地址:https://www.cnblogs.com/qujingtongxiao/p/10197784.html
Copyright © 2020-2023  润新知