0

我运行一个每个进程都进入的函数。进行了一些计算,然后所有进程退出该函数,但只有等级为 0 的进程返回一些东西。问题是在 return 语句中,值是正确的,但在 main 中,我分配函数的结果,返回值为 0。这里有一些代码:

MPI_Barrier(MPI_COMM_WORLD);
CCI = TestKNN (tlist, data, true, mode, false, false);      
MPI_Barrier(MPI_COMM_WORLD);

…………

TestKNN(....)
{
    int res; 
    if (rank == 0)
    {
          res = 0;
          send data to each process and receive result
          receive result from every process
          res += return_value
    }
    else
    {
         receive data
         work on data
         send result to rank 0
    }

    if (rank == 0)
         return res
 }

可能是什么问题呢?

4

0 回答 0