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