Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
complete reorganisation of examples/smpi/NAS
[simgrid.git] / examples / smpi / NAS / DGraph.c
similarity index 82%
rename from examples/smpi/NAS/DT/DGraph.c
rename to examples/smpi/NAS/DGraph.c
index f573786..6dd0ed3 100644 (file)
@@ -31,8 +31,7 @@ DGNode *newNode(char *nm){
   return nd;
 }
 void nodeShow(DGNode* nd){
-  fprintf( stderr,"%3d.%s: (%d,%d)\n",
-             nd->id,nd->name,nd->inDegree,nd->outDegree);
+  fprintf( stderr,"%3d.%s: (%d,%d)\n", nd->id,nd->name,nd->inDegree,nd->outDegree);
 /*
   if(nd->verified==1) fprintf(stderr,"%ld.%s\t: usable.",nd->id,nd->name);
   else if(nd->verified==0)  fprintf(stderr,"%ld.%s\t: unusable.",nd->id,nd->name);
@@ -51,6 +50,7 @@ DGraph* newDGraph(char* nm){
   dg->name=strdup(nm);
   return dg;
 }
+
 int AttachNode(DGraph* dg, DGNode* nd) {
   int i=0,j,len=0;
   DGNode **nds =NULL, *tmpnd=NULL;
@@ -58,13 +58,13 @@ int AttachNode(DGraph* dg, DGNode* nd) {
 
   if (dg->numNodes == dg->maxNodes-1 ) {
     dg->maxNodes += BLOCK_SIZE;
-          nds =(DGNode **) calloc(dg->maxNodes,sizeof(DGNode*));
+    nds =(DGNode **) calloc(dg->maxNodes,sizeof(DGNode*));
     memcpy(nds,dg->node,(dg->maxNodes-BLOCK_SIZE)*sizeof(DGNode*));
     free(dg->node);
     dg->node=nds;
   }
 
-        len = strlen( nd->name);
+  len = strlen( nd->name);
   for (i = 0; i < dg->numNodes; i++) {
     tmpnd =dg->node[ i];
     ar=NULL;
@@ -72,7 +72,7 @@ int AttachNode(DGraph* dg, DGNode* nd) {
     if ( strncmp( nd->name, tmpnd->name, len) ) continue;
     if ( nd->inDegree > 0 ) {
       tmpnd->maxInDegree += nd->maxInDegree;
-            ar =(DGArc **) calloc(tmpnd->maxInDegree,sizeof(DGArc*));
+      ar =(DGArc **) calloc(tmpnd->maxInDegree,sizeof(DGArc*));
       memcpy(ar,tmpnd->inArc,(tmpnd->inDegree)*sizeof(DGArc*));
       free(tmpnd->inArc);
       tmpnd->inArc=ar;
@@ -84,60 +84,58 @@ int AttachNode(DGraph* dg, DGNode* nd) {
     }   
     if ( nd->outDegree > 0 ) {
       tmpnd->maxOutDegree += nd->maxOutDegree;
-            ar =(DGArc **) calloc(tmpnd->maxOutDegree,sizeof(DGArc*));
+      ar =(DGArc **) calloc(tmpnd->maxOutDegree,sizeof(DGArc*));
       memcpy(ar,tmpnd->outArc,(tmpnd->outDegree)*sizeof(DGArc*));
       free(tmpnd->outArc);
       tmpnd->outArc=ar;
       for (j = 0; j < nd->outDegree; j++ ) {
         nd->outArc[ j]->tail = tmpnd;
-      }      
+      }
       memcpy( &(tmpnd->outArc[tmpnd->outDegree]),nd->outArc,nd->outDegree*sizeof( DGArc *));
       tmpnd->outDegree += nd->outDegree;
-    } 
+    }
     free(nd); 
     return i;
   }
   nd->id = dg->numNodes;
   dg->node[dg->numNodes] = nd;
   dg->numNodes++;
-return nd->id;
+  return nd->id;
 }
+
 int AttachArc(DGraph *dg,DGArc* nar){
-int  arcId = -1;
-int i=0,newNumber=0;
-DGNode  *head = nar->head,
-  *tail = nar->tail; 
-DGArc **ars=NULL,*probe=NULL;
-/*fprintf(stderr,"AttachArc %ld\n",dg->numArcs); */
+  int  arcId = -1;
+  int i=0,newNumber=0;
+  DGNode  *head = nar->head,
+          *tail = nar->tail;
+  DGArc **ars=NULL,*probe=NULL;
+  /*fprintf(stderr,"AttachArc %ld\n",dg->numArcs); */
   if ( !tail || !head ) return arcId;
   if ( dg->numArcs == dg->maxArcs-1 ) {
     dg->maxArcs += BLOCK_SIZE;
-          ars =(DGArc **) calloc(dg->maxArcs,sizeof(DGArc*));
+    ars =(DGArc **) calloc(dg->maxArcs,sizeof(DGArc*));
     memcpy(ars,dg->arc,(dg->maxArcs-BLOCK_SIZE)*sizeof(DGArc*));
     free(dg->arc);
     dg->arc=ars;
   }
   for(i = 0; i < tail->outDegree; i++ ) { /* parallel arc */
     probe = tail->outArc[ i];
-    if(probe->head == head
-       &&
-       probe->length == nar->length
-            ){
-            free(nar);
-      return probe->id;   
+    if(probe->head == head && probe->length == nar->length){
+      free(nar);
+      return probe->id;
     }
   }
-  
+
   nar->id = dg->numArcs;
   arcId=dg->numArcs;
   dg->arc[dg->numArcs] = nar;
   dg->numArcs++;
-  
+
   head->inArc[ head->inDegree] = nar;
   head->inDegree++;
   if ( head->inDegree >= head->maxInDegree ) {
     newNumber = head->maxInDegree + SMALL_BLOCK_SIZE;
-          ars =(DGArc **) calloc(newNumber,sizeof(DGArc*));
+    ars =(DGArc **) calloc(newNumber,sizeof(DGArc*));
     memcpy(ars,head->inArc,(head->inDegree)*sizeof(DGArc*));
     free(head->inArc);
     head->inArc=ars;
@@ -147,15 +145,16 @@ DGArc **ars=NULL,*probe=NULL;
   tail->outDegree++;
   if(tail->outDegree >= tail->maxOutDegree ) {
     newNumber = tail->maxOutDegree + SMALL_BLOCK_SIZE;
-          ars =(DGArc **) calloc(newNumber,sizeof(DGArc*));
+    ars =(DGArc **) calloc(newNumber,sizeof(DGArc*));
     memcpy(ars,tail->outArc,(tail->outDegree)*sizeof(DGArc*));
     free(tail->outArc);
     tail->outArc=ars;
     tail->maxOutDegree = newNumber;
   }
 /*fprintf(stderr,"AttachArc: head->in=%d tail->out=%ld\n",head->inDegree,tail->outDegree);*/
-return arcId;
+  return arcId;
 }
+
 void graphShow(DGraph *dg,int DetailsLevel){
   int i=0,j=0;
   fprintf(stderr,"%d.%s: (%d,%d)\n",dg->id,dg->name,dg->numNodes,dg->numArcs);
@@ -164,8 +163,8 @@ void graphShow(DGraph *dg,int DetailsLevel){
     DGNode *focusNode = dg->node[ i];
     if(DetailsLevel >= 2) {
       for (j = 0; j < focusNode->inDegree; j++ ) {
-  fprintf(stderr,"\t ");
-  nodeShow(focusNode->inArc[ j]->tail);
+        fprintf(stderr,"\t ");
+        nodeShow(focusNode->inArc[ j]->tail);
       }
     }
     nodeShow(focusNode);
@@ -173,12 +172,9 @@ void graphShow(DGraph *dg,int DetailsLevel){
     for (j = 0; j < focusNode->outDegree; j++ ) {
       fprintf(stderr, "\t ");
       nodeShow(focusNode->outArc[ j]->head);
-    }  
+    }
     fprintf(stderr, "---\n");
   }
   fprintf(stderr,"----------------------------------------\n");
   if ( DetailsLevel < 3) return;
 }
-
-
-