12#include "gadgetconfig.h"
14#ifdef SUBFIND_ORPHAN_TREATMENT
25#include "../cooling_sfr/cooling.h"
26#include "../data/allvars.h"
27#include "../data/dtypes.h"
28#include "../data/mymalloc.h"
29#include "../fof/fof.h"
30#include "../io/hdf5_util.h"
32#include "../logs/timer.h"
33#include "../main/main.h"
34#include "../main/simulation.h"
35#include "../mergertree/io_readsnap.h"
36#include "../mergertree/mergertree.h"
37#include "../mpi_utils/mpi_utils.h"
38#include "../sort/parallel_sort.h"
39#include "../system/system.h"
42void fof<simparticles>::subfind_match_ids_of_previously_most_bound_ids(
simparticles *Sp)
44 int *Send_count = (
int *)
Mem.mymalloc(
"Send_count",
sizeof(
int) * NTask);
45 int *Send_offset = (
int *)
Mem.mymalloc(
"Send_offset",
sizeof(
int) * NTask);
46 int *Recv_count = (
int *)
Mem.mymalloc(
"Recv_count",
sizeof(
int) * NTask);
47 int *Recv_offset = (
int *)
Mem.mymalloc(
"Recv_offset",
sizeof(
int) * NTask);
58 MPI_Allgather(&idmin,
sizeof(
MyIDType), MPI_BYTE, list_min_id,
sizeof(
MyIDType), MPI_BYTE, Communicator);
59 MPI_Allgather(&idmax,
sizeof(
MyIDType), MPI_BYTE, list_max_id,
sizeof(
MyIDType), MPI_BYTE, Communicator);
61 int *num_list = (
int *)
Mem.mymalloc(
"num_list", NTask *
sizeof(
int));
62 MPI_Allgather(&Sp->
NumPart, 1, MPI_INT, num_list, 1, MPI_INT, Communicator);
64 int nexport = 0, nimport = 0;
65 MyIDType *import_data = NULL, *export_data = NULL;
67 for(
int mode = 0; mode < 2; mode++)
69 for(
int i = 0; i < NTask; i++)
74 for(
int i = 0; i < Sp->IdStore.
NumPart; i++)
76 while(target < NTask - 1 && (num_list[target] == 0 || Sp->IdStore.ID[i] > list_max_id[target]))
79 if(num_list[target] == 0)
80 Terminate(
"How can this be? target=%d", target);
82 if(Sp->IdStore.ID[i] >= list_min_id[target] && Sp->IdStore.ID[i] <= list_max_id[target])
88 int off = Send_offset[target] + Send_count[target]++;
89 export_data[off] = Sp->IdStore.ID[i];
96 myMPI_Alltoall(Send_count, 1, MPI_INT, Recv_count, 1, MPI_INT, Communicator);
97 Recv_offset[0] = Send_offset[0] = 0;
98 for(
int j = 0; j < NTask; j++)
100 nimport += Recv_count[j];
101 nexport += Send_count[j];
104 Send_offset[j] = Send_offset[j - 1] + Send_count[j - 1];
105 Recv_offset[j] = Recv_offset[j - 1] + Recv_count[j - 1];
114 for(
int ngrp = 0; ngrp < (1 << PTask); ngrp++)
116 int recvTask = ThisTask ^ ngrp;
118 if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0)
120 &import_data[Recv_offset[recvTask]], Recv_count[recvTask] *
sizeof(
MyIDType), MPI_BYTE, recvTask,
TAG_DENS_B,
121 Communicator, MPI_STATUS_IGNORE);
127 for(
int i = 0, j = 0; i < Sp->
NumPart && j < nimport;)
129 if(Sp->
P[i].
ID.
get() < import_data[j])
131 else if(Sp->
P[i].
ID.
get() > import_data[j])
145 Mem.myfree(import_data);
146 Mem.myfree(export_data);
148 Mem.myfree(num_list);
149 Mem.myfree(list_max_id);
150 Mem.myfree(list_min_id);
152 Mem.myfree(Recv_offset);
153 Mem.myfree(Recv_count);
154 Mem.myfree(Send_offset);
155 Mem.myfree(Send_count);
157 long long tot_ncheck, tot_nmarked;
161 mpi_printf(
"SUBFIND_ORPHAN_TREATMENT: Got %lld particles from previous snapshot, led to %lld additionally marked particles\n",
162 tot_ncheck, tot_nmarked);
void mark_as_formerly_most_bound(void)
bool is_previously_most_bound(void)
static bool compare_IDs(const MyIDType &a, const MyIDType &b)
void sumup_large_ints(int n, int *src, long long *res, MPI_Comm comm)
int myMPI_Alltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
int myMPI_Sendrecv(void *sendbuf, size_t sendcount, MPI_Datatype sendtype, int dest, int sendtag, void *recvbuf, size_t recvcount, MPI_Datatype recvtype, int source, int recvtag, MPI_Comm comm, MPI_Status *status)
double mycxxsort_parallel(T *begin, T *end, Comp comp, MPI_Comm comm)