【问题标题】:MPI communication running multiple executables运行多个可执行文件的 MPI 通信
【发布时间】:2018-03-04 13:24:40
【问题描述】:

我正在实现一个应该运行主从算法的程序,主从作业将由执行参数决定。 例如:

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

在这种情况下,master 将运行这部分:./BioNetFit2 -a load -c parabolaA_272002678.sconf

而slave会执行这部分:./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;

我的问题是master发送了一条消息,slave从来没有收到,反之亦然。

所有源代码都在这里:https://github.com/raqueldias/testing_rep 这是一个大程序,是别人在boost-MPI中实现的,我的工作是将分布式消息传递功能从boost-MPI转换为MPI。

我的第一个非常基本的问题是:如果我像这样分两部分运行程序,默认情况下进程是否能够正常通信,或者我必须指定任何不同的配置才能使它们通信?

【问题讨论】:

  • 请在问题中发布发送/接收部分。目前尚不清楚它的原因是什么。放更多代码以便我们检查。
  • 刚刚上传了整个源代码。

标签: c++ mpi


【解决方案1】:

原来这个进程挂起的问题与mpirun执行中多个程序或多个实例的执行无关。

我误解了 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
    }

}

【讨论】:

    猜你喜欢
    • 2019-11-26
    • 2017-05-12
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 2016-06-17
    • 2023-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多