Commit 85bee249 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'redistribute_fixes' into 'master'

Redistribute fixes



See merge request !131
parents dfd7461e f24a6554
......@@ -502,7 +502,7 @@ void writeXMFline(FILE* xmfFile, char* fileName, char* partTypeGroupName,
* @param gparts The array of #gpart freshly read in.
* @param Ndm The number of DM particles read in.
*/
void prepare_dm_gparts(struct gpart* gparts, size_t Ndm) {
void prepare_dm_gparts(struct gpart* const gparts, size_t Ndm) {
/* Let's give all these gparts a negative id */
for (size_t i = 0; i < Ndm; ++i) {
......@@ -527,8 +527,9 @@ void prepare_dm_gparts(struct gpart* gparts, size_t Ndm) {
* @param Ngas The number of gas particles read in.
* @param Ndm The number of DM particles read in.
*/
void duplicate_hydro_gparts(struct part* parts, struct gpart* gparts,
size_t Ngas, size_t Ndm) {
void duplicate_hydro_gparts(struct part* const parts,
struct gpart* const gparts, size_t Ngas,
size_t Ndm) {
for (size_t i = 0; i < Ngas; ++i) {
......@@ -557,16 +558,19 @@ void duplicate_hydro_gparts(struct part* parts, struct gpart* gparts,
* @param dmparts The array of #gpart containg DM particles to be filled.
* @param Ndm The number of DM particles.
*/
void collect_dm_gparts(struct gpart* gparts, size_t Ntot, struct gpart* dmparts,
size_t Ndm) {
void collect_dm_gparts(const struct gpart* const gparts, size_t Ntot,
struct gpart* const dmparts, size_t Ndm) {
size_t count = 0;
/* Loop over all gparts */
for (size_t i = 0; i < Ntot; ++i) {
/* message("i=%zd count=%zd id=%lld part=%p", i, count, gparts[i].id,
* gparts[i].part); */
/* And collect the DM ones */
if (gparts[i].id < 0) {
if (gparts[i].id < 0LL) {
memcpy(&dmparts[count], &gparts[i], sizeof(struct gpart));
dmparts[count].id = -dmparts[count].id;
count++;
......
......@@ -78,11 +78,12 @@ extern const char* particle_type_names[];
hid_t hdf5Type(enum DATA_TYPE type);
size_t sizeOfType(enum DATA_TYPE type);
void collect_dm_gparts(struct gpart* gparts, size_t Ntot, struct gpart* dmparts,
size_t Ndm);
void prepare_dm_gparts(struct gpart* gparts, size_t Ndm);
void duplicate_hydro_gparts(struct part* parts, struct gpart* gparts,
size_t Ngas, size_t Ndm);
void collect_dm_gparts(const struct gpart* const gparts, size_t Ntot,
struct gpart* const dmparts, size_t Ndm);
void prepare_dm_gparts(struct gpart* const gparts, size_t Ndm);
void duplicate_hydro_gparts(struct part* const parts,
struct gpart* const gparts, size_t Ngas,
size_t Ndm);
void readAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data);
......
......@@ -225,6 +225,10 @@ void engine_redistribute(struct engine *e) {
count_this_dest = 0;
}
/* Debug */
/* if(s->parts[k].gpart->id < 0) */
/* error("Trying to link a partnerless gpart !"); */
s->parts[k].gpart->id = count_this_dest;
count_this_dest++;
}
......@@ -309,6 +313,8 @@ void engine_redistribute(struct engine *e) {
/* Are we sending any part/xpart ? */
if (counts[ind_send] > 0) {
/* message("Sending %d part to node %d", counts[ind_send], k); */
/* If the send is to the same node, just copy */
if (k == nodeID) {
memcpy(&parts_new[offset_recv], &s->parts[offset_send],
......@@ -335,6 +341,8 @@ void engine_redistribute(struct engine *e) {
/* Are we sending any gpart ? */
if (g_counts[ind_send] > 0) {
/* message("Sending %d gpart to node %d", g_counts[ind_send], k); */
/* If the send is to the same node, just copy */
if (k == nodeID) {
memcpy(&gparts_new[g_offset_recv], &s->gparts[g_offset_send],
......@@ -348,7 +356,7 @@ void engine_redistribute(struct engine *e) {
e->gpart_mpi_type, k, 3 * ind_send + 2, MPI_COMM_WORLD,
&reqs[6 * k + 2]) != MPI_SUCCESS)
error("Failed to isend gparts to node %i.", k);
g_offset_send += counts[ind_send];
g_offset_send += g_counts[ind_send];
}
}
......@@ -418,9 +426,11 @@ void engine_redistribute(struct engine *e) {
/* Verify that all parts are in the right place. */
/* for ( int k = 0 ; k < nr_parts ; k++ ) {
int cid = cell_getid( cdim , parts_new[k].x[0]*ih[0], parts_new[k].x[1]*ih[1], parts_new[k].x[2]*ih[2] );
int cid = cell_getid( cdim , parts_new[k].x[0]*ih[0],
parts_new[k].x[1]*ih[1], parts_new[k].x[2]*ih[2] );
if ( cells[ cid ].nodeID != nodeID )
error( "Received particle (%i) that does not belong here (nodeID=%i).", k , cells[ cid ].nodeID );
error( "Received particle (%i) that does not belong here
(nodeID=%i).", k , cells[ cid ].nodeID );
} */
/* Verify that the links are correct */
......@@ -429,10 +439,20 @@ void engine_redistribute(struct engine *e) {
if (gparts_new[k].id > 0) {
if (gparts_new[k].part->gpart != &gparts_new[k])
error("Linking problem !");
if (gparts_new[k].x[0] != gparts_new[k].part->x[0] ||
gparts_new[k].x[1] != gparts_new[k].part->x[1] ||
gparts_new[k].x[2] != gparts_new[k].part->x[2])
message("Linked particles are not at the same position !");
error("Linked particles are not at the same position !");
}
}
for (size_t k = 0; k < nr_parts; ++k) {
if (parts_new[k].gpart != NULL) {
if (parts_new[k].gpart->part != &parts_new[k]) error("Linking problem !");
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment