9 #define SLOTS_ENABLED(ptype, sman) (sman->info[ptype].enabled)
63 int oldtype = pman->
Base[parent].
Type;
64 int oldPI = pman->
Base[parent].
PI;
70 int newPI = placement;
108 endrun(8888,
"Tried to spawn: NumPart=%ld MaxPart = %ld. Sorry, no space left.\n", child, pman->
MaxPart);
112 pman->
Base[child] = pman->
Base[parent];
115 pman->
Base[child].
ID = (pman->
Base[parent].
ID & 0x00ffffffffffffffL) + (g << 56L);
116 if(g >= (1 << (64-56L)))
117 endrun(1,
"Particle %d (ID: %ld) generated too many particles: generation %ld wrapped.\n", parent, pman->
Base[parent].
ID, g);
120 pman->
Base[parent].
Mass -= childmass;
123 pman->
Base[child].
PI = -1;
149 int tree_invalid = 0;
158 MPI_Allreduce(MPI_IN_PLACE, &tree_invalid, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
164 #define GARBAGE(i, ptype, pman, sman) (sman ? BASESLOT_PI(i,ptype, sman)->ReverseLink > pman->MaxPart : pman->Base[i].IsGarbage)
165 #define PART(i, ptype, pman, sman) (sman ? (void *) BASESLOT_PI(i, ptype, sman) : (void *) &pman->Base[i])
171 int i, nextgc = used;
173 for(i = start; i < used; i++)
185 int i, nextgc = used;
187 for(i = start; i < used; i++)
206 while(nextgc < used) {
217 int dest = lastgc - ngc;
224 int nmove = nextgc - src +1;
229 endrun(1,
"ngc = %d > used = %d!\n", ngc, used);
236 int64_t total0, total;
238 MPI_Allreduce(&pman->
NumPart, &total0, 1,
MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
246 MPI_Allreduce(&pman->
NumPart, &total, 1,
MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
248 if(total != total0) {
249 message(0,
"GC : Reducing Particle slots from %ld to %ld\n", total0, total);
281 #pragma omp parallel for
282 for(i = 0; i < info.
size; i++) {
289 #pragma omp parallel for
290 for(i = 0; i < pman->
NumPart; i++) {
294 int sind = pman->
Base[i].
PI;
295 if(sind >= info.
size || sind < 0)
296 endrun(1,
"Particle %d, type %d has PI index %d beyond max slot size %d.\n", i, pman->
Base[i].
Type, sind, info.
size);
328 #pragma omp parallel for
335 endrun(1,
"Shall not happen: i=%d ptype = %d\n", i,
ptype);
355 if(compact_slots[
ptype])
367 if(!compact_slots[
ptype])
426 int nmid = (nfirst + nlast)/2;
432 while(nlast - nfirst > 1);
477 int64_t newMaxSlots[6];
481 if(sman->
Base == NULL) {
490 if (
add < 8192)
add = 8192;
503 size_t total_bytes = 0;
505 size_t bytes[6] = {0};
508 offsets[
ptype] = total_bytes;
510 total_bytes += bytes[
ptype];
516 char * newSlotsBase = (
char *)
myrealloc(sman->
Base, total_bytes);
525 message(where,
"SLOTS: Reserved %g MB for %ld sph, %ld stars and %ld BHs (disabled: %ld %ld %ld)\n", total_bytes / (1024.0 * 1024.0),
526 newMaxSlots[0], newMaxSlots[4], newMaxSlots[5], newMaxSlots[1], newMaxSlots[2], newMaxSlots[3]);
532 memmove(newSlotsBase + offsets[
ptype],
537 sman->
Base = newSlotsBase;
552 memset(sman, 0,
sizeof(sman[0]));
589 int64_t used[6] = {0};
592 for(i = 0; i < pman->
NumPart; i++) {
600 int PI = pman->
Base[i].
PI;
601 if(PI >= info.
size) {
602 endrun(1,
"slot PI consistency failed2\n");
605 endrun(1,
"slot id consistency failed2: i=%d PI=%d type = %d P.ID = %ld SLOT.ID=%ld\n",i, PI, pman->
Base[i].
Type, pman->
Base[i].
ID,
BASESLOT_PI(PI, type, sman)->ID);
611 MPI_Allreduce(used, NTotal, 6,
MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
615 if(NTotal[
ptype] > 0) {
632 #pragma omp parallel for
633 for(i = 0; i < NLocal[
ptype]; i++)
635 size_t j = offset + i;
641 offset += NLocal[
ptype];
657 #pragma omp parallel for
658 for(i = 0; i < pman->
NumPart; i++)
664 int sind = pman->
Base[i].
PI;
665 if(sind >= info.
size || sind < 0)
666 endrun(1,
"Particle %d, type %d has PI index %d beyond max slot size %d.\n", i, pman->
Base[i].
Type, sind, info.
size);
void message(int where, const char *fmt,...)
void endrun(int where, const char *fmt,...)
int event_emit(EventSpec *eh, EIBase *event)
#define mymalloc(name, size)
#define myrealloc(ptr, size)
static int slots_gc_base(struct part_manager_type *pman)
void slots_setup_id(const struct part_manager_type *pman, struct slots_manager_type *sman)
size_t slots_reserve(int where, int64_t atleast[6], struct slots_manager_type *sman)
MPI_Datatype MPI_TYPE_SLOT[6]
#define SLOTS_ENABLED(ptype, sman)
static struct bh_particle_data * GDB_BhP
MPI_Datatype MPI_TYPE_PARTICLE
void slots_set_enabled(int ptype, size_t elsize, struct slots_manager_type *sman)
void slots_mark_garbage(int i, struct part_manager_type *pman, struct slots_manager_type *sman)
static int slots_gc_mark(const struct part_manager_type *pman, const struct slots_manager_type *sman)
static int slots_find_next_garbage(int start, int used, int ptype, struct part_manager_type *pman, struct slots_manager_type *sman)
static int slots_gc_slots(int *compact_slots, struct part_manager_type *pman, struct slots_manager_type *sman)
void slots_free(struct slots_manager_type *sman)
static int slots_gc_compact(const int used, int ptype, struct part_manager_type *pman, struct slots_manager_type *sman)
#define GARBAGE(i, ptype, pman, sman)
static void slots_gc_collect(int ptype, struct part_manager_type *pman, struct slots_manager_type *sman)
static void slots_connect_new_slot(int i, int pi, int type, struct part_manager_type *pman, struct slots_manager_type *sman)
static int slots_gc_sweep(int ptype, struct part_manager_type *pman, struct slots_manager_type *sman)
void slots_setup_topology(struct part_manager_type *pman, int64_t *NLocal, struct slots_manager_type *sman)
#define PART(i, ptype, pman, sman)
MPI_Datatype MPI_TYPE_PLAN_ENTRY
static int slots_find_next_nongarbage(int start, int used, int ptype, struct part_manager_type *pman, struct slots_manager_type *sman)
int slots_gc(int *compact_slots, struct part_manager_type *pman, struct slots_manager_type *sman)
void slots_check_id_consistency(struct part_manager_type *pman, struct slots_manager_type *sman)
struct slots_manager_type SlotsManager[1]
static int order_by_type_and_key(const void *a, const void *b)
void slots_gc_sorted(struct part_manager_type *pman, struct slots_manager_type *sman)
static struct sph_particle_data * GDB_SphP
static struct star_particle_data * GDB_StarP
void slots_init(double increase, struct slots_manager_type *sman)
int slots_get_last_garbage(int nfirst, int nlast, int ptype, const struct part_manager_type *pman, const struct slots_manager_type *sman)
static int slot_cmp_reverse_link(const void *b1in, const void *b2in)
int slots_convert(int parent, int ptype, int placement, struct part_manager_type *pman, struct slots_manager_type *sman)
int slots_split_particle(int parent, double childmass, struct part_manager_type *pman)
#define BASESLOT_PI(PI, ptype, sman)
struct particle_data * Base
static int64_t atomic_fetch_and_add_64(int64_t *ptr, int64_t value)
static enum TransferType ptype