Неправильная работа Bcast с массивом
Почему c числом Bcast работает как нужно:
int buf;
if (rnk == 0) {
buf = 777;
}
MPI_Barrier(MPI_COMM_WORLD);
cout << "Process " << rnk << " before Bcast: buf = " << buf << endl;
MPI_Bcast(&buf, 1, MPI_INT, 0, MPI_COMM_WORLD);
cout << "Process " << rnk << " after Bcast: buf = " << buf << endl;
а с массивом нет?
vector<int> p_flat;
p_flat.reserve(n * n);
if (rnk == 0) {
//в этом условии я забиваю созданный массив данными
vector<vector<int>> p(n,vector<int>(n));
int number = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
p[i][j] = ++number;
}
}
for (auto const &row : p)
copy(row.begin(), row.end(), back_inserter(p_flat));
}
MPI_Barrier(MPI_COMM_WORLD);
cout << "Process " << rnk << " before Bcast:" << endl;
for (auto x: p_flat) {
cout << x << " ";
}
cout << endl;
MPI_Bcast(&p_flat[0], n * n, MPI_INT, 0, MPI_COMM_WORLD);
cout << "Process " << rnk << " after Bcast:" << endl;
for (auto x: p_flat) {
cout << x << " ";
}
cout << endl;