【发布时间】:2016-10-09 07:08:59
【问题描述】:
我正在尝试使用 MPI 创建一些服务器,我可以编译它,但是当我运行它时,它会立即出现段错误。我尝试添加打印语句以查看它在哪里崩溃,但这无济于事。我是使用 MPI 的新手,我找不到问题所在。我使用的是 Mac,我正在尝试找出 llvm,因为我无法使用 GDB 检查核心转储,因此非常感谢您在此期间提供的任何帮助。
#include "mpi.h"
#include <iostream>
#include <list>
using namespace std;
void error(const char *msg)
{
perror(msg);
exit(1);
}
int main( int argc, char **argv )
{
int MAX_DATA = 255;
MPI_Comm client;
MPI_Status status;
char port_name[MPI_MAX_PORT_NAME];
int size, again;
double buf[MAX_DATA];
cout << "Did we get here? [1]";
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &size);
cout << "Did we get here before it pukes";
if (size != 1) error("ERROR");
// Create the random list
list<int> rand_list;
list<int>::iterator it;
for(int i = 0; i < 5; ++i)
{
int r;
r = rand();
rand_list.insert (it,r);
it++;
}
cout << "mylist contains:";
for (it=rand_list.begin(); it!=rand_list.end(); ++it)
{
cout << ' ' << *it;
cout << '\n';
}
MPI_Open_port(MPI_INFO_NULL, port_name);
printf("server available at %s\n",port_name);
while (1) {
MPI_Comm_accept( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &client);
again = 1;
while (again) {
MPI_Recv( buf, MAX_DATA, MPI_DOUBLE,
MPI_ANY_SOURCE, MPI_ANY_TAG, client, &status );
switch (status.MPI_TAG) {
case 0: MPI_Comm_free( &client );
MPI_Close_port(port_name);
MPI_Finalize();
return 0;
case 1: MPI_Comm_disconnect( &client );
again = 0;
break;
case 2: /* do something */
cout << "Why did we get here?";
default:
/* Unexpected message type */
MPI_Abort( MPI_COMM_WORLD, 1 );
}
}
}
}
[asdfa:04443] *** Process received signal ***
[asdfa:04443] Signal: Segmentation fault: 11 (11)
[asdfa:04443] Signal code: Address not mapped (1)
[asdfa:04443] Failing at address: 0x0
[asdfa:04443] [ 0] 0 libsystem_platform.dylib 0x00007fff8ed1452a _sigtramp + 26
[asdfa:04443] [ 1] 0 ??? 0x0000000000000001 0x0 + 1
[asdfa:04443] [ 2] 0 server.o 0x000000010a40eba2 main + 834
[asdfa:04443] [ 3] 0 libdyld.dylib 0x00007fff9cb245ad start + 1
[asdfa:04443] *** End of error message ***
Segmentation fault: 11 (core dumped)
【问题讨论】:
-
你可以添加你用来编译和运行的命令......
-
这里,在 linux 和 gcc 下,第一次调用
rand_list.insert(it,r);失败 -
为什么不能使用
gdb来检查核心转储?
标签: c++ segmentation-fault mpi