Esempio n. 1
0
int setup_zoltan(struct Zoltan_Struct *zz, Matrix A)
{
  /* Set the load-balance method */
  /* You can change "RCB" to any Zoltan method below. */

  if (Zoltan_Set_Param(zz, "LB_METHOD", "RCB") == ZOLTAN_FATAL) {
    printf("fatal:  error returned from Zoltan_Set_Param(LB_METHOD)\n");
    return 0;
  }

  /*
   * Set the callback functions
   */

  if (Zoltan_Set_Fn(zz, ZOLTAN_NUM_OBJ_FN_TYPE, (void (*)()) get_num_entries,
                    (void *) &A) == ZOLTAN_FATAL) {
    printf("fatal:  error returned from Zoltan_Set_Fn()\n");
    return 0;
  }

  if (Zoltan_Set_Fn(zz, ZOLTAN_OBJ_LIST_FN_TYPE,
                    (void (*)()) get_entries,
                    (void *) &A) == ZOLTAN_FATAL) {
    printf("fatal:  error returned from Zoltan_Set_Fn()\n");
    return 0;
  }

  /* Functions for geometry based algorithms */
  if (Zoltan_Set_Fn(zz, ZOLTAN_NUM_GEOM_FN_TYPE, (void (*)()) get_num_geom,
                    (void *) &A) == ZOLTAN_FATAL) {
    printf("fatal:  error returned from Zoltan_Set_Fn()\n");
    return 0;
  }

  if (Zoltan_Set_Fn(zz, ZOLTAN_GEOM_MULTI_FN_TYPE,
                    (void (*)()) get_geom_multi,
                    (void *) &A) == ZOLTAN_FATAL) {
    printf("fatal:  error returned from Zoltan_Set_Fn()\n");
    return 0;
  }

#ifdef USE_GRAPH
  /* Functions for graph based algorithms */
  /* These two functions are needed to use ParMETIS thru Zoltan. */
  /* They are not needed for geometric methods. */
  if (Zoltan_Set_Fn(zz, ZOLTAN_NUM_EDGES_MULTI_FN_TYPE,
                    (void (*)()) get_num_edges_multi,
                    (void *) &A) == ZOLTAN_FATAL) {
    printf("fatal:  error returned from Zoltan_Set_Fn()\n");
    return 0;
  }
  if (Zoltan_Set_Fn(zz, ZOLTAN_EDGE_LIST_MULTI_FN_TYPE,
                    (void (*)()) get_edge_list_multi,
                    (void *) &A) == ZOLTAN_FATAL) {
    printf("fatal:  error returned from Zoltan_Set_Fn()\n");
    return 0;
  }
#endif /* USE_GRAPH */

  return 1;
}
Esempio n. 2
0
int migrate_elements(
    int Proc,
    MESH_INFO_PTR mesh,
    struct Zoltan_Struct *zz,
    int num_gid_entries,
    int num_lid_entries,
    int num_imp,
    ZOLTAN_ID_PTR imp_gids,
    ZOLTAN_ID_PTR imp_lids,
    int *imp_procs,
    int *imp_to_part,
    int num_exp,
    ZOLTAN_ID_PTR exp_gids,
    ZOLTAN_ID_PTR exp_lids,
    int *exp_procs,
    int *exp_to_part)
{
    /* Local declarations. */
    char *yo = "migrate_elements";

    /***************************** BEGIN EXECUTION ******************************/
    DEBUG_TRACE_START(Proc, yo);

    /*
     * register migration functions
     */
    if (!Test.Null_Lists) {
        /* If not passing NULL lists, let Help_Migrate call the
         * pre-processing and post-processing routines.
         */
        if (Zoltan_Set_Fn(zz, ZOLTAN_PRE_MIGRATE_PP_FN_TYPE,
                          (void (*)()) migrate_pre_process,
                          (void *) mesh) == ZOLTAN_FATAL) {
            Gen_Error(0, "fatal:  error returned from Zoltan_Set_Fn()\n");
            return 0;
        }

        if (Zoltan_Set_Fn(zz, ZOLTAN_POST_MIGRATE_PP_FN_TYPE,
                          (void (*)()) migrate_post_process,
                          (void *) mesh) == ZOLTAN_FATAL) {
            Gen_Error(0, "fatal:  error returned from Zoltan_Set_Fn()\n");
            return 0;
        }
    }

    if (Test.Multi_Callbacks) {
        if (Zoltan_Set_Fn(zz, ZOLTAN_OBJ_SIZE_MULTI_FN_TYPE,
                          (void (*)()) migrate_elem_size_multi,
                          (void *) mesh) == ZOLTAN_FATAL) {
            Gen_Error(0, "fatal:  error returned from Zoltan_Set_Fn()\n");
            return 0;
        }

        if (Zoltan_Set_Fn(zz, ZOLTAN_PACK_OBJ_MULTI_FN_TYPE,
                          (void (*)()) migrate_pack_elem_multi,
                          (void *) mesh) == ZOLTAN_FATAL) {
            Gen_Error(0, "fatal:  error returned from Zoltan_Set_Fn()\n");
            return 0;
        }

        if (Zoltan_Set_Fn(zz, ZOLTAN_UNPACK_OBJ_MULTI_FN_TYPE,
                          (void (*)()) migrate_unpack_elem_multi,
                          (void *) mesh) == ZOLTAN_FATAL) {
            Gen_Error(0, "fatal:  error returned from Zoltan_Set_Fn()\n");
            return 0;
        }
    }
    else {
        if (Zoltan_Set_Fn(zz, ZOLTAN_OBJ_SIZE_FN_TYPE,
                          (void (*)()) migrate_elem_size,
                          (void *) mesh) == ZOLTAN_FATAL) {
            Gen_Error(0, "fatal:  error returned from Zoltan_Set_Fn()\n");
            return 0;
        }

        if (Zoltan_Set_Fn(zz, ZOLTAN_PACK_OBJ_FN_TYPE,
                          (void (*)()) migrate_pack_elem,
                          (void *) mesh) == ZOLTAN_FATAL) {
            Gen_Error(0, "fatal:  error returned from Zoltan_Set_Fn()\n");
            return 0;
        }

        if (Zoltan_Set_Fn(zz, ZOLTAN_UNPACK_OBJ_FN_TYPE,
                          (void (*)()) migrate_unpack_elem,
                          (void *) mesh) == ZOLTAN_FATAL) {
            Gen_Error(0, "fatal:  error returned from Zoltan_Set_Fn()\n");
            return 0;
        }
    }


    if (Test.Null_Lists == NONE) {
        if (Zoltan_Migrate(zz, num_imp, imp_gids, imp_lids, imp_procs, imp_to_part,
                           num_exp, exp_gids, exp_lids, exp_procs, exp_to_part)
                == ZOLTAN_FATAL) {
            Gen_Error(0, "fatal:  error returned from Zoltan_Migrate()\n");
            return 0;
        }
    }
    else {
        /* Call Zoltan_Help_Migrate with empty import lists. */
        /* Have to "manually" call migrate_pre_process and migrate_post_process. */
        int ierr = 0;
        migrate_pre_process((void *) mesh, 1, 1,
                            num_imp, imp_gids, imp_lids, imp_procs, imp_to_part,
                            num_exp, exp_gids, exp_lids, exp_procs, exp_to_part,
                            &ierr);
        if (Test.Null_Lists == IMPORT_LISTS) {
            if (Zoltan_Migrate(zz,
                               -1, NULL, NULL, NULL, NULL,
                               num_exp, exp_gids, exp_lids, exp_procs, exp_to_part)
                    == ZOLTAN_FATAL) {
                Gen_Error(0, "fatal:  error returned from Zoltan_Migrate()\n");
                return 0;
            }
        }
        else {
            if (Zoltan_Migrate(zz,
                               num_imp, imp_gids, imp_lids, imp_procs, imp_to_part,
                               -1, NULL, NULL, NULL, NULL)
                    == ZOLTAN_FATAL) {
                Gen_Error(0, "fatal:  error returned from Zoltan_Migrate()\n");
                return 0;
            }
        }
        migrate_post_process((void *) mesh, 1, 1,
                             num_imp, imp_gids, imp_lids, imp_procs, imp_to_part,
                             num_exp, exp_gids, exp_lids, exp_procs, exp_to_part,
                             &ierr);
    }

    DEBUG_TRACE_END(Proc, yo);
    return 1;

}