【发布时间】:2020-03-27 16:26:34
【问题描述】:
我已经将我的代码中抛出的分段错误的问题缩小到与该行有关的问题
#pragma acc data copyout(result_mat[0:MAT1_X][0:MAT2_Y]), copyin(mat1[0:MAT1_X][0:MAT1_Y],mat2[0:MAT2_X][0:MAT2_Y])
在以下代码中:
// https://github.com/wrembish/MatMul_Parallel.git
#include <iostream>
#include <omp.h>
#include <cstdlib>
#include <ctime>
#include <chrono>
using namespace std;
using namespace std::chrono;
// constant variables for the desired size of matrix 1
const size_t MAT1_X = 835;
const size_t MAT1_Y = 835;
// constant variables for the desired size of matrix 2
const size_t MAT2_X = 835;
const size_t MAT2_Y = 835;
int main()
{
// take start time of whole program
auto prog_start = high_resolution_clock::now();
// seed rand for randomly filling the matrices
srand(time(NULL));
// define the matrices to the variables mat1 and mat2
int mat1[MAT1_X][MAT1_Y];
int mat2[MAT2_X][MAT2_Y];
// define the result matrix
int result_mat[MAT1_X][MAT2_Y];
// zero result matrix
#pragma acc loop
for(int unsigned i = 0; i < MAT1_X; i++)
{
for(int unsigned j = 0; j < MAT2_Y; j++)
{
result_mat[i][j] = 0;
}
}
// fill in mat1 with random positive integers <= 100
#pragma acc loop
for(int unsigned i = 0; i < MAT1_X; i++)
{
for(int unsigned j = 0; j < MAT1_Y; j++)
{
mat1[i][j] = (rand() % 100) + 1;
}
}
// fill in mat2 with random positive integers <= 100
#pragma acc loop
for(int unsigned i = 0; i < MAT2_X; i++)
{
for(int unsigned j = 0; j < MAT2_Y; j++)
{
mat2[i][j] = (rand() % 100) + 1;
}
}
// if the matrices can be multiplied, do it
if(MAT1_Y == MAT2_X)
{
//#pragma omp parallel for ordered schedule(auto) collapse(3)
#pragma acc data copyout(result_mat[0:MAT1_X][0:MAT2_Y]), copyin(mat1[0:MAT1_X][0:MAT1_Y],mat2[0:MAT2_X][0:MAT2_Y])
#pragma kernels
for(int unsigned i = 0; i < MAT1_X; i++)
{
//#pragma acc loop
for(int unsigned j = 0; j < MAT2_Y; j++)
{
//#pragma acc loop seq
for(int unsigned k = 0; k < MAT1_Y; k++)
{
result_mat[i][j] += mat1[i][k] * mat2[k][j];
}
}
}
} else
{
cout << "the dimensions of the two matrices don't allow multiplication" << endl;
}
// take end time of whole program
auto prog_stop = high_resolution_clock::now();
// get the difference in time between program start and finish
auto prog_duration = duration_cast<microseconds>(prog_stop - prog_start);
cout << "time taken(program): " << prog_duration.count() << " microseconds." << endl;
}
我在我的类虚拟机上使用 pgi/19.4,我正在编译和运行代码
pgc++ -ta=tesla -Minfo=accel matmul_acc.cpp
srun -p cisc372 --gres=gpu:1 ./a.out
并收到以下消息
srun: error: beowulf: task 0: Segmentation fault (core dumped)
我是 openacc 和 pgi 的新手,过去 3 小时我一直在互联网上寻找修复方法。如果有人知道我的代码有什么问题,我将不胜感激任何建议或修复。抱歉,如果已经有任何与此类似的问题,但我找不到任何适合我的问题。
【问题讨论】:
-
我看到的是,即使在没有 OpenACC 或使用 g++ 的情况下构建它也是核心转储,并且它几乎立即这样做。我认为这里发生了一些更根本的事情,但对我来说并不是很明显。您有适合您的参考版本吗?
标签: c++ parallel-processing segmentation-fault openacc