Пример #1
0
 bool save_metis_structure(const std::string& filename,
                           const graphlab::local_graph<VertexType, EdgeType>& graph) {
   typedef graphlab::local_graph<VertexType, EdgeType> graph_type;
   typedef typename graph_type::edge_type          edge_type;
   typedef typename graph_type::edge_list_type     edge_list_type;
 
   std::ofstream fout(filename.c_str());
   if(!fout.good()) return false;
   // Count the number of actual edges
   size_t nedges = 0;
   for(vertex_id_type i = 0; i < graph.num_vertices(); ++i)
     nedges += num_neighbors(graph, i);
   fout << graph.num_vertices() << ' ' << (nedges/2) << '\n';
   // Save the adjacency structure
   std::vector<vertex_id_type> neighbor_set;
   for(vertex_id_type i = 0; i < graph.num_vertices(); ++i) {
     neighbors(graph, i, neighbor_set);
     for(size_t j = 0; j < neighbor_set.size(); ++j) {
       fout << (neighbor_set[j] + 1);
       if(j + 1 < neighbor_set.size()) fout << ' ';
     }
     fout << '\n';
   }
   fout.close();
   return true;
 } // end of save metis
Пример #2
0
void compute_neighbors(board b) {
  int i, j;
  for(i=0; i<b->height; i++) {
    for(j=0; j<b->width; j++) {
      b->cells[i][j].neighbors = num_neighbors(b, i, j);
    }
  }
}
Пример #3
0
static int migrate_graph(int num_exports, int num_imports, ZOLTAN_ID_TYPE *export_lids, ZOLTAN_ID_TYPE *import_gids)
{
  int i, j, k, nextv, nextp, npins, numNewVertices, numNewPins, sum;
  long nbors[4];
  float wgts[4];
  int rc, startlocv, startloce;
  int status = 0;

  numNewVertices = numMyVertices - num_exports + num_imports;

  for (i=0; i < num_exports; i++){
    vtxGID[export_lids[i]] = ZOLTAN_ID_INVALID;
  }

  for (i=0, nextv=0, nextp=0; i < numMyVertices; i++){
    npins = nborIndex[i+1] - nborIndex[i];
    if (vtxGID[i] != ZOLTAN_ID_INVALID){
      if (i > nextv){
        vtxGID[nextv] = vtxGID[i];
        for (j=nborIndex[i], k=0; j < nborIndex[i+1]; j++, k++){
          nborGID[nextp+k] = nborGID[j];
          edgeWgt[nextp+k] = edgeWgt[j];
          /* skip nborProc because we don't know what it is yet */
        }
        nborIndex[nextv+1] = nborIndex[nextv] + npins;
      }

      nextv++;
      nextp += npins;
    }
  }

  numNewPins = nextp;

  startlocv = nextv;
  startloce = nextp;

  for (i=0; i < num_imports; i++){
    numNewPins += num_neighbors(import_gids[i]);
  }

  status = reallocate_buffers(numNewVertices, numNewPins);

  if (status == 0){
    for (i=0; i < num_imports; i++, nextv++){
      vtxGID[nextv] = import_gids[i];
      sum = get_nbor_info(import_gids[i], nbors, wgts);

      for (j=0; j < sum; j++, nextp++){
        nborGID[nextp] = (ZOLTAN_ID_TYPE)nbors[j];
        edgeWgt[nextp] = wgts[j];
      }
      nborIndex[nextv+1] = nborIndex[nextv] + sum;
    }
  }
  else{
    fprintf(stderr,"memory allocation failure in reallocate buffers\n");
    return 1;
  }

  numMyVertices = numNewVertices;
  numMyPins = numNewPins;

  rc = Zoltan_DD_Update(dd, vtxGID+startlocv, NULL, NULL, NULL, num_imports);

  if ((rc != ZOLTAN_OK) && (rc != ZOLTAN_WARN)){
    status = 1;
  }

  rc = Zoltan_DD_Find(dd, nborGID+startloce, NULL, NULL, NULL, numNewPins - startloce, nborProc+startloce);

  if ((rc != ZOLTAN_OK) && (rc != ZOLTAN_WARN)){
    status = 1;
  }

  return status;
}
Пример #4
0
static int create_a_graph()
{
  int rc, i, sum, n, j;
  float wgts[4];
  long gid, nbors[4], count[2];
  ldiv_t result;
  float c;

  c = sqrt((float)numGlobalVertices);

  c = (c < 3.0) ? 3.0 : c;

  cylCount = cylSize = (long)c;

  numGlobalVertices = cylCount * cylSize;

  result = ldiv(numGlobalVertices, (long)numProcs);

  numMyVertices = (int)result.quot + (myRank < result.rem ? 1 : 0);

  count[0] = (long)numMyVertices;

  MPI_Scan(count+0, count+1, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);

  myFirstGID = count[1] - count[0];

  numMyPins = 0;

  for (i=0, gid = myFirstGID; i < numMyVertices; i++, gid++){
    numMyPins += num_neighbors(gid);
  }

  vtxGID = (ZOLTAN_ID_TYPE *)malloc(sizeof(ZOLTAN_ID_TYPE) * numMyVertices);
  nborIndex = (int *)malloc(sizeof(int) * (numMyVertices + 1));
  nborGID = (ZOLTAN_ID_TYPE *)malloc(sizeof(ZOLTAN_ID_TYPE) * numMyPins);
  nborProc = (int *)malloc(sizeof(int) * numMyPins);
  edgeWgt = (float *)malloc(sizeof(float) * numMyPins);

  if (numMyPins && !(vtxGID || nborIndex || nborGID || nborProc || edgeWgt)){
    fprintf(stderr,"%d out of memory\n",myRank);
    return 1;
  }

  nborIndex[0] = 0;

  for (i=0, gid=myFirstGID, n=0; i < numMyVertices; i++, gid++){
    vtxGID[i] = (ZOLTAN_ID_TYPE)gid;
    sum = get_nbor_info(gid, nbors, wgts);

    for (j=0; j < sum; j++, n++){
      nborGID[n] = (ZOLTAN_ID_TYPE)nbors[j];
      edgeWgt[n] = wgts[j];

      if (nborGID[n] < myFirstGID)
        nborProc[n] = myRank - 1;
      else if (nborGID[n] >= myFirstGID + numMyVertices)
        nborProc[n] = myRank + 1;
      else
        nborProc[n] = myRank;
    }
    nborIndex[i+1] = nborIndex[i] + sum;
  }

  rc = Zoltan_DD_Create(&dd, MPI_COMM_WORLD, 1, 0, 0, (int)(numGlobalVertices / numProcs), 0);

  if ((rc != ZOLTAN_OK) && (rc != ZOLTAN_WARN)){
    fprintf(stderr,"%d DD Create failure\n",myRank);
    MPI_Abort(MPI_COMM_WORLD, 1);
  }

  rc = Zoltan_DD_Update(dd, vtxGID, NULL, NULL, NULL, numMyVertices);

  if ((rc != ZOLTAN_OK) && (rc != ZOLTAN_WARN)){
    fprintf(stderr,"%d DD Update failure in create\n",myRank);
    return 1;
  }

  return 0;
}