From fe7c359da5e3a56f729e3d8eeca09f7883501117 Mon Sep 17 00:00:00 2001 From: "Alex R. Long" Date: Mon, 4 Nov 2024 08:55:25 -0700 Subject: [PATCH] Try to fix MPI error + Call resize portion even if no particles in buffer (like old behavior) --- src/interface/swarm_comms.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/interface/swarm_comms.cpp b/src/interface/swarm_comms.cpp index 7b236b6e4e1f2..d216fd2f16e29 100644 --- a/src/interface/swarm_comms.cpp +++ b/src/interface/swarm_comms.cpp @@ -178,6 +178,13 @@ void Swarm::LoadBuffers_() { auto &y = Get(swarm_position::y::name()).Get(); auto &z = Get(swarm_position::z::name()).Get(); + // Zero out number of particles to send before accumulating + pmb->par_for( + PARTHENON_AUTO_LABEL, 0, NMAX_NEIGHBORS - 1, KOKKOS_LAMBDA(const int n) { + num_particles_to_send[n] = 0; + buffer_start[n] = 0; + }); + if (max_active_index_ >= 0) { auto &buffer_sorted = buffer_sorted_; auto &buffer_start = buffer_start_; @@ -201,12 +208,6 @@ void Swarm::LoadBuffers_() { auto &num_particles_to_send = num_particles_to_send_; auto max_active_index = max_active_index_; - // Zero out number of particles to send before accumulating - pmb->par_for( - PARTHENON_AUTO_LABEL, 0, NMAX_NEIGHBORS - 1, KOKKOS_LAMBDA(const int n) { - num_particles_to_send[n] = 0; - buffer_start[n] = 0; - }); pmb->par_for( PARTHENON_AUTO_LABEL, 0, max_active_index_, KOKKOS_LAMBDA(const int n) { @@ -228,19 +229,21 @@ void Swarm::LoadBuffers_() { // copy values back to host for buffer sizing auto num_particles_to_send_h = num_particles_to_send_.GetHostMirrorAndCopy(); auto buffer_start_h = buffer_start.GetHostMirrorAndCopy(); + } - // Resize send buffers if too small - for (int n = 0; n < pmb->neighbors.size(); n++) { - num_particles_to_send_h(n) -= buffer_start_h(n); - const int bufid = pmb->neighbors[n].bufid; - auto sendbuf = vbswarm->bd_var_.send[bufid]; - if (sendbuf.extent(0) < num_particles_to_send_h(n) * particle_size) { - sendbuf = BufArray1D("Buffer", num_particles_to_send_h(n) * particle_size); - vbswarm->bd_var_.send[bufid] = sendbuf; - } - vbswarm->send_size[bufid] = num_particles_to_send_h(n) * particle_size; + // Resize send buffers if too small + for (int n = 0; n < pmb->neighbors.size(); n++) { + num_particles_to_send_h(n) -= buffer_start_h(n); + const int bufid = pmb->neighbors[n].bufid; + auto sendbuf = vbswarm->bd_var_.send[bufid]; + if (sendbuf.extent(0) < num_particles_to_send_h(n) * particle_size) { + sendbuf = BufArray1D("Buffer", num_particles_to_send_h(n) * particle_size); + vbswarm->bd_var_.send[bufid] = sendbuf; } + vbswarm->send_size[bufid] = num_particles_to_send_h(n) * particle_size; + } + if (max_active_index_ >= 0) { auto &bdvar = vbswarm->bd_var_; auto neighbor_buffer_index = neighbor_buffer_index_; // Loop over active particles buffer_sorted, use index n and buffer_start to