Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calculation of attribute_data_offset #1094

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/t8_cmesh/t8_cmesh_commit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct ghost_facejoins_struct
{
t8_gloidx_t ghost_id; /* The id of the ghost */
t8_locidx_t local_id; /* The local id of the ghost */
t8_gloidx_t attr_id; /* The current number of inserted ghost attributes */
} t8_ghost_facejoin_t;

static int
Expand Down Expand Up @@ -112,8 +113,9 @@ t8_cmesh_add_attributes (t8_cmesh_t cmesh, sc_hash_t *ghost_ids, size_t *attribu
temp_facejoin->ghost_id = attribute->id;
if (sc_hash_lookup (ghost_ids, temp_facejoin, (void ***) &facejoin_pp)) {
/* attribute is on a ghost tree */
t8_cmesh_trees_add_ghost_attribute (cmesh->trees, 0, attribute, (*facejoin_pp)->local_id, sj,
attribute_data_offset);
t8_cmesh_trees_add_ghost_attribute (cmesh->trees, 0, attribute, (*facejoin_pp)->local_id,
(*facejoin_pp)->attr_id, attribute_data_offset);
(*facejoin_pp)->attr_id++;
}
}
}
Expand Down Expand Up @@ -261,6 +263,7 @@ t8_cmesh_commit_partitioned_new (t8_cmesh_t cmesh, sc_MPI_Comm comm)
ghost_ids = sc_hash_new (t8_ghost_hash, t8_ghost_facejoin_equal, &num_hashes, NULL);

temp_facejoin = (t8_ghost_facejoin_t *) sc_mempool_alloc (ghost_facejoin_mempool);
temp_facejoin->attr_id = 0;

cmesh->num_ghosts = 0;
/* Parse joinfaces array and save all global id of local ghosts, and assign them a local id */
Expand All @@ -280,6 +283,7 @@ t8_cmesh_commit_partitioned_new (t8_cmesh_t cmesh, sc_MPI_Comm comm)
/* If we did not already stored id2 in the hash we do so and assign the next local ghost id */
temp_facejoin->local_id = cmesh->num_ghosts++;
temp_facejoin = (t8_ghost_facejoin_t *) sc_mempool_alloc (ghost_facejoin_mempool);
temp_facejoin->attr_id = 0;
}
}
if (!id1_istree) {
Expand All @@ -290,6 +294,7 @@ t8_cmesh_commit_partitioned_new (t8_cmesh_t cmesh, sc_MPI_Comm comm)
/* If we did not already stored id1 in the hash we do so and assign the next local ghost id */
temp_facejoin->local_id = cmesh->num_ghosts++;
temp_facejoin = (t8_ghost_facejoin_t *) sc_mempool_alloc (ghost_facejoin_mempool);
temp_facejoin->attr_id = 0;
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/t8_cmesh/t8_cmesh_trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,15 @@ t8_cmesh_trees_get_part_alloc (t8_cmesh_trees_t trees, t8_part_tree_t part)
byte_alloc = part->num_trees * sizeof (t8_ctree_struct_t) + part->num_ghosts * sizeof (t8_cghost_struct_t);
for (ltree = 0; ltree < part->num_trees; ltree++) {
tree = t8_cmesh_trees_get_tree (trees, ltree + part->first_tree_id);
byte_alloc += t8_cmesh_trees_neighbor_bytes (tree);
byte_alloc += t8_cmesh_trees_attribute_size (tree);
byte_alloc += tree->num_attributes * sizeof (t8_attribute_info_struct_t);
byte_alloc += t8_cmesh_trees_neighbor_bytes (tree);
}
for (lghost = 0; lghost < part->num_ghosts; lghost++) {
ghost = t8_cmesh_trees_get_ghost (trees, lghost + part->first_ghost_id);
byte_alloc += t8_cmesh_trees_gneighbor_bytes (ghost);
byte_alloc += t8_cmesh_trees_ghost_attribute_size (ghost);
byte_alloc += ghost->num_attributes * sizeof (t8_attribute_info_struct_t);
}
return byte_alloc;
}
Expand Down Expand Up @@ -686,7 +688,7 @@ t8_cmesh_trees_add_ghost_attribute (t8_cmesh_trees_t trees, int proc, t8_stash_a
ghost = t8_part_tree_get_ghost (part, local_ghost_id);

attr_info = T8_GHOST_ATTR_INFO (ghost, index);
attr_info->attribute_offset = *attribute_data_offset - local_ghost_id * sizeof (t8_attribute_info_struct_t);
attr_info->attribute_offset = *attribute_data_offset;
new_attr_data = T8_GHOST_ATTR (ghost, attr_info);

memcpy (new_attr_data, attr->attr_data, attr->attr_size);
Expand All @@ -697,6 +699,9 @@ t8_cmesh_trees_add_ghost_attribute (t8_cmesh_trees_t trees, int proc, t8_stash_a
attr_info->attribute_size = attr->attr_size;

*attribute_data_offset += attr->attr_size;
if (index == (size_t) ghost->num_attributes - 1) {
*attribute_data_offset -= ghost->num_attributes * sizeof (t8_attribute_info_struct_t);
}
}

/* gets a key_id_pair as first argument and an attribute as second */
Expand Down