00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <math.h>
00013 #include <stdlib.h>
00014 #include "TopoLB.decl.h"
00015 #include "TopoLB.h"
00016
00017 #define alpha PER_MESSAGE_SEND_OVERHEAD_DEFAULT
00018 #define beta PER_BYTE_SEND_OVERHEAD_DEFAULT
00019 #define DEG_THRES 0.50
00020 #define EPSILON -0.001
00021
00022 #define _lb_debug_on 0
00023 #define _lb_debug2_on 0
00024 #define _make_new_grouping_ 0
00025 #define _FASTER_
00026 #define _DIJKSTRA_LIKE_ 0
00027 #define _INIT_FROM_FILE
00028
00029
00030 CreateLBFunc_Def(TopoLB,"TopoLB: Balance objects based on the network topology")
00031
00032
00033 TopoLB::TopoLB(const CkLBOptions &opt) : CentralLB (opt)
00034 {
00035 lbname = "TopoLB";
00036 if (CkMyPe () == 0) {
00037 CkPrintf ("[%d] TopoLB created\n",CkMyPe());
00038 }
00039 }
00040
00041 CmiBool TopoLB::QueryBalanceNow (int _step)
00042 {
00043 return CmiTrue;
00044 }
00045
00046 void TopoLB::freeDataStructures(int count)
00047 {
00048 for(int i=0;i<count;i++)
00049 {
00050 delete[] hopBytes[i];
00051 delete[] dist[i];
00052 delete[] comm[i];
00053 }
00054 delete[] comm;
00055 delete[] hopBytes;
00056 delete[] dist;
00057 delete[] pfree;
00058 delete[] cfree;
00059 delete[] commUA;
00060 delete[] assign;
00061 }
00062
00063 void TopoLB::allocateDataStructures(int count )
00064 {
00065 int i;
00066
00067 hopBytes=new double*[count];
00068 for(i=0;i<count;i++)
00069 {
00070 hopBytes[i]=new double[count+2];
00071 }
00072
00073 dist=new double*[count];
00074 for(i=0;i<count;i++)
00075 {
00076 dist[i]=new double[count+1];
00077 }
00078
00079 comm=new double*[count];
00080 for(i=0;i<count;i++)
00081 {
00082 comm[i]=new double[count];
00083 }
00084
00085 commUA=new double[count];
00086 pfree=new bool[count];
00087 cfree=new bool[count];
00088 assign=new int[count];
00089 }
00090
00091
00092 void TopoLB::computePartitions(CentralLB::LDStats *stats,int count,int *newmap)
00093 {
00094 int numobjs = stats->n_objs;
00095 int i, j, m;
00096
00097
00098 double *objtime = new double[numobjs];
00099 int *objwt = new int[numobjs];
00100 int *origmap = new int[numobjs];
00101 LDObjHandle *handles = new LDObjHandle[numobjs];
00102
00103 for(i=0;i<numobjs;i++) {
00104 objtime[i] = 0.0;
00105 objwt[i] = 0;
00106 origmap[i] = 0;
00107 }
00108
00109 for (i=0; i<stats->n_objs; i++) {
00110 LDObjData &odata = stats->objData[i];
00111 if (!odata.migratable)
00112 CmiAbort("MetisLB doesnot dupport nonmigratable object.\n");
00113 int frompe = stats->from_proc[i];
00114 origmap[i] = frompe;
00115 objtime[i] = odata.wallTime*stats->procs[frompe].pe_speed;
00116 handles[i] = odata.handle;
00117 }
00118
00119
00120 double max_objtime = objtime[0];
00121 for(i=0; i<numobjs; i++) {
00122 if(max_objtime < objtime[i])
00123 max_objtime = objtime[i];
00124 }
00125 int maxobj=0;
00126 int totalwt=0;
00127 double ratio = 1000.0/max_objtime;
00128 for(i=0; i<numobjs; i++) {
00129 objwt[i] = (int)(objtime[i]*ratio);
00130 if(maxobj<objwt[i])
00131 maxobj=objwt[i];
00132 totalwt+=objwt[i];
00133 }
00134
00135
00136
00137 int **comm = new int*[numobjs];
00138 for (i=0; i<numobjs; i++) {
00139 comm[i] = new int[numobjs];
00140 for (j=0; j<numobjs; j++) {
00141 comm[i][j] = 0;
00142 }
00143 }
00144
00145 const int csz = stats->n_comm;
00146 for(i=0; i<csz; i++) {
00147 LDCommData &cdata = stats->commData[i];
00148
00149
00150 if(!cdata.from_proc() && cdata.receiver.get_type() == LD_OBJ_MSG){
00151 int senderID = stats->getHash(cdata.sender);
00152 int recverID = stats->getHash(cdata.receiver.get_destObj());
00153 CmiAssert(senderID < numobjs);
00154 CmiAssert(recverID < numobjs);
00155
00156
00157
00158 comm[senderID][recverID] += cdata.messages;
00159 comm[recverID][senderID] += cdata.messages;
00160
00161
00162 }
00163 else if (cdata.receiver.get_type() == LD_OBJLIST_MSG) {
00164
00165 int nobjs;
00166 LDObjKey *objs = cdata.receiver.get_destObjs(nobjs);
00167 int senderID = stats->getHash(cdata.sender);
00168 for (j=0; j<nobjs; j++) {
00169 int recverID = stats->getHash(objs[j]);
00170 if((senderID == -1)||(recverID == -1))
00171 if (_lb_args.migObjOnly()) continue;
00172 else CkAbort("Error in search\n");
00173 comm[senderID][recverID] += cdata.messages;
00174 comm[recverID][senderID] += cdata.messages;
00175 }
00176 }
00177 }
00178
00179
00180 for (i=0; i<numobjs; i++)
00181 comm[i][i] = 0;
00182
00183
00184 int *xadj = new int[numobjs+1];
00185 int numedges = 0;
00186 for(i=0;i<numobjs;i++) {
00187 for(j=0;j<numobjs;j++) {
00188 if(comm[i][j] != 0)
00189 numedges++;
00190 }
00191 }
00192 int *adjncy = new int[numedges];
00193 int *edgewt = new int[numedges];
00194 int factor = 10;
00195 xadj[0] = 0;
00196 int count4all = 0;
00197 for (i=0; i<numobjs; i++) {
00198 for (j=0; j<numobjs; j++) {
00199 if (comm[i][j] != 0) {
00200 adjncy[count4all] = j;
00201 edgewt[count4all++] = comm[i][j]/factor;
00202 }
00203 }
00204 xadj[i+1] = count4all;
00205 }
00206
00207
00208
00209
00210
00211
00212 int wgtflag = 3;
00213 int numflag = 0;
00214 int options[5];
00215 int edgecut;
00216 options[0] = 0;
00217
00218 if (count < 1) {
00219 CkPrintf("error: Number of Pe less than 1!");
00220 }
00221 else if (count == 1) {
00222 for(m=0;m<numobjs;m++)
00223 newmap[i] = origmap[i];
00224 }
00225 else {
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 METIS_PartGraphRecursive(&numobjs, xadj, adjncy, objwt, edgewt,
00238 &wgtflag, &numflag, &count, options,
00239 &edgecut, newmap);
00240
00241 }
00242
00243
00244
00245
00246
00247
00248 for(i=0;i<numobjs;i++)
00249 delete[] comm[i];
00250 delete[] comm;
00251 delete[] objtime;
00252 delete[] xadj;
00253 delete[] adjncy;
00254 delete[] objwt;
00255 delete[] edgewt;
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00279
00280
00281
00282
00283
00284
00285
00286 delete[] origmap;
00287 }
00288
00289 void TopoLB::initDataStructures(CentralLB::LDStats *stats,int count,int *newmap)
00290 {
00291 int i;
00292
00293 if(_lb_debug_on)
00294 CkPrintf("Before initing dist\n");
00295
00296 topo->get_pairwise_hop_count(dist);
00297
00298
00299
00300
00301
00302 for(i=0;i<count;i++)
00303 {
00304 double totaldist=0;
00305 for(int j=0;j<count;j++)
00306 {
00307
00308 totaldist+=dist[i][j];
00309 }
00310 dist[i][count]=totaldist/(count-1);
00311 }
00312
00313
00314 stats->makeCommHash();
00315 if(_lb_debug_on)
00316 CkPrintf("Before initing comm\n");
00317 for(i=0;i<count;i++)
00318 {
00319 for(int j=0;j<count;j++)
00320 {
00321 comm[i][j]=0;
00322 }
00323 commUA[i]=0;
00324 }
00325 bool *multicastAdded=new bool[count];
00326 for(i=0;i<stats->n_comm;i++)
00327 {
00328 LDCommData &cdata=stats->commData[i];
00329 if(!cdata.from_proc() && cdata.receiver.get_type() ==LD_OBJ_MSG)
00330 {
00331 int sender=stats->getHash(cdata.sender);
00332 int receiver=stats->getHash(cdata.receiver.get_destObj());
00333
00334 CmiAssert(sender<stats->n_objs);
00335 CmiAssert(receiver<stats->n_objs);
00336
00337 if(newmap[sender]==newmap[receiver])
00338 continue;
00339
00340 int send_part=newmap[sender];
00341 int recv_part=newmap[receiver];
00342 comm[send_part][recv_part]+=cdata.bytes;
00343 comm[recv_part][send_part]+=cdata.bytes;
00344
00345 commUA[send_part]+=cdata.bytes;
00346 commUA[recv_part]+=cdata.bytes;
00347 }
00348 if(!cdata.from_proc() && cdata.receiver.get_type()==LD_OBJLIST_MSG)
00349 {
00350 int nobjs=0;
00351 LDObjKey *receivers=cdata.receiver.get_destObjs(nobjs);
00352 int sender=stats->getHash(cdata.sender);
00353 int send_part=newmap[sender];
00354
00355 CmiAssert(sender<stats->n_objs);
00356
00357 for(int i=0;i<count;i++)
00358 multicastAdded[i]=false;
00359 multicastAdded[send_part]=true;
00360
00361 for(int k=0;k<nobjs;k++)
00362 {
00363 int receiver=stats->getHash(receivers[k]);
00364 CmiAssert ( receiver < stats->n_objs);
00365
00366 int recv_part=newmap[receiver];
00367 if(!multicastAdded[recv_part])
00368 {
00369 comm[send_part][recv_part]+=cdata.bytes;
00370 comm[recv_part][send_part]+=cdata.bytes;
00371
00372 commUA[send_part]+=cdata.bytes;
00373 commUA[recv_part]+=cdata.bytes;
00374
00375 multicastAdded[recv_part]=true;
00376 }
00377 }
00378 }
00379 }
00380
00381 delete[] multicastAdded;
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400 total_comm=0;
00401 if(_lb_debug2_on)
00402 {
00403 int avg_degree=0;
00404 for(int i=0;i<count;i++)
00405 {
00406 double comm_i_total=0;
00407 for(int j=0;j<count;j++)
00408 {
00409 avg_degree+=(comm[i][j]>0);
00410 total_comm+=comm[i][j];
00411 comm_i_total+=comm[i][j];
00412 }
00413 }
00414
00415 }
00416
00417
00418
00419
00420 if(_lb_debug_on)
00421 CkPrintf("Before initing hopBytes\n");
00422 for(i=0;i<count;i++)
00423 {
00424 int hbminIndex=0;
00425 double hbtotal=0;
00426 for(int j=0;j<count;j++)
00427 {
00428
00429 if(_DIJKSTRA_LIKE_)
00430 hopBytes[i][j]=0;
00431 else
00432 hopBytes[i][j]=commUA[i]*dist[j][count];
00433
00434 hbtotal+=hopBytes[i][j];
00435 if(hopBytes[i][hbminIndex]>hopBytes[i][j])
00436 hbminIndex=j;
00437 }
00438 hopBytes[i][count]=hbminIndex;
00439 hopBytes[i][count+1]=hbtotal/count;
00440 }
00441
00442
00443 if(_lb_debug_on)
00444 CkPrintf("Before initing pfree cfree assign\n");
00445 for(i=0;i<count;i++)
00446 {
00447 pfree[i]=true;
00448 cfree[i]=true;
00449 assign[i]=-1;
00450 }
00451
00452 }
00453
00454 void randomAssign(int count, int *perm)
00455 {
00456 int i;
00457 for(i=0;i<count;i++)
00458 perm[i]=i;
00459 for(i=0;i<count;i++)
00460 {
00461 int randpos=i+rand()%(count-i);
00462 int temp=perm[i];
00463 perm[i]=perm[randpos];
00464 perm[randpos]=temp;
00465 }
00466 }
00467
00468 void TopoLB::performMapping(int *newmap, int count)
00469 {
00470 int i,j;
00471 if(_lb_debug_on)
00472 CkPrintf("before performing mapping...\n");
00473
00474 double *distnew=new double[count];
00475 for(i=0;i<count;i++)
00476 {
00477
00478
00479
00480
00481 int part_index=-1;
00482 int proc_index=-1;
00483
00484
00485 double gainMax=-1;
00486 for(j=0;j<count;j++)
00487 {
00488 if(!cfree[j])
00489 continue;
00490
00491 int hb_j_minIndex=(int)hopBytes[j][count];
00492
00493 double gain=hopBytes[j][count+1]-hopBytes[j][hb_j_minIndex];
00494
00495
00496
00497
00498 if(_lb_debug_on)
00499 CkPrintf("Gain is : %lf\n",gain);
00500
00501 if(gain>gainMax)
00502 {
00503 part_index=j;
00504 proc_index=hb_j_minIndex;
00505 gainMax=gain;
00506 }
00507 }
00508 if(_lb_debug_on)
00509 CkPrintf("GainMax [%d] is : %lf\n",i,gainMax);
00510
00511 CmiAssert(part_index!=-1);
00512 CmiAssert(proc_index!=-1);
00513
00514
00515 CmiAssert(assign[part_index]==-1);
00516 CmiAssert(pfree[proc_index]);
00517 assign[part_index]=proc_index;
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531 #ifndef _FASTER_
00532 cfree[part_index]=false;
00533 pfree[proc_index]=false;
00534
00535
00536 if(i == count-1)
00537 continue;
00538
00539 int procs_left=count-i-1;
00540
00541
00542
00543 for(j=0;j<count;j++)
00544 {
00545 if(procs_left>1)
00546 distnew[j]=(dist[j][count]*procs_left -dist[j][proc_index]) / (procs_left-1);
00547 else
00548 distnew[j]=0;
00549 }
00550 for(int cpart=0;cpart<count;cpart++)
00551 {
00552 if(!cfree[cpart])
00553 continue;
00554
00555 if(commUA[cpart]==0 && hopBytes[cpart][count]!=proc_index)
00556 {
00557 if(procs_left>0)
00558 hopBytes[cpart][count+1]=(hopBytes[cpart][count+1]*(procs_left+1) - hopBytes[cpart][proc_index])/(procs_left);
00559 continue;
00560 }
00561
00562
00563 int h_min_index=-1;
00564 double h_min=-1;
00565 double h_total=0;
00566
00567 double c1=commUA[cpart];
00568 double c2=comm[cpart][part_index];
00569
00570 double h_updated=0;
00571
00572 for(int proc=0;proc<count;proc++)
00573 {
00574 if(!pfree[proc])
00575 continue;
00576
00577 hopBytes[cpart][proc]+=(c1-c2)*distnew[proc]+c2*dist[proc][proc_index]-c1*dist[proc][count];
00578 h_updated=hopBytes[cpart][proc];
00579
00580
00581
00582 h_total+=h_updated;
00583 if( h_updated<h_min || h_min_index==-1 )
00584 {
00585 h_min=h_updated;
00586 h_min_index=proc;
00587 }
00588 }
00589
00590 hopBytes[cpart][count]=h_min_index;
00591 hopBytes[cpart][count+1]=h_total/(procs_left);
00592 }
00593
00594
00595
00596 for(j=0;j<count;j++)
00597 {
00598 if(procs_left>1)
00599 dist[j][count]=(dist[j][count]*procs_left -dist[j][proc_index]) / (procs_left-1);
00600 else
00601 dist[j][count]=0;
00602 commUA[j]-=comm[j][part_index];
00603 }
00604
00605 #else
00606 cfree[part_index]=false;
00607 pfree[proc_index]=false;
00608
00609
00610 if(i == count-1)
00611 continue;
00612
00613 int procs_left=count-i-1;
00614
00615
00616 for(int cpart=0;cpart<count;cpart++)
00617 {
00618
00619 if(!cfree[cpart])
00620 continue;
00621
00622
00623 if(comm[cpart][part_index]==0)
00624 {
00625
00626 if(procs_left>0)
00627 hopBytes[cpart][count+1]=(hopBytes[cpart][count+1]*(procs_left+1) - hopBytes[cpart][proc_index])/(procs_left);
00628
00629
00630 if(hopBytes[cpart][count]==proc_index)
00631 {
00632 int c_min=-1;
00633 double c_min_val=-1;
00634 for(int l=0;l<count;l++)
00635 {
00636 if(!pfree[l])
00637 continue;
00638
00639 if(c_min==-1 || hopBytes[cpart][l]<c_min_val)
00640 {
00641 c_min_val=hopBytes[cpart][l];
00642 c_min=l;
00643 }
00644 }
00645 CmiAssert(c_min!=-1);
00646 hopBytes[cpart][count]=c_min;
00647 }
00648 continue;
00649 }
00650
00651
00652 int h_min_index=-1;
00653 double h_min=-1;
00654 double h_total=0;
00655
00656
00657 double c2=comm[cpart][part_index];
00658
00659 double h_updated=0;
00660
00661 for(int proc=0;proc<count;proc++)
00662 {
00663 if(!pfree[proc])
00664 continue;
00665
00666 if(_DIJKSTRA_LIKE_)
00667 hopBytes[cpart][proc]+=c2*(dist[proc][proc_index]);
00668 else
00669 hopBytes[cpart][proc]+=c2*(dist[proc][proc_index]-dist[proc][count]);
00670 h_updated=hopBytes[cpart][proc];
00671
00672
00673
00674 h_total+=h_updated;
00675 if(h_updated<h_min || h_min_index==-1 )
00676 {
00677 h_min=h_updated;
00678 h_min_index=proc;
00679 }
00680 }
00681 CmiAssert(h_min_index!=-1);
00682 CmiAssert(pfree[h_min_index]);
00683 hopBytes[cpart][count]=h_min_index;
00684 hopBytes[cpart][count+1]=h_total/(procs_left);
00685 }
00686
00687 #endif
00688
00689 }
00690
00691
00692 delete [] distnew;
00693
00694
00695 }
00696
00697 void TopoLB :: work(LDStats *stats)
00698 {
00699 int i;
00700 int n_pes = stats->nprocs();
00701
00702 if (_lb_args.debug() >= 2) {
00703 CkPrintf("In TopoLB Strategy...\n");
00704 }
00705
00706
00707 int proc;
00708 for (proc = 0; proc < n_pes; proc++) {
00709 if (stats->procs[proc].available)
00710 break;
00711 }
00712
00713 if (proc == n_pes) {
00714 CmiAbort ("TopoLB: no available processors!");
00715 }
00716
00717 removeNonMigratable(stats, n_pes);
00718
00719 if(_lb_debug_on)
00720 {
00721 CkPrintf("Num of procs: %d\n", n_pes);
00722 CkPrintf("Num of objs: %d\n",stats->n_objs);
00723 }
00724
00725
00726 LBtopoFn topofn;
00727 char *lbcopy = strdup(_lbtopo);
00728 char *ptr = strchr(lbcopy, ':');
00729 if (ptr!=NULL)
00730 ptr = strtok(lbcopy, ":");
00731 else
00732 ptr=lbcopy;
00733
00734 topofn = LBTopoLookup(ptr);
00735 if (topofn == NULL)
00736 {
00737 char str[1024];
00738 CmiPrintf("TopoLB> Fatal error: Unknown topology: %s. Choose from:\n", _lbtopo);
00739 printoutTopo();
00740 sprintf(str, "TopoLB> Fatal error: Unknown topology: %s", _lbtopo);
00741 CmiAbort(str);
00742 }
00743 topo = topofn(n_pes);
00744
00745
00746 if(_lb_debug_on)
00747 CkPrintf("before computing partitions...\n");
00748
00749 int *newmap = new int[stats->n_objs];
00750 if(_make_new_grouping_)
00751 computePartitions(stats, n_pes, newmap);
00752 else
00753 {
00754 for(i=0;i<stats->n_objs;i++)
00755 {
00756 newmap[i]=stats->from_proc[i];
00757 }
00758 }
00759
00760 if(_lb_debug_on)
00761 CkPrintf("before allocating dataStructures...\n");
00762
00763 allocateDataStructures(n_pes);
00764
00765 if(_lb_debug_on)
00766 CkPrintf("before initizlizing dataStructures...\n");
00767
00768 initDataStructures(stats, n_pes, newmap);
00769
00770 if(_lb_debug_on)
00771 printDataStructures(n_pes, stats->n_objs, newmap);
00772
00773
00774
00775 if(_lb_debug_on)
00776 CkPrintf("before performing mapping...\n");
00777
00778 performMapping(newmap, n_pes);
00779
00780 for(i=0;i<stats->n_objs;i++)
00781 {
00782 stats->to_proc[i]= assign[newmap[i]];
00783 }
00784
00785 if(_lb_debug2_on)
00786 {
00787 double hbval1=getHopBytesNew(NULL, n_pes);
00788 CkPrintf("\n");
00789 CkPrintf(" Original hopBytes : %.1lf \n", hbval1);
00790 CkPrintf(" Original Avg hops : %.1lf \n", hbval1/total_comm);
00791 double hbval2=getHopBytesNew(assign, n_pes);
00792
00793
00794
00795
00796
00797 double total_hb_rand=0;
00798 int nTrials=10;
00799 for(int t=0;t<nTrials;t++)
00800 {
00801 randomAssign(n_pes, assign);
00802 double hbval3=getHopBytesNew(assign, n_pes);
00803 total_hb_rand+=hbval3;
00804
00805
00806 }
00807
00808 double hbval4=total_hb_rand/nTrials;
00809 CkPrintf(" Average Random hopBytes : %.1lf \n", hbval4);
00810 CkPrintf(" Average Random Avg hops : %.1lf \n", hbval4/total_comm);
00811 CkPrintf(" Resulting hopBytes : %.1lf \n", hbval2);
00812 CkPrintf(" Resulting Avg hops : %.1lf \n", hbval2/total_comm);
00813 CkPrintf(" Percentage gain(TopoLB vs random) %.2lf\n",(hbval4-hbval2)*100/hbval4);
00814 CkPrintf("\n");
00815 }
00816 freeDataStructures(n_pes);
00817 delete[] newmap;
00818 return;
00819 }
00820
00821
00822 void TopoLB::printDataStructures(int count,int n_objs,int *newmap)
00823 {
00824 int i;
00825
00826
00827
00828
00829
00830
00831
00832
00833 CkPrintf("Dist : \n");
00834 for(i=0;i<count;i++)
00835 {
00836 for(int j=0;j<count+1;j++)
00837 {
00838 CkPrintf("%lf ",dist[i][j]);
00839 }
00840 CkPrintf("\n");
00841 }
00842 CkPrintf("HopBytes: \n");
00843 for(i=0;i<count;i++)
00844 {
00845 for(int j=0;j<count+2;j++)
00846 {
00847 CkPrintf("%lf ",hopBytes[i][j]);
00848 }
00849 CkPrintf("\n");
00850 }
00851 }
00852
00853 double TopoLB::getHopBytesNew(int *assign_map, int count)
00854 {
00855 double totalHB=0;
00856 int i,j;
00857 if(assign_map==NULL)
00858 {
00859 for(i=0;i<count;i++)
00860 for(j=0;j<count;j++)
00861 totalHB+=dist[i][j]*comm[i][j];
00862 }
00863 else
00864 {
00865 for(i=0;i<count;i++)
00866 for(j=0;j<count;j++)
00867 totalHB+=dist[assign_map[i]][assign_map[j]]*comm[i][j];
00868 }
00869 return totalHB;
00870 }
00871
00872 double TopoLB::getHopBytes(CentralLB::LDStats *stats,int count,CkVec<int>map)
00873 {
00874 int i;
00875 double **comm1=new double*[count];
00876 for(i=0;i<count;i++)
00877 comm1[i]=new double[count];
00878
00879 for(i=0;i<count;i++)
00880 {
00881 for(int j=0;j<count;j++)
00882 {
00883 comm1[i][j]=0;
00884 }
00885 }
00886
00887 bool *multicastAdded=new bool[count];
00888 for(i=0;i<stats->n_comm;i++)
00889 {
00890 LDCommData &cdata=stats->commData[i];
00891 if(!cdata.from_proc() && cdata.receiver.get_type() ==LD_OBJ_MSG)
00892 {
00893 int sender=stats->getHash(cdata.sender);
00894 int receiver=stats->getHash(cdata.receiver.get_destObj());
00895
00896 CmiAssert(sender<stats->n_objs);
00897 CmiAssert(receiver<stats->n_objs);
00898
00899 if(map[sender]==map[receiver])
00900 continue;
00901
00902 int send_part=map[sender];
00903 int recv_part=map[receiver];
00904 comm1[send_part][recv_part]+=cdata.bytes;
00905 comm1[recv_part][send_part]+=cdata.bytes;
00906 }
00907 if(!cdata.from_proc() && cdata.receiver.get_type()==LD_OBJLIST_MSG)
00908 {
00909 int nobjs=0;
00910 LDObjKey *receivers=cdata.receiver.get_destObjs(nobjs);
00911 int sender=stats->getHash(cdata.sender);
00912 int send_part=map[sender];
00913
00914 CmiAssert(sender<stats->n_objs);
00915
00916 for(i=0;i<count;i++)
00917 multicastAdded[i]=false;
00918 multicastAdded[send_part]=true;
00919
00920 for(int k=0;k<nobjs;k++)
00921 {
00922 int receiver=stats->getHash(receivers[k]);
00923
00924 CmiAssert ( receiver < stats->n_objs);
00925
00926 int recv_part=map[receiver];
00927 if(!multicastAdded[recv_part])
00928 {
00929 comm1[send_part][recv_part]+=cdata.bytes;
00930 comm1[recv_part][send_part]+=cdata.bytes;
00931
00932 multicastAdded[recv_part]=true;
00933 }
00934 }
00935 }
00936 }
00937 delete[] multicastAdded;
00938
00939 double totalHB=0;
00940
00941 for(i=0;i<count;i++)
00942 {
00943 for(int j=0;j<count;j++)
00944 {
00945 totalHB+=dist[i][j]*comm1[i][j];
00946 }
00947 }
00948 for(i=0;i<count;i++)
00949 delete[] comm1[i];
00950 delete[] comm1;
00951
00952 return totalHB;
00953 }
00954
00955 #include "TopoLB.def.h"