Canoe
Comprehensive Atmosphere N' Ocean Engine
particle_restart.cpp
Go to the documentation of this file.
1 
4 // Athena++
5 #include <athena/mesh/mesh.hpp>
6 
7 // canoe
8 #include <configure.hpp>
9 
10 // n-body
11 #include "particle_data.hpp"
12 #include "particles.hpp"
13 
14 // mpi
15 #ifdef MPI_PARALLEL
16 #include <mpi.h>
17 #endif
18 
19 size_t ParticleBase::RestartDataSizeInBytes(Mesh const *pm) const {
20  size_t size = sizeof(int);
21  size += pc.size() * sizeof(ParticleData);
22 
23  // gather maximum size across all local blocks
24  for (int b = 0; b < pm->nbtotal; b++) {
25  auto pmb = pm->my_blocks(b);
26  for (auto &pt : pmb->pimpl->all_particles) {
27  size_t tmp = sizeof(int) + pt->pc.size() * sizeof(ParticleData);
28  if (tmp > size) size = tmp;
29  }
30  }
31 
32  // gather maximum size across all MPI ranks
33 #ifdef MPI_PARALLEL
34  MPI_Allreduce(MPI_IN_PLACE, &size, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
35 #endif
36 
37  return size;
38 }
39 
41 void ParticleBase::DumpRestartData(char *pdst) const {
42  int size = pc.size();
43 
44  std::memcpy(pdst, &size, sizeof(int));
45  pdst += sizeof(int);
46  std::memcpy(pdst, pc.data(), size * sizeof(ParticleData));
47  pdst += size * sizeof(ParticleData);
48 }
49 
50 size_t ParticleBase::LoadRestartData(char *psrc) {
51  int size;
52 
53  std::memcpy(&size, psrc, sizeof(int));
54  psrc += sizeof(int);
55  pc.resize(size);
56  std::memcpy(pc.data(), psrc, size * sizeof(ParticleData));
57  psrc += size * sizeof(ParticleData);
58 
59  return size;
60 }
ParticleContainer pc
Definition: particles.hpp:39
void DumpRestartData(char *pdst) const override
size_t RestartDataSizeInBytes(Mesh const *pm) const override
size_t LoadRestartData(char *psrt) override