Zoltan User's Guide  |  Next  |  Previous

Load-Balancing Example

An example of the typical calling sequence for load balancing using Zoltan in a finite element application is shown in the figure below. An application first selects a load-balancing algorithm by setting the LB_METHOD parameter with Zoltan_Set_Param. Next, other parameter values are set by calls to Zoltan_Set_Param. After some computation, load balancing is invoked by calling Zoltan_LB_Partition. The results of the load balancing include the number of nodes to be imported and exported to the processor, lists of global and local IDs of the imported and exported nodes, and source and destination processors of the imported and exported nodes. A returned argument of Zoltan_LB_Partition is tested to see whether the new decomposition differs from the old one. If the decompositions differ, some sort of data migration is needed to establish the new decomposition; the details of migration are not shown in this figure but will be addressed in the migration examples. After the data migration is completed, the arrays of information about imported and exported nodes returned by Zoltan_LB_Partition are freed by a call to Zoltan_LB_Free_Part.
 
 
char *lb_method;
int new, num_imp, num_exp, *imp_procs, *exp_procs;
int *imp_to_part, *exp_to_part;
int num_gid_entries, num_lid_entries;
ZOLTAN_ID_PTR imp_global_ids, exp_global_ids;
ZOLTAN_ID_PTR imp_local_ids, exp_local_ids;

/* Set load-balancing method. */
read_load_balancing_info_from_input_file(&lb_method);
Zoltan_Set_Param(zz, "LB_METHOD", lb_method);

/* Reset some load-balancing parameters. */
Zoltan_Set_Param(zz, "RCB_Reuse", "TRUE");

/* Perform computations */
...
/* Perform load balancing */
Zoltan_LB_Partition(zz,&new,&num_gid_entries,&num_lid_entries,
    &num_imp,&imp_global_ids,&imp_local_ids,&imp_procs,&imp_to_part,
    &num_exp,&exp_global_ids,&exp_local_ids,&exp_procs,&exp_to_part); 
if (new)
  perform_data_migration(...);

/* Free memory allocated for load-balancing results by Zoltan library */
Zoltan_LB_Free_Part(&imp_global_ids, &imp_local_ids, &imp_procs, &imp_to_part);
Zoltan_LB_Free_Part(&exp_global_ids, &exp_local_ids, &exp_procs, &exp_to_part);
...

Typical calling sequence for performing load balancing with the Zoltan library.

 
character(len=3) lb_method
logical new
integer(Zoltan_INT) num_imp, num_exp
integer(Zoltan_INT) num_gid_entries, num_lid_entries 
integer(Zoltan_INT), pointer :: imp_procs(:), exp_procs(:)
integer(Zoltan_INT), pointer :: imp_global_ids(:), exp_global_ids(:) ! global IDs
integer(Zoltan_INT), pointer :: imp_local_ids(:), exp_local_ids(:) ! local IDs
integer(Zoltan_INT) ierr

! Set load-balancing method.
lb_method = "RCB"
ierr = Zoltan_Set_Param(zz, "LB_METHOD", lb_method)

! Reset some load-balancing parameters
ierr = Zoltan_Set_Param(zz, "RCB_Reuse", "TRUE")

! Perform computations
...
! Perform load balancing
ierr = Zoltan_LB_Partition(zz,new,num_gid_entries,num_lid_entries, &
       num_imp,imp_global_ids,imp_local_ids, &
       imp_procs,imp_to_part, &
       num_exp,exp_global_ids,exp_local_ids, &
       exp_procs,exp_to_part) 
if (new) then
  perform_data_migration(...)
endif

! Free memory allocated for load-balancing results by Zoltan library
ierr = Zoltan_LB_Free_Part(imp_global_ids, imp_local_ids, imp_procs, imp_to_part);
ierr = Zoltan_LB_Free_Part(exp_global_ids, exp_local_ids, exp_procs, exp_to_part);
...

Fortran version of the load-balancing example.


[Table of Contents  | Next:  Migration Examples  |  Previous:  General Usage Example  |  Privacy and Security]