MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Functions | Variables
partmanager.c File Reference
#include <string.h>
#include "partmanager.h"
#include "utils/mymalloc.h"
#include "utils/endrun.h"
#include "utils/system.h"
Include dependency graph for partmanager.c:

Go to the source code of this file.

Functions

void particle_alloc_memory (struct part_manager_type *PartManager, double BoxSize, int64_t MaxPart)
 
void update_random_offset (struct part_manager_type *PartManager, double *rel_random_shift, double RandomParticleOffset)
 

Variables

struct part_manager_type PartManager [1] = {{0}}
 

Function Documentation

◆ particle_alloc_memory()

void particle_alloc_memory ( struct part_manager_type PartManager,
double  BoxSize,
int64_t  MaxPart 
)

Definition at line 14 of file partmanager.c.

15 {
16  size_t bytes;
17  PartManager->Base = (struct particle_data *) mymalloc("P", bytes = MaxPart * sizeof(struct particle_data));
18  PartManager->MaxPart = MaxPart;
19  PartManager->NumPart = 0;
20  if(MaxPart >= 1L<<31 || MaxPart < 0)
21  endrun(5, "Trying to store %ld particles on a single node, more than fit in an int32, not supported\n", MaxPart);
22  memset(PartManager->CurrentParticleOffset, 0, 3*sizeof(double));
23 
24  PartManager->BoxSize = BoxSize;
25  /* clear the memory to avoid valgrind errors;
26  *
27  * note that I tried to set each component in P to zero but
28  * valgrind still complains in PFFT
29  * seems to be to do with how the struct is padded and
30  * the missing holes being accessed by __kmp_atomic functions.
31  * (memory lock etc?)
32  * */
33  memset(PartManager->Base, 0, sizeof(struct particle_data) * MaxPart);
34  message(0, "Allocated %g MByte for storing %ld particles.\n", bytes / (1024.0 * 1024.0), MaxPart);
35 }
void message(int where, const char *fmt,...)
Definition: endrun.c:175
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
#define mymalloc(name, size)
Definition: mymalloc.h:15
struct part_manager_type PartManager[1]
Definition: partmanager.c:11
struct particle_data * Base
Definition: partmanager.h:74
double CurrentParticleOffset[3]
Definition: partmanager.h:82

References part_manager_type::Base, part_manager_type::BoxSize, part_manager_type::CurrentParticleOffset, endrun(), part_manager_type::MaxPart, message(), mymalloc, part_manager_type::NumPart, and PartManager.

Referenced by init_alloc_particle_slot_memory(), setup_density(), and setup_particles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_random_offset()

void update_random_offset ( struct part_manager_type PartManager,
double *  rel_random_shift,
double  RandomParticleOffset 
)

Definition at line 43 of file partmanager.c.

44 {
45  int i;
46  for (i = 0; i < 3; i++) {
47  /* Note random number table is duplicated across processors*/
48  double rr = get_random_number(i);
49  /* Upstream Gadget uses a random fraction of the box, but since all we need
50  * is to adjust the tree openings, and the tree force is zero anyway on the
51  * scale of a few PM grid cells, this seems enough.*/
52  rr *= RandomParticleOffset * PartManager->BoxSize;
53  /* Subtract the old random shift first.*/
54  rel_random_shift[i] = rr - PartManager->CurrentParticleOffset[i];
56  }
57  message(0, "Internal particle offset is now %g %g %g\n", PartManager->CurrentParticleOffset[0], PartManager->CurrentParticleOffset[1], PartManager->CurrentParticleOffset[2]);
58 #ifdef DEBUG
59  /* Check explicitly that the vector is the same on all processors*/
60  double test_random_shift[3] = {0};
61  for (i = 0; i < 3; i++)
62  test_random_shift[i] = PartManager->CurrentParticleOffset[i];
63  MPI_Bcast(test_random_shift, 3, MPI_DOUBLE, 0, MPI_COMM_WORLD);
64  for (i = 0; i < 3; i++)
65  if(test_random_shift[i] != PartManager->CurrentParticleOffset[i])
66  endrun(44, "Random shift %d is %g != %g on task 0!\n", i, test_random_shift[i], PartManager->CurrentParticleOffset[i]);
67 #endif
68 }
double get_random_number(uint64_t id)
Definition: system.c:60

References part_manager_type::BoxSize, part_manager_type::CurrentParticleOffset, endrun(), get_random_number(), message(), and PartManager.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ PartManager

struct part_manager_type PartManager[1] = {{0}}

This structure holds all the information that is stored for each particle of the simulation on the local processor.

Definition at line 1 of file partmanager.c.

Referenced by _prepare(), add_particle_to_group(), apply_PM_half_kick(), begrun(), blackhole_accretion_ngbiter(), blackhole_feedback_ngbiter(), blackhole_make_one(), check_accns(), check_against_force_direct(), check_densities(), check_omega(), check_positions(), check_smoothing_length(), collect_BH_info(), cooling_direct(), copy_and_mean_accn(), density(), do_density_test(), do_force_test(), do_random_test(), domain_allocate(), domain_check_for_local_refine_subsample(), domain_check_memory_bound(), domain_compute_costs(), domain_decompose_full(), domain_maintain(), drift_all_particles(), effhsml(), energy_statistics(), ev_alloc_threadlocals(), ev_begin(), find_means(), find_timesteps(), fof_compile_base(), fof_compile_catalogue(), fof_distribute_particles(), fof_fof(), fof_label_primary(), fof_label_secondary(), fof_seed(), fof_try_particle_exchange(), fof_write_header(), force_direct(), force_tree_build(), force_tree_create_nodes(), force_tree_rebuild(), force_tree_rebuild_mask(), force_update_hmax(), gas_ionization_fraction(), GDB_find_garbage(), GDB_particle_by_generation(), GDB_particle_by_id(), GDB_particle_by_timebin(), GDB_particle_by_type(), get_helium_neutral_fraction_sfreff(), get_long_range_timestep_dloga(), get_neutral_fraction_sfreff(), get_sfr_eeqos(), gravpm_force(), GTBlackholeMinPotPos(), GTFirstPos(), GTMassCenterPosition(), GTPosition(), init(), init_alloc_particle_slot_memory(), lightcone_compute(), lightcone_cross(), make_particle_star(), particle_alloc_memory(), petaio_read_snapshot(), petaio_readout_buffer(), petaio_save_snapshot(), rebuild_activelist(), run(), run_gravity_test(), runfof(), runpower(), set_init_hsml(), setup_density(), setup_particles(), setup_smoothinglengths(), setup_tree(), sfr_reserve_slots(), teardown_particles(), test_density_close(), test_density_flat(), test_exchange(), test_exchange_uneven(), test_exchange_with_garbage(), test_exchange_zero_slots(), test_fof(), test_force_close(), test_force_flat(), test_force_random(), turn_on_quasars(), update_random_offset(), and use_pairwise_gravity().