MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Classes | Macros | Functions | Variables
partmanager.h File Reference
#include "types.h"
#include "utils/peano.h"
Include dependency graph for partmanager.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  particle_data
 
struct  part_manager_type
 

Macros

#define P   PartManager->Base
 
#define NEAREST(x, BoxSize)   (((x)>0.5*BoxSize)?((x)-BoxSize):(((x)<-0.5*BoxSize)?((x)+BoxSize):(x)))
 

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)
 
static double DMAX (double a, double b)
 
static double DMIN (double a, double b)
 
static int IMAX (int a, int b)
 
static int IMIN (int a, int b)
 

Variables

struct part_manager_type PartManager [1]
 

Macro Definition Documentation

◆ NEAREST

#define NEAREST (   x,
  BoxSize 
)    (((x)>0.5*BoxSize)?((x)-BoxSize):(((x)<-0.5*BoxSize)?((x)+BoxSize):(x)))

Definition at line 99 of file partmanager.h.

◆ P

#define P   PartManager->Base

Definition at line 88 of file partmanager.h.

Function Documentation

◆ DMAX()

static double DMAX ( double  a,
double  b 
)
inlinestatic

Definition at line 101 of file partmanager.h.

101  {
102  if(a > b) return a;
103  return b;
104 }

◆ DMIN()

static double DMIN ( double  a,
double  b 
)
inlinestatic

Definition at line 105 of file partmanager.h.

105  {
106  if(a < b) return a;
107  return b;
108 }

◆ IMAX()

static int IMAX ( int  a,
int  b 
)
inlinestatic

Definition at line 109 of file partmanager.h.

109  {
110  if(a > b) return a;
111  return b;
112 }

◆ IMIN()

static int IMIN ( int  a,
int  b 
)
inlinestatic

Definition at line 113 of file partmanager.h.

113  {
114  if(a < b) return a;
115  return b;
116 }

◆ 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]