为什么容器中的这个 C++ 容器无法使用 MPI_Recv 填充新值?

问题描述 投票:0回答:1

我已经实现了一个有效的 MPI 发送/接收,但我想更好地组织和提高性能,所以我采用 std::vector 和 std::map 并以块而不是单独发送数据。以下是我的工作代码和失败代码。

// working method (Individual send/recv)



// ... here the struct fvm::F is turned into an MPI datatype STRUCT_FACE to be used ...


// main rank 0

map<int, vector<fvm::F>> faces_buf;

// ... here faces_buf is initialized and the inside vectors are properly resized using vector.resize() ...


// the collection loop in main rank 0 (collects all faces from compute ranks 1, 2, 3, ...)
for(auto& fb : faces_buf){
   int compute_rank = fb.first;
   int n = 0;
   for(auto& f : fb.second){
      MPI_Recv(&f, 1, STRUCT_FACE, compute_rank, (n++ + 100000), MPI_COMM_WORLD, MPI_STATUS_IGNORE);
   }
}

// print results of collection
for(auto& fb : faces_buf){
    for(auto& f : fb.second){
        cerr << "f.T " << f.T << endl;
        if(f.T == 0.){
            goto done;
        }
    }
}
done:;




// compute ranks 1, 2, 3, ...

vector<fvm::F> faces;

// ... here faces vector is filled with values ...

for(auto& f : faces){
   MPI_Send(&f, 1, STRUCT_FACE, 0, (f.id + 100000), MPI_COMM_WORLD);
}


// Works as intended!


.

.

// failing method (Chunk send/recv)


// ... here the struct fvm::F is turned into an MPI datatype STRUCT_FACE to be used ...


// main rank 0

map<int, vector<fvm::F>> faces_buf;

// ... here faces_buf is initialized and the inside vectors are properly resized using vector.resize() ...

// the collection loop in main rank 0 (collects all faces from compute ranks 1, 2, 3, ...)
for(auto& fb : faces_buf){
   int compute_rank = fb.first;
   MPI_Recv(fb.second.data(), fb.second.size(), STRUCT_FACE, compute_rank, (compute_rank + 100000), MPI_COMM_WORLD, MPI_STATUS_IGNORE);
}

// print results of collection
for(auto& fb : faces_buf){
    for(auto& f : fb.second){
        cerr << "f.T " << f.T << endl;
        if(f.T == 0.){
            goto done;
        }
    }
}
done:;



// compute ranks 1, 2, 3, ...

vector<fvm::F> faces;

// ... here faces vector is filled with values ...

MPI_Isend(faces.data(), faces.size(), STRUCT_FACE, 0, (rank + 100000), MPI_COMM_WORLD, &reqf);
int flagf = 0;
while(true){
   MPI_Test(&reqf, &flagf, MPI_STATUS_IGNORE);
   if(flagf){
      break;
   }
}

// Fails to recv new fvm::F values

工作方式的输出:

f.T 298.15
f.T 298.15
f.T 298.15
f.T 298.15
f.T 298.15
...
...
...

失败方法的输出:

f.T 298.15
f.T 298.15
f.T 298.15
f.T 8.48798e-315
f.T 0

为什么第二种方法会失败,而第一种方法会成功?

c++ mpi
1个回答
0
投票

我的 fvm::F 结构具有比 MPI_Datatype STRUCT_FACE 更多的属性。

© www.soinside.com 2019 - 2024. All rights reserved.