发送数组时MPI_Recv中发生错误
有人能解释我为什么会犯这个错误吗 正如您在代码中看到的,有一个for循环,其中包含一个被注释的print语句。奇怪的是。。。取消对该循环的注释后。工作正常。想法:发送数组时MPI_Recv中发生错误,c,parallel-processing,mpi,openmpi,C,Parallel Processing,Mpi,Openmpi,有人能解释我为什么会犯这个错误吗 正如您在代码中看到的,有一个for循环,其中包含一个被注释的print语句。奇怪的是。。。取消对该循环的注释后。工作正常。想法: MPI_Init应该是程序中的第一件事 只有一个等级应scanf N不会跨列通信,因此您正在分配未定义大小的内存 定义尽可能接近其使用点的变量。把inti放在函数的顶端是一场即将发生的灾难 末端的屏障是不必要的 所有列组都需要分配自己的内存 这让我们了解了以下代码: #包括 #包括 #包括“mpi.h” int main(int ar
MPI_Init
应该是程序中的第一件事scanf
N
不会跨列通信,因此您正在分配未定义大小的内存inti
放在函数的顶端是一场即将发生的灾难#包括
#包括
#包括“mpi.h”
int main(int argc,字符**argv){
MPI_Init(&argc,&argv);
const int tag=99;
常数int tag1=100;
int等级、大小;
MPI_通信大小(MPI_通信世界和大小);
MPI通信等级(MPI通信世界和等级);
double*a;//指向我们将分配的内存的指针
int N;
如果(秩==0){
scanf(“%d”和“&N”);
a=(双*)malloc(N*sizeof(双));
for(int j=0;j感谢您提供一个最低限度的工作示例!
#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
int main(int argc, char **argv)
{
int N;
scanf("%d", &N);
double *a = (double *)malloc(N * sizeof(double));
int i, rank, size, tag = 99, tag1 = 100;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
for(int j=0;j<N;++j)
{
a[j] = j+0.1;
}
for (i = 1; i < size; i++)
{
MPI_Send(&N, 1, MPI_INT, i, tag1, MPI_COMM_WORLD);
MPI_Send(a, N, MPI_DOUBLE, i, tag, MPI_COMM_WORLD);
}
}
else
{
MPI_Recv(&N, 1, MPI_INT, 0, tag1, MPI_COMM_WORLD, &status);
MPI_Recv(a, N, MPI_DOUBLE, 0, tag, MPI_COMM_WORLD, &status);
// for(int j=0;j<N*2;++j)
// printf("%d %f\n", rank, a[j]);
}
MPI_Barrier(MPI_COMM_WORLD);
printf("Message from process %d : %f\n", rank, a[rank]);
MPI_Finalize();
return 0;
}
[nikhil:8599] *** An error occurred in MPI_Recv
[nikhil:8599] *** reported by process [4228579329,1]
[nikhil:8599] *** on communicator MPI_COMM_WORLD
[nikhil:8599] *** MPI_ERR_BUFFER: invalid buffer pointer
[nikhil:8599] *** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
[nikhil:8599] *** and potentially your MPI job)
[nikhil:08593] 2 more processes have sent help message help-mpi-errors.txt / mpi_errors_are_fatal
[nikhil:08593] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages