B:BD[
2.5487] → [
2.5487:6917]
// Loop over all processes
for (int proc = 0; proc < nprocs; ++proc) {
if (myproc == ioproc || myproc == proc) {
vector<CCTK_REAL> out_data;
if (proc == ioproc) {
// Optimize self-communication
swap(out_data, data);
} else {
if (myproc == ioproc) {
// Receive data
int npoints_out;
MPI_Recv(&npoints_out, 1, MPI_INT, proc, 0, comm, MPI_STATUS_IGNORE);
out_data.resize(npoints_out);
static_assert(is_same_v<CCTK_REAL, double>);
MPI_Recv(out_data.data(), npoints_out, MPI_DOUBLE, proc, 0, comm,
MPI_STATUS_IGNORE);
} else {
// Send data
assert(data.size() <= INT_MAX);
const int npoints = data.size();
MPI_Send(&npoints, 1, MPI_INT, ioproc, 0, comm);
static_assert(is_same_v<CCTK_REAL, double>);
MPI_Send(data.data(), npoints, MPI_DOUBLE, ioproc, 0, comm);
}
}
if (myproc == ioproc) {
// Output data
assert(out_data.size() % nvalues == 0);
size_t pos = 0;
while (pos < out_data.size()) {
file << cctkGH->cctk_iteration << sep << cctkGH->cctk_time;
for (int v = 0; v < 4; ++v)
file << sep << int(out_data.at(pos++));
for (int v = 4; v < nvalues; ++v)
file << sep << out_data.at(pos++);
file << "\n";
}
}
// Output data
for (const auto i : iptr) {
int pos = nvalues * i;
file << cctkGH->cctk_iteration << sep << cctkGH->cctk_time;
for (int v = 0; v < 4; ++v)
file << sep << int(all_data.at(pos++));
for (int v = 4; v < nvalues; ++v)
file << sep << all_data.at(pos++);
file << "\n";
assert(pos % nvalues == 0);