我使用MPI制作了一个集群应用程序。它使用主从设计计算一些问题。一切正常,但是当从属进程必须将其结果发送回主进程时,它会在MPI_Send中失败,并显示“地址未映射”。
这是处理从机和主机之间通信的代码。
void main_slave( int width, int height ) {
int transferSize = 6 + width * height;
int responseSize = 1 + width * height;
int* buffer = new int[transferSize];
int* response = new int[responseSize];
MPI_Status status;
while ( true ) {
MPI_Recv( buffer, transferSize, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &status );
if ( status.MPI_TAG == TAG_DONE ) break;
State state = deserialize_task( width, height, buffer );
task_solve( state );
response[0] = maximum;
serialize_board( best, &response[1] );
MPI_Send( response, responseSize, MPI_INT, 0, TAG_DONE, MPI_COMM_WORLD);
}
delete[] buffer;
delete[] response;
}
这是我失败时收到的错误输出。在其中,您可以看到由于某种原因,它在MPI_Send中就失败了。
[star:27344] *** Process received signal ***
[star:27344] Signal: Segmentation fault (11)
[star:27344] Signal code: Address not mapped (1)
[star:27344] Failing at address: 0x584f4f4fa0
[star:27344] [ 0] /usr/lib64/libpthread.so.0(+0xf5d0)[0x7f85705155d0]
[star:27344] [ 1] /usr/lib64/openmpi/mca_pml_ob1.so(mca_pml_ob1_send+0x68)[0x7f8565987d08]
[star:27344] [ 2] /usr/lib64/libmpi.so.40(PMPI_Send+0xf2)[0x7f85711e0792]
[star:27344] [ 3] run.exe[0x402977]
[star:27344] [ 4] run.exe[0x4035f0]
[star:27344] [ 5] /usr/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f857015b3d5]
[star:27344] [ 6] run.exe[0x4016c9]
[star:27344] *** End of error message ***