我正在实现一个应该运行主从算法的程序,主从作业将由执行参数决定。例如:
mpirun -oversubscribe -tag-output -np 1 BioNetFit2 -a load -c parabolaA_272002678.sconf : -oversubscribe -tag-output -np 4 BioNetFit2 -t particle -p 0 -a run -c parabolaA_272002678.sconf
在这种情况下,主服务器将运行以下部分:./BioNetFit2 -a load -c parabolaA_272002678.sconf
从机将执行这一部分:./BioNetFit2 -t particle -p 0 -a run -c parabolaA_272002678.sconf
这就是我初始化通信世界的方式:
cout << "Detected BNF2mpi in Pheromones init()" << endl;
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
cout << "Defined mpi environment" << endl;
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
cout << "My rank is " << world_rank << "and I have just started." << endl;我的问题是,主机发送一条消息,从机永远不会收到它,反之亦然。
所有的源代码都可以在这里找到:https://github.com/raqueldias/testing_rep这是一个很大的程序,它是由另一个人首先在boost-MPI中实现的,我的工作是将分布式消息传递函数从boost-MPI转换为MPI。
我的第一个非常基本的问题是:如果我将程序分成两部分运行,默认情况下进程是否能够正常通信,或者我必须指定任何不同的配置才能使它们通信?
发布于 2017-09-23 06:29:44
事实证明,进程挂起的问题与多个程序或多个实例的执行无关。
我误解了MPI_Iprobe的工作方式。这是我之前实现它的方式:
while (1) {
//std::cout << "rcv loop" << std::endl;
serializedMessage.resize(1000);
usleep(10000);
MPI_Status status;
int flag = 0;
while(!flag){
MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
}
if (flag) {
//receive code here
}} ...
这会使进程挂起。使程序正常工作的正确实现是:
while (1) {
//std::cout << "rcv loop" << std::endl;
serializedMessage.resize(1000);
usleep(10000);
MPI_Status status;
int flag = 0;
MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
if (flag==1) {
//do something here
}
}https://stackoverflow.com/questions/46373622
复制相似问题