Skip to content

Commit

Permalink
Avoid needless allocation.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Nov 20, 2024
1 parent ee016d2 commit 404da68
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/nrnpython/nrnpy_p2h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,25 +930,24 @@ static Object* py_alltoall_type(int size, int type) {
} else { // scatter

// destination counts
rcnt = new int[1];
nrnmpi_int_scatter(scnt.data(), rcnt, 1, root);
std::vector<char> r(rcnt[0] + 1); // rcnt[0] can be 0
int rcnt = -1;
nrnmpi_int_scatter(scnt.data(), &rcnt, 1, root);
std::vector<char> r(rcnt + 1); // rcnt can be 0

// exchange
if (nrnmpi_myid == root) {
sdispl = mk_displ(scnt.data());
}
nrnmpi_char_scatterv(s.data(), scnt.data(), sdispl, r.data(), rcnt[0], root);
nrnmpi_char_scatterv(s.data(), scnt.data(), sdispl, r.data(), rcnt, root);
if (sdispl)
delete[] sdispl;

if (rcnt[0]) {
if (rcnt) {
pdest = unpickle(r);
} else {
pdest = nb::none();
}

delete[] rcnt;
assert(rdispl == NULL);
}
}
Expand Down

0 comments on commit 404da68

Please sign in to comment.