void CostZonesHelper (long my_id, box *b, long work, direction dir) { box *cb; long i; long *next_child; long *child_dir; if (b->type == CHILDLESS) { if (work >= Local[my_id].Min_Work) InsertBoxInPartition(my_id, b); } else { next_child = Child_Sequence[dir]; child_dir = Direction_Sequence[dir]; for (i = 0; (i < NUM_OFFSPRING) && (work < Local[my_id].Max_Work); i++) { cb = b->children[next_child[i]]; if (cb != NULL) { if ((work + cb->subtree_cost) >= Local[my_id].Min_Work) CostZonesHelper(my_id, cb, work, child_dir[i]); work += cb->subtree_cost; } if (i == 2) { if ((work >= Local[my_id].Min_Work) && (work < Local[my_id].Max_Work)) InsertBoxInPartition(my_id, b); work += b->cost; } } } }
void CleanupGrid (long my_id) { box *b_scan, *tb; b_scan = Local[my_id].Childless_Partition; while (b_scan != NULL) { if (((b_scan->parent != NULL) || (b_scan == Grid)) && (b_scan->type == CHILDLESS)) b_scan = b_scan->next; else { tb = b_scan; b_scan = b_scan->next; if (tb->type == PARENT) { tb->type = CHILDLESS; RemoveBoxFromPartition(my_id, tb); tb->type = PARENT; if ((tb->parent != NULL) || (tb == Grid)) { InsertBoxInPartition(my_id, tb); } } else RemoveBoxFromPartition(my_id, tb); } } }
void InsertSubtreeInPartition (long my_id, box *b) { long i; box *child; if (b->proc == my_id) { InsertBoxInPartition(my_id, b); } if (b->type == PARENT) { for (i = 0; i < NUM_OFFSPRING; i++) { child = b->children[i]; if (child == NULL) child = b->shadow[i]; if (child != NULL) InsertSubtreeInPartition(my_id, child); } } }