我希望以下代码能够产生.f
但它会产生1,0,2,0
。为什么不填充收到的数据?
1,2,0,0
但是,如果我将接收部件更改为
// tmp.cpp
#include <iostream>
#include <mpi.h>
int main( int argc, char* argv[] )
{
MPI_Init( &argc, &argv );
int rk;
MPI_Comm_rank( MPI_COMM_WORLD, &rk );
if ( rk == 0 )
{
double b[2] = {1.0, 2.0};
MPI_Send( b, 2, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD );
}
if ( rk == 1 )
{
double b[4] = {0.0, 0.0, 0.0, 0.0};
MPI_Datatype padded;
MPI_Type_vector( 1, 1, 2, MPI_DOUBLE, &padded );
MPI_Type_commit( &padded );
MPI_Recv( b, 2, padded, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE );
std::cout << b[0] << ',' << b[1] << ','
<< b[2] << ',' << b[3] << '\n';
MPI_Type_free( &padded );
}
MPI_Finalize();
return 0;
}
它产生 MPI_Datatype padded;
MPI_Type_vector( 2, 1, 2, MPI_DOUBLE, &padded );
MPI_Type_commit( &padded );
MPI_Recv( b, 1, padded, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE );
。
MPI:OpenMPI 3.1.2
海湾合作委员会:7.2.1
内部版本:1,0,2,0
运行:mpicxx tmp.cpp