Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Parallel processing OpenMP线程的OpenBlas并行化_Parallel Processing_Nested_Openmp_Lapack_Openblas - Fatal编程技术网

Parallel processing OpenMP线程的OpenBlas并行化

Parallel processing OpenMP线程的OpenBlas并行化,parallel-processing,nested,openmp,lapack,openblas,Parallel Processing,Nested,Openmp,Lapack,Openblas,我试图从OpenMP线程调用OpenBlas函数,而Blas并行化设置为不等于1的值。我正在使用OpenBlas 0.3.9,在下载源代码后,我解开了它并调用了它 使用OPENMP=1 makeprefix=/someFolder/install 但是,我总是从我的可执行文件中收到以下错误消息 OpenBLAS警告:检测OpenMP循环,此应用程序可能挂起。请使用“使用OPENMP=1”选项重建库 有人知道为什么会这样吗?我怎样才能改变它?下面是我的代码的一个简单示例: #include <

我试图从OpenMP线程调用OpenBlas函数,而Blas并行化设置为不等于1的值。我正在使用OpenBlas 0.3.9,在下载源代码后,我解开了它并调用了它

使用OPENMP=1

makeprefix=/someFolder/install

但是,我总是从我的可执行文件中收到以下错误消息

OpenBLAS警告:检测OpenMP循环,此应用程序可能挂起。请使用“使用OPENMP=1”选项重建库

有人知道为什么会这样吗?我怎样才能改变它?下面是我的代码的一个简单示例:

#include <complex>
#include <vector>
#include <random>
#include <iostream>
#include <algorithm>
#include <omp.h>
#include <cblas.h>
#include <lapacke.h>

int main(int, char**) {
    int const blas_threads = 2,
              omp_threads = 2,
              matrix_size = 100;
    openblas_set_num_threads(blas_threads);
    omp_set_max_active_levels(2);

    double alpha = 1.,
           beta = 0.;

    std::vector<std::vector<double>> as(omp_threads,
                                        std::vector<double>(matrix_size*matrix_size));
    std::vector<std::vector<double>> bs(omp_threads,
                                        std::vector<double>(matrix_size*matrix_size));
    std::vector<std::vector<double>> cs(omp_threads,
                                        std::vector<double>(matrix_size*matrix_size));

    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_real_distribution<double> dis;
    for(int i = 0; i < omp_threads; ++i) {
        std::generate(as[i].begin(),
                      as[i].end(), 
                      [&dis,&gen]() { return dis(gen); });
        std::generate(bs[i].begin(),
                      bs[i].end(), 
                      [&dis,&gen]() { return dis(gen); });
    }

    // for(int i = 0; i < matrix_size*matrix_size; ++i) {
    //  std::cout << as[0][i] << " " << bs[0][i] << std::endl;
    // } 

#pragma omp parallel for num_threads(omp_threads), schedule(static, 1)
    for(int i = 0; i < omp_threads; ++i) {
        cblas_dgemm(CblasColMajor,
                    CblasNoTrans,
                    CblasNoTrans,
                    matrix_size,
                    matrix_size,
                    matrix_size,
                    alpha,
                    as[i].data(),
                    matrix_size,
                    bs[i].data(),
                    matrix_size,
                    beta,
                    cs[i].data(),
                    matrix_size);
    }

    // for(int i = 0; i < matrix_size*matrix_size; ++i) {
    //  std::cout << cs[0][i] << std::endl;
    // } 

    return 0;
}

#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
int main(int,char**){
int const blas_threads=2,
omp_螺纹=2,
矩阵_大小=100;
openblas_设置_num_线程(blas_线程);
omp\u设置\u最大\u活动\u级别(2);
双α=1。,
β=0。;
标准::向量as(omp_线程,
向量(矩阵大小*矩阵大小);
标准::矢量bs(omp_线程,
向量(矩阵大小*矩阵大小);
标准::向量cs(omp_线程,
向量(矩阵大小*矩阵大小);
std::随机_装置rd;
标准:mt19937 gen(rd());
标准:均匀实分布图;
对于(int i=0;i//std::cout OpenBlas在
cblas_dgemm
中已经使用OpenMP。在调用函数的循环中使用
#pragma omp parallel
可能会导致显著的速度减慢,并且由于嵌套的
parallel for
可能会出现类似的问题。有关与OpenMP中嵌套并行性相关的问题。尽管我理解您对我的代码质量的担忧,但这不是我要问的问题。显然,这是可能的,因为存在这样做的标志。