PaCO++
0.05
|
00001 #include "BasicBC.h" 00002 #include <vector> 00003 #include <iostream> 00004 #include <stdio.h> 00005 00006 #define LIBGRAPH 00007 00008 #ifdef LIBGRAPH 00009 #include "kbps.h" 00010 #endif 00011 00012 using namespace std; 00013 00014 vector<BasicBC> sd; 00015 vector<BasicBC> dd; 00016 00017 vector<long*> sdata; 00018 vector<long*> ddata; 00019 00020 vector<void*> vdescr; 00021 00022 vector<PieceToSend*> spiece; 00023 vector<unsigned> ssize; 00024 00025 void emuleSrc(int id) { 00026 } 00027 00028 int main(int argc, char *argv[]) { 00029 00030 PaCO::PacoTopology_t stopo; 00031 PaCO::PacoTopology_t dtopo; 00032 unsigned long glen = 10; 00033 unsigned long bz = 0; 00034 00035 switch(argc) { 00036 case 5: 00037 sscanf(argv[4],"%lu",&bz); 00038 case 4: 00039 sscanf(argv[3],"%lu",&glen); 00040 case 3: 00041 case 2: 00042 sscanf(argv[1],"%lu",&stopo.total); 00043 sscanf(argv[2],"%lu",&dtopo.total); 00044 break; 00045 default: 00046 cerr << "Usage: " << argv[0] << " sd.total dd.total [glen [sz=0 bloc, else bloccyclic(sz)]]\n"; 00047 exit(-1); 00048 } 00049 00050 cerr << "stopo: " << stopo.total << endl; 00051 cerr << "dtopo: " << dtopo.total << endl; 00052 00053 // Allocating memory 00054 sd.resize(stopo.total); 00055 dd.resize(dtopo.total); 00056 sdata.resize(stopo.total); 00057 ddata.resize(dtopo.total); 00058 vdescr.resize(stopo.total*dtopo.total); 00059 spiece.resize(stopo.total); 00060 ssize.resize(stopo.total); 00061 00062 cerr << " glen: " << glen << endl; 00063 00064 // Allocating & initializing comm matrix 00065 unsigned ** comm_matrix = new unsigned *[stopo.total]; 00066 unsigned* comm_area = (unsigned*)calloc(stopo.total*dtopo.total, sizeof(unsigned)); // ZEROED ! 00067 if (comm_area == NULL) { 00068 cerr << "Can not allocate memory of size " << stopo.total*dtopo.total*sizeof(unsigned) << endl; 00069 abort(); 00070 } 00071 00072 for(unsigned i=0; i<stopo.total; i++) 00073 { 00074 comm_matrix[i] = &comm_area[i*dtopo.total]; 00075 } 00076 00077 // Allocating & initializing info matrix : 1 => number of argument 00078 void *** info_matrix = new void **[stopo.total]; 00079 void ** info_area = (void**) calloc(stopo.total*dtopo.total*1, sizeof(void*)); // zeroed 00080 if (info_area == NULL) { 00081 cerr << "Can not allocate memory of size " << stopo.total*dtopo.total*sizeof(unsigned) << endl; 00082 abort(); 00083 } 00084 for(unsigned i=0; i<stopo.total; i++) 00085 { 00086 info_matrix[i] = &info_area[i*dtopo.total*1]; 00087 } 00088 00089 cerr<<endl<<"##############################"<<endl; 00090 00091 for(unsigned i=0; i<stopo.total; i++) { 00092 00093 cerr<<endl<<"###### Sender "<<i<<endl<<endl; 00094 00095 sd[i].setSourceTopology(stopo); 00096 sd[i].setDestTopology(dtopo); 00097 sd[i].setNodeRank(i); 00098 sd[i].setEltSize(sizeof(long)); 00099 sd[i].setTotalNbElt(glen); 00100 sd[i].setBlocSize(bz); 00101 00102 long* ptr = sdata[i] = (long*) malloc(glen); 00103 sd[i].setDataPtr((void*) ptr); 00104 for(unsigned j=0;j<glen;j++) 00105 ptr[j] = i*0x1000+j; 00106 00107 spiece[i]=sd[i].computePiecesToSend(ssize[i]); 00108 00109 for ( unsigned j = 0; j < ssize[i]; j++) 00110 { 00111 PieceToSend& p = spiece[i][j]; 00112 long dest = p.destNode; 00113 comm_matrix[i][dest] += p.size; 00114 info_matrix[i][dest+0] = p.id; 00115 cerr << "p.id: " << p.id<<endl; 00116 } 00117 } 00118 cerr<<endl<<"##############################"<<endl; 00119 00120 for(unsigned i=0; i<stopo.total; i++) { 00121 cerr<<endl<<"###### Sender "<<i<<endl; 00122 if (ssize[i] > dtopo.total) { 00123 cerr << "*** case not yet supported (cf descr)\n"; 00124 abort(); 00125 } 00126 for(unsigned j=0; j<ssize[i]; j++) { 00127 cerr<<" Message "<<j; 00128 fprintf(stderr," , %2d -> %2d : %4d octets (%p)\n", 00129 spiece[i][j].sourceNode, spiece[i][j].destNode, spiece[i][j].size, spiece[i][j].id); 00130 bool b=false; 00131 long msz= spiece[i][j].size; 00132 while(!b) { 00133 long mlen; 00134 void* ptr = sd[i].getClientData(spiece[i][j].id, i, msz, mlen, b); 00135 fprintf(stderr," #element: %2u ptr:%p -- ", mlen, ptr); 00136 for(int k=0; k<mlen; k++) 00137 fprintf(stderr," %d", ((int*)ptr)[k]); 00138 fprintf(stderr,"\n"); 00139 } 00140 if (msz) { 00141 cerr << "BIIIGGGG TROUBLE: msz is not 0: " <<msz<<endl; 00142 exit(-1); 00143 } 00144 vdescr[i*dtopo.total+j] = sd[i].getDescr(); 00145 cerr<<endl; 00146 //cerr << " descr: "<<sd[i].getDescr()<<endl; 00147 } 00148 } 00149 00150 cerr<<endl<<"##############################"<<endl; 00151 00152 #ifdef LIBGRAPH 00153 00154 //build our graph 00155 bigraph g; 00156 00157 //add nodes 00158 for(unsigned int i = 0 ; i < stopo.total ; i++) 00159 g.add_node(true); 00160 for(unsigned int i = 0 ; i < dtopo.total ; i++) 00161 g.add_node(false); 00162 00163 // 2. fill the bigraph 00164 for (unsigned i = 0; i < (unsigned) stopo.total; i++) 00165 { 00166 for (unsigned j = 0; j < dtopo.total; j++) 00167 { 00168 edge*e = g.add_edge(g.get_node(i, true), 00169 g.get_node(j, false), 00170 comm_matrix[i][j], 00171 info_matrix[i][j]); 00172 cerr << "id: " << info_matrix[i][j]<<" "<<e->getDecoration()<<endl; 00173 } 00174 } 00175 g.remove_empty_nodes(); 00176 g.set_beta(10); 00177 g.set_k(100); 00178 00179 kbps_approximation* _schedule_info = new kbps_approximation(&g); 00180 _schedule_info->compute_poly(); 00181 _schedule_info->serialize(); 00182 00183 _schedule_info->serial_display(); 00184 00185 // Display result 00186 unsigned int phases = _schedule_info->infophases[0]; 00187 unsigned int k=0; 00188 for(unsigned int i = 0; i < phases; i++) 00189 { 00190 for(unsigned int j = 0 ; j < _schedule_info->infophases[i+1] ; j++) 00191 { 00192 kbps_approximation::_comm_t& s= _schedule_info->comms[k]; 00193 fprintf(stderr," %d -> %d : %d %p\n", s.src, s.dst, s.weight, s.info); 00194 k++; 00195 } 00196 } 00197 00198 #endif 00199 00200 // Init receiver 00201 00202 for(unsigned i=0; i<dtopo.total; i++) { 00203 00204 cerr<<endl<<"##############################"<<endl; 00205 cerr<<"###### Receiver "<<i<<endl<<endl; 00206 00207 dd[i].setSourceTopology(stopo); 00208 dd[i].setDestTopology(dtopo); 00209 dd[i].setNodeRank(i); 00210 dd[i].setEltSize(sizeof(long)); 00211 dd[i].setBlocSize(bz); 00212 00213 // Receive data 00214 00215 } 00216 00217 00218 00219 }