3
MPI中发生了一些奇怪的事情,我不太明白。我有以下简单的代码:MPI中的C++双类型
MPI_Init(&argc, &argv);
int rank;
int size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (rank == 0) {
double ridiculous = 7.9;
printf("Process 0 will be sending number %d\n", ridiculous);
MPI_Send(&ridiculous, 1, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD);
printf("Process 0 sent number %d\n", ridiculous);
}
else {
double received = 0.;
MPI_Recv(&received, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
printf("Process 1 received number %d from process 0\n", received);
}
MPI_Finalize();
我期待这样的输出:
Process 0 will be sending number 7.9
Process 0 sent number 7.9
Process 1 received number 7.9 from process 0
但奇怪的是收到此:
Process 0 will be sending number 1112261192
Process 0 sent number -32766
Process 1 received number -32766 from process 0
我没那么擅长此道MPI的东西,但它看起来像我双面类型出了问题。因为如果我将“double”更改为“int”,我会得到预期输出:
Process 0 will be sending number 7
Process 0 sent number 7
Process 1 received number 7 from process 0
有什么建议吗?
不行!多么荒谬的错误!我应该在晚上停止编码:D谢谢! – picusiaubas