コード例 #1
0
ファイル: GridCommRefineLB.C プロジェクト: davidheryanto/sc14
/**************************************************************************
** The Charm++ load balancing framework invokes this method to cause the
** load balancer to migrate objects to "better" PEs.
*/
void GridCommRefineLB::work (LDStats *stats)
{
  int i;
  // int j;
  // CmiBool available;
  // CmiBool all_pes_mapped;
  // int max_cluster;
  // int min_speed;
  // int send_object;
  // int send_pe;
  // int send_cluster;
  // int recv_object;
  // int recv_pe;
  // int recv_cluster;
  // LDCommData *com_data;


  if (_lb_args.debug() > 0) {
    CkPrintf ("[%d] GridCommRefineLB is working.\n", CkMyPe());
  }

  // Since this load balancer looks at communications data, it must call stats->makeCommHash().
  stats->makeCommHash ();

  // Initialize object variables for the number of PEs and number of objects.
  Num_PEs = stats->nprocs();
  Num_Objects = stats->n_objs;

  if (_lb_args.debug() > 0) {
    CkPrintf ("[%d] GridCommRefineLB is examining %d PEs and %d objects.\n", CkMyPe(), Num_PEs, Num_Objects);
  }

  // Initialize the PE_Data[] data structure.
  Initialize_PE_Data (stats);

  // If at least one available PE does not exist, return from load balancing.
  if (Available_PE_Count() < 1) {
    if (_lb_args.debug() > 0) {
      CkPrintf ("[%d] GridCommRefineLB finds no available PEs -- no balancing done.\n", CkMyPe());
    }

    delete [] PE_Data;

    return;
  }

  // Determine the number of clusters.
  // If any PE is not mapped to a cluster, return from load balancing.
  Num_Clusters = Compute_Number_Of_Clusters ();
  if (Num_Clusters < 1) {
    if (_lb_args.debug() > 0) {
      CkPrintf ("[%d] GridCommRefineLB finds incomplete PE cluster map -- no balancing done.\n", CkMyPe());
    }

    delete [] PE_Data;

    return;
  }

  if (_lb_args.debug() > 0) {
    CkPrintf ("[%d] GridCommRefineLB finds %d clusters.\n", CkMyPe(), Num_Clusters);
  }

  // Initialize the Object_Data[] data structure.
  Initialize_Object_Data (stats);

  // Examine all object-to-object messages for intra-cluster and inter-cluster communications.
  Examine_InterObject_Messages (stats);

  // Place objects on the PE they are currently assigned to.
  Place_Objects_On_PEs ();

  // Remap objects to PEs in each cluster.
  for (i = 0; i < Num_Clusters; i++) {
    Remap_Objects_To_PEs (i);
  }

  // Make the assignment of objects to PEs in the load balancer framework.
  for (i = 0; i < Num_Objects; i++) {
    stats->to_proc[i] = (&Object_Data[i])->to_pe;

    if (_lb_args.debug() > 2) {
      CkPrintf ("[%d] GridCommRefineLB migrates object %d from PE %d to PE %d.\n", CkMyPe(), i, stats->from_proc[i], stats->to_proc[i]);
    } else if (_lb_args.debug() > 1) {
      if (stats->to_proc[i] != stats->from_proc[i]) {
	CkPrintf ("[%d] GridCommRefineLB migrates object %d from PE %d to PE %d.\n", CkMyPe(), i, stats->from_proc[i], stats->to_proc[i]);
      }
    }
  }

  // Free memory.
  delete [] Object_Data;
  delete [] PE_Data;
}
コード例 #2
0
ファイル: GridCommLB.C プロジェクト: gitter-badger/quinoa
/**************************************************************************
** The Charm++ load balancing framework invokes this method to cause the
** load balancer to migrate objects to "better" PEs.
*/
void GridCommLB::work (LDStats *stats)
{
    int i;


    if (_lb_args.debug() > 0) {
        CkPrintf ("[%d] GridCommLB is working (mode=%d, background load=%d, load tolerance=%f).\n", CkMyPe(), CK_LDB_GridCommLB_Mode, CK_LDB_GridCommLB_Background_Load, CK_LDB_GridCommLB_Load_Tolerance);
    }

    // Since this load balancer looks at communications data, it must initialize the CommHash.
    stats->makeCommHash ();

    // Initialize object variables for the number of PEs and number of objects.
    Num_PEs = stats->nprocs();
    Num_Objects = stats->n_objs;

    if (_lb_args.debug() > 0) {
        CkPrintf ("[%d] GridCommLB is examining %d PEs and %d objects.\n", CkMyPe(), Num_PEs, Num_Objects);
    }

    // Initialize the PE_Data[] data structure.
    Initialize_PE_Data (stats);

    // If at least one available PE does not exist, return from load balancing.
    if (Available_PE_Count() < 1) {
        if (_lb_args.debug() > 0) {
            CkPrintf ("[%d] GridCommLB finds no available PEs -- no balancing done.\n", CkMyPe());
        }

        delete [] PE_Data;

        return;
    }

    // Determine the number of clusters.
    // If any PE is not mapped to a cluster, return from load balancing.
    Num_Clusters = Compute_Number_Of_Clusters ();
    if (Num_Clusters < 1) {
        if (_lb_args.debug() > 0) {
            CkPrintf ("[%d] GridCommLB finds incomplete PE cluster map -- no balancing done.\n", CkMyPe());
        }

        delete [] PE_Data;

        return;
    }

    if (_lb_args.debug() > 0) {
        CkPrintf ("[%d] GridCommLB finds %d clusters.\n", CkMyPe(), Num_Clusters);
    }

    // Initialize the Object_Data[] data structure.
    Initialize_Object_Data (stats);

    // Examine all object-to-object messages for intra-cluster and inter-cluster communications.
    Examine_InterObject_Messages (stats);

    // Map non-migratable objects to PEs.
    Map_NonMigratable_Objects_To_PEs ();

    // Map migratable objects to PEs in each cluster.
    for (i = 0; i < Num_Clusters; i++) {
        Map_Migratable_Objects_To_PEs (i);
    }

    // Make the assignment of objects to PEs in the load balancer framework.
    for (i = 0; i < Num_Objects; i++) {
        stats->to_proc[i] = (&Object_Data[i])->to_pe;

        if (_lb_args.debug() > 2) {
            CkPrintf ("[%d] GridCommLB migrates object %d from PE %d to PE %d.\n", CkMyPe(), i, stats->from_proc[i], stats->to_proc[i]);
        } else if (_lb_args.debug() > 1) {
            if (stats->to_proc[i] != stats->from_proc[i]) {
                CkPrintf ("[%d] GridCommLB migrates object %d from PE %d to PE %d.\n", CkMyPe(), i, stats->from_proc[i], stats->to_proc[i]);
            }
        }
    }

    // Free memory.
    delete [] Object_Data;
    delete [] PE_Data;
}