MPI_Get_address(&member, &offset[0]);
がoffset[0] = 0;
に置き換えられた場合、コードは以下のように出力されます。私の知る限りでは、MPI_BOTTOM
の絶対メモリアドレスが必要であり、そのためにMPI_Get_address()
が使用されています。構造体Member
はMPI_Get_address()
に問題ありませんが、構造体Family
は機能しませんでした。何が問題ですか?派生データ型のMPI_Sendのセグメンテーションフォルト
コマンド:
mpirun -n 2 ./out
出力:
Signal: Segmentation fault (11)
Signal code: (128)
Failing at address: (nil)
mpirun noticed that process rank 0...
コード:
#include <mpi.h>
struct Member
{
double height;
MPI_Datatype mpi_dtype;
Member() { make_layout(); }
void make_layout()
{
int nblock = 1;
int block_count[nblock] = {1};
MPI_Aint offset[nblock];
MPI_Get_address(&height, &offset[0]);
MPI_Datatype block_type[nblock] = {MPI_DOUBLE};
MPI_Type_create_struct(nblock, block_count, offset, block_type, &mpi_dtype);
MPI_Type_commit(&mpi_dtype);
}
};
struct Family
{
Member member;
MPI_Datatype mpi_dtype;
Family() { make_layout(); }
void make_layout()
{
int nblock = 1;
int block_count[nblock] = {1};
MPI_Aint offset[nblock];
MPI_Get_address(&member, &offset[0]);
//offset[0] = 0; <-- HERE!!!!!!!
MPI_Datatype block_type[nblock] = {member.mpi_dtype};
MPI_Type_create_struct(nblock, block_count, offset, block_type, &mpi_dtype);
MPI_Type_commit(&mpi_dtype);
}
};
int main()
{
int rank;
MPI_Init(NULL, NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
Family f;
MPI_Send(MPI_BOTTOM, 1, f.mpi_dtype, 1, 0, MPI_COMM_WORLD);
}
else if (rank == 1)
{
Family f;
MPI_Recv(MPI_BOTTOM, 1, f.mpi_dtype, 0, 0, MPI_COMM_WORLD, NULL);
}
MPI_Finalize();
return 0;
}
C++はCではなく、あなたのコードは*間違いなく* Cである。 –
代わりに、C++インターフェイス 'MPI :: Get_address(void *) 'を代わりに使用することを検討したことがありますか? –
@JohnBollinger C++バインディングは償却されていませんか? ([リンク](http://blogs.cisco.com/performance/the-mpi-c-bindings-what-happened-and-why))を参照してください。 – Shibli