/* Allocate RCB data structure for this Zoltan structure. * If the previous data structure still exists, free the Dots first; * the other fields can be reused. */ if (zz->LB.Data_Structure == NULL) { rcb = (RCB_STRUCT *) ZOLTAN_MALLOC(sizeof(RCB_STRUCT)); zz->LB.Data_Structure = (void *) rcb; rcb->Tree_Ptr = (struct rcb_tree *) ZOLTAN_MALLOC(zz->Num_Proc*sizeof(struct rcb_tree)); rcb->Box = (struct rcb_box *) ZOLTAN_MALLOC(sizeof(struct rcb_box)); } else { rcb = (RCB_STRUCT *) zz->LB.Data_Structure; ZOLTAN_FREE(&(rcb->Dots)); } |
The data needed for the algorithm is collected through calls to the
query functions registered by the application. Algorithms should test the
query function pointers for NULL and report errors when needed functions
are not registered. The appropriate query functions can be called to build
the algorithm's data structures up front, or they can be called during
the algorithm's execution to gather data only as it is needed. The figure
below shows how the Dots data structure needed by RCB is built.
The call to zz->Get_Num_Obj invokes an ZOLTAN_NUM_OBJ_FN
query function to determine the number of objects on the processor.
Space for the Dots data structure is allocated through calls to
ZOLTAN_MALLOC, ZOLTAN_MALLOC_GID_ARRAY,
and ZOLTAN_MALLOC_LID_ARRAY. The Dots information is obtained
through a call to the Zoltan service function Zoltan_Get_Obj_List; this
function calls either an ZOLTAN_OBJ_LIST_FN
or an ZOLTAN_FIRST_OBJ_FN/ZOLTAN_NEXT_OBJ_FN
pair to get the object IDs and weights. The data for each
Dot is
set in the function initialize_dot, which includes calls to zz->Get_Geom,
an ZOLTAN_GEOM_FN
query function.
/* * Allocate space for objects. Allow extra space * for objects that are imported to the processor. */ *num_obj = zz->Get_Num_Obj(zz->Get_Num_Obj_Data, &ierr);
*max_obj = (int)(1.5 * *num_obj) + 1;
if (!(*global_ids) || (zz->Num_LID && !(*local_ids)) ||
!(*dots)) {
if (*num_obj > 0) { if (wgtflag) { /*
objs_wgt = (float *) ZOLTAN_MALLOC((*num_obj)*sizeof(float));
/*
Zoltan_Get_Obj_List(zz, *global_ids, *local_ids, wgtflag,
ierr = initialize_dot(zz, *global_ids, *local_ids, *dots,
ZOLTAN_FREE(&objs_wgt);
|
The data structures pointed to by zz->LB.Data_Structure will be freed at some point, and may be copied.
A function that frees these structures and resets zz->LB.Data_Structure to NULL should be written. The function should be called when the load-balancing algorithm exits, either normally or due to an error condition. The function Zoltan_RCB_Free_Structure in rcb/rcb_util.c may be used as an example.
If your algorithm uses the KEEP_CUTS parameter, a function that copies one zz->LB.Data_Structure to another is required. This is particularly important for C++, which may create temporary objects at runtime by invoking a copy operator (which will call your copy function). It is a convenience for C applications, which may wish to copy one Zoltan_Struct to another. See the function Zoltan_RCB_Copy_Structure in rcb/rcb_util.c for an example.