예제 #1
0
파일: tm_mapping.c 프로젝트: 00datman/ompi
int nb_leaves(tree_t *comm_tree)
{
  int j,n=0;

  if(!comm_tree->child)
    return 1;

  for( j = 0 ; j < comm_tree->arity ; j++)
    n += nb_leaves(comm_tree->child[j]);

  return n;
}
예제 #2
0
int nb_leaves(tree_t *comm_tree){
  int n=0,j;

  if(!comm_tree->child){
    return 1;
  }

  for(j=0;j<comm_tree->arity;j++){
    n+=nb_leaves(comm_tree->child[j]);
  }
  return n;
}
예제 #3
0
int EmbedPolyline(TopologicalGraph &G)
  {if(G.nv() < 3 || G.ne() < 2)return -1;
  int OldNumEdge = G.ne();
  PSet1  propSave(G.Set());
  G.MakeConnected();
  if(!G.FindPlanarMap() )
      {Tprintf("Not Planar Graph");
      for(tedge e = G.ne(); e > OldNumEdge; e--) G.DeleteEdge(e);
      return -1;
      }
 tbrin FirstBrin = 1;
  bool MaxPlanar = (G.ne() != 3 * G.nv() - 6) ? false : true;
  int len;
  if(!FirstBrin && !MaxPlanar)
      G.LongestFace(FirstBrin,len);
  else if(FirstBrin == 0)
      {FirstBrin = G.extbrin();FirstBrin = -G.acir[FirstBrin];}

  if(!MaxPlanar && G.ZigZagTriangulate())return -2;
  svector<short> ecolor(1, G.ne());
  SchnyderDecomp(G,FirstBrin,ecolor);
  GeometricGraph G0(G);
  
  //Compute trees 
  tedge ee;
  Prop<Tpoint> Ebend(G.Set(tedge()),PROP_DRAW_POINT_3);
  
  svector<tbrin> FatherB(1,G.nv(),(tbrin)0);           FatherB.SetName("FatherB");
  svector<tbrin> FatherG(1,G.nv(),(tbrin)0);           FatherG.SetName("FatherG");
  svector<tbrin> FatherR(1,G.nv(),(tbrin)0);           FatherR.SetName("FatherR");
  svector<int> x(1,G.nv(),0), y(1,G.nv(),0);
  x.clear(); y.clear();
  compute_parents(G0, Blue, -FirstBrin, FatherB, ecolor);
  compute_parents(G0, Red, FirstBrin, FatherR, ecolor);
  compute_parents(G0, Green, -G0.acir[FirstBrin], FatherG, ecolor);
  // Compute the number of leaves of each tree
  int nb_leavesB, nb_leavesR, nb_leavesG;
  nb_leavesB = nb_leaves(G0, Blue, -FirstBrin, ecolor);
  nb_leavesR = nb_leaves(G0, Red, FirstBrin, ecolor);
  nb_leavesG = nb_leaves(G0, Green, -G0.acir[FirstBrin], ecolor);

    // Compute the coordinates using the tree with the minimum number of leaves
  ForAllEdges(ee, G) Ebend[ee] = Tpoint(-1,-1);
  if (nb_leavesB <= nb_leavesR && nb_leavesB <= nb_leavesG) 
      compute_coords(G0,Red,Blue,-FirstBrin,FatherB,FatherR,FatherG,ecolor,x,y,Ebend);
  else if (nb_leavesR <= nb_leavesG) 
      compute_coords(G0,Green,Red,G0.acir[FirstBrin],FatherR,FatherG,FatherB,ecolor,x,y,Ebend);
  else 
      compute_coords(G0,Blue,Green,G0.acir[-G0.acir[FirstBrin]],FatherG,FatherB,FatherR,ecolor,x,y,Ebend);
  // computes extremities of vertices
  Prop<Tpoint> Epoint1(G.Set(tedge()),PROP_DRAW_POINT_1);
  Prop<Tpoint> Epoint2(G.Set(tedge()),PROP_DRAW_POINT_2);
  Prop<Tpoint> Vcoord(G.Set(tvertex()),PROP_DRAW_POINT_1);
  G.Set() =  propSave;
  Prop1<Tpoint> pmin(G.Set(),PROP_POINT_MIN);
  Prop1<Tpoint> pmax(G.Set(),PROP_POINT_MAX);  
  tvertex vv;
  pmin() = Tpoint(0,0);
  pmax() = Tpoint(0,0);
  ForAllVertices(vv, G0) 
   {Vcoord[vv] = Tpoint(x[vv], y[vv]);
   if (Vcoord[vv].x() > pmax().x())
       pmax().x() = Vcoord[vv].x();
   if (Vcoord[vv].y() > pmax().y())
       pmax().y() = Vcoord[vv].y();
   }
예제 #4
0
파일: tm_mapping.c 프로젝트: 00datman/ompi
void map_topology(tm_topology_t *topology,tree_t *comm_tree,int nb_compute_units,
                  int level,int *sigma, int nb_processes, int *k)
{
    int *nodes_id = NULL;
    int *proc_list = NULL;
    int i,N,M,block_size;
    unsigned int vl = get_verbose_level();

    M = nb_leaves(comm_tree);
    nodes_id = topology->node_id[level];
    N = topology->nb_nodes[level];

    if(vl >= INFO){
        printf("nb_leaves=%d\n",M);
        printf("level=%d, nodes_id=%p, N=%d\n",level,(void *)nodes_id,N);
        printf("N=%d,nb_compute_units=%d\n",N,nb_compute_units);
    }

    /* The number of node at level "level" in the tree should be equal to the number of processors*/
    assert(N==nb_compute_units);

    proc_list = (int*)MALLOC(sizeof(int)*M);
    i = 0;
    depth_first(comm_tree,proc_list,&i);

    if(vl >= DEBUG)
        for(i=0;i<M;i++){
            printf ("%d\n",proc_list[i]);
        }

    block_size = M/N;

    if(k){/*if we need the k vector*/
        if(vl >= INFO)
            printf("M=%d, N=%d, BS=%d\n",M,N,block_size);
        for( i = 0 ; i < nb_processing_units(topology) ; i++ )
            k[i] = -1;

        for( i = 0 ; i < M ; i++ )
            if(proc_list[i] != -1){
                if(vl >= DEBUG)
                    printf ("%d->%d\n",proc_list[i],nodes_id[i/block_size]);

                if( proc_list[i] < nb_processes ){
                    sigma[proc_list[i]] = nodes_id[i/block_size];
                    k[nodes_id[i/block_size]] = proc_list[i];
                }
            }
    }else{
        if(vl >= INFO)
            printf("M=%d, N=%d, BS=%d\n",M,N,block_size);
        for( i = 0 ; i < M ; i++ )
            if(proc_list[i] != -1){
                if(vl >= DEBUG)
                    printf ("%d->%d\n",proc_list[i],nodes_id[i/block_size]);
                if( proc_list[i] < nb_processes )
                    sigma[proc_list[i]] = nodes_id[i/block_size];
            }
    }

    if((vl >= DEBUG) && (k)){
        printf("k: ");
        for( i = 0 ; i < nb_processing_units(topology) ; i++ )
            printf("%d ",k[i]);
        printf("\n");
    }


    FREE(proc_list);
}
예제 #5
0
/*Map topology to cores: 
 sigma_i is such that  process i is mapped on core sigma_i
 k_i is such that core i exectutes process k_i

 size of sigma is the number of process
 size of k is the number of cores/nodes

 We must have numbe of process<=number of cores

 k_i =-1 if no process is mapped on core i
*/
void map_topology(tm_topology_t *topology,tree_t *comm_tree,int nb_proc,int level,
		  int *sigma, int *k){
  int *nodes_id;
  int N;
  int *proc_list,i,l;
  int M;
  int block_size;

 
  M=nb_leaves(comm_tree);
  printf("nb_leaves=%d\n",M);



  nodes_id=topology->node_id[level];
  N=topology->nb_nodes[level];
  //printf("level=%d, nodes_id=%p, N=%d\n",level,nodes_id,N);


  //printf("N=%d,nb_proc=%d\n",N,nb_proc);
  /* The number of node at level "level" in the tree should be equal to the number of processors*/
  assert(N==nb_proc);


  proc_list=(int*)malloc(sizeof(int)*M);
  i=0;
  depth_first(comm_tree,proc_list,&i);

  l=0;
  for(i=0;i<M;i++){
    //printf ("%d\n",proc_list[i]);
  }


  block_size=M/N;


  if(k){/*if we need the k vector*/
    printf("M=%d, N=%d, BS=%d\n",M,N,block_size);
    for(i=0;i<nb_nodes(topology);i++){
      k[i]=-1;
    }
    for(i=0;i<M;i++){
      if(proc_list[i]!=-1){
#ifdef DEBUG
	printf ("%d->%d\n",proc_list[i],nodes_id[i/block_size]);
#endif
	sigma[proc_list[i]]=nodes_id[i/block_size];
	k[nodes_id[i/block_size]]=proc_list[i];
      }
    }
  }else{
    printf("M=%d, N=%d, BS=%d\n",M,N,block_size);
    for(i=0;i<M;i++){
      if(proc_list[i]!=-1){
#ifdef DEBUG
	printf ("%d->%d\n",proc_list[i],nodes_id[i/block_size]);
#endif
	sigma[proc_list[i]]=nodes_id[i/block_size];
      }
    }

  }
  free(proc_list);

}