问题描述
#include <stdio.h>
#include <mpi.h>
#include
#include <time.h>
#include <math.h>
#define size 1000
float a[size][size];
float sum[size];
void norm(int istart, int iend)
{
int i,j;
for ( i = istart; i <= iend; ++i) {
for (j = 0; j < size; ++j) {
sum[i]=sum[i]+a[i][j];
}
}
}
int main(int argc, char* argv[])
{
int rank, nproc,i,j;
int istart, iend;
float t_1;
clock_t c_1,c_2;
c_1=time(NULL); // time measure: start mm
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
// Initialize buffers.
for ( i = 0; i < size; ++i) {
for (j = 0; j < size; ++j) {
a[i][j] = (float)i + j;
}
sum[i]=0;
}
}
MPI_Bcast(a, size*size, MPI_FLOAT, 0,MPI_COMM_WORLD);
istart = (size / nproc) * rank;
iend = (size / nproc) * (rank + 1) - 1;
norm(istart, iend);
MPI_Gather(sum+ (size/nproc*rank),
size*size/nproc,
MPI_FLOAT,
sum + (size/nproc*rank),
size*size/nproc,
MPI_FLOAT,
0,
MPI_COMM_WORLD);
if (rank == 0) {
if (size % nproc > 0) {
norm((size/nproc)*nproc, size-1);
}
}
MPI_Finalize();
c_2=time(NULL);
t_1 = (float)(c_2-c_1);
printf("Execution time: %f \n",t_1);
return 0;
}
我的尝试:
PMPI_Gather中的致命错误:无效的缓冲区指针,错误堆栈:
PMPI_Gather(856):MPI_Gather(sbuf = 0x6010a0,scount = 1000000,MPI_FLOAT,rbuf = 0x6010a0,rcount = 1000000 ,MPI_FLOAT,root = 0,MPI_COMM_WORLD)失败
PMPI_Gather(797):缓冲区一定不能别名
计算norm1和数学上的无限规范
它运行....
但是当它运行时告诉我这个错误
这个错误是什么意思
请帮助
What I have tried:
Fatal error in PMPI_Gather: Invalid buffer pointer, error stack:
PMPI_Gather(856): MPI_Gather(sbuf=0x6010a0, scount=1000000, MPI_FLOAT, rbuf=0x6010a0, rcount=1000000, MPI_FLOAT, root=0, MPI_COMM_WORLD) failed
PMPI_Gather(797): Buffers must not be aliased
it program to compute norm1 and infinite norm in mathmatical
it run ....
but when it get run show me this error
what means of this error
please help
推荐答案
缓冲区不得使用别名
告诉您已使用相同的缓冲区进行发送和接收,这在必须提供接收缓冲区时是不允许的。您必须使用单独的缓冲区或 MPI_IN_PLACE
选项。
另请参阅 []。
tells you that you have used the same buffer for sending and receiving which is not allowed when the receive buffer must be supplied. You must use separate buffers or the MPI_IN_PLACE
option.
See also MPI_Gather(3) man page (version 1.8.8)[^].
这篇关于我该如何解决这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!