PaCO++  0.05
debug.cc
Go to the documentation of this file.
1 #include "BasicBC.h"
2 #include <vector>
3 #include <iostream>
4 #include <stdio.h>
5 
6 #define LIBGRAPH
7 
8 #ifdef LIBGRAPH
9 #include "kbps.h"
10 #endif
11 
12 using namespace std;
13 
14 vector<BasicBC> sd;
15 vector<BasicBC> dd;
16 
17 vector<long*> sdata;
18 vector<long*> ddata;
19 
20 vector<void*> vdescr;
21 
22 vector<PieceToSend*> spiece;
23 vector<unsigned> ssize;
24 
25 void emuleSrc(int id) {
26 }
27 
28 int main(int argc, char *argv[]) {
29 
32  unsigned long glen = 10;
33  unsigned long bz = 0;
34 
35  switch(argc) {
36  case 5:
37  sscanf(argv[4],"%lu",&bz);
38  case 4:
39  sscanf(argv[3],"%lu",&glen);
40  case 3:
41  case 2:
42  sscanf(argv[1],"%lu",&stopo.total);
43  sscanf(argv[2],"%lu",&dtopo.total);
44  break;
45  default:
46  cerr << "Usage: " << argv[0] << " sd.total dd.total [glen [sz=0 bloc, else bloccyclic(sz)]]\n";
47  exit(-1);
48  }
49 
50  cerr << "stopo: " << stopo.total << endl;
51  cerr << "dtopo: " << dtopo.total << endl;
52 
53  // Allocating memory
54  sd.resize(stopo.total);
55  dd.resize(dtopo.total);
56  sdata.resize(stopo.total);
57  ddata.resize(dtopo.total);
58  vdescr.resize(stopo.total*dtopo.total);
59  spiece.resize(stopo.total);
60  ssize.resize(stopo.total);
61 
62  cerr << " glen: " << glen << endl;
63 
64  // Allocating & initializing comm matrix
65  unsigned ** comm_matrix = new unsigned *[stopo.total];
66  unsigned* comm_area = (unsigned*)calloc(stopo.total*dtopo.total, sizeof(unsigned)); // ZEROED !
67  if (comm_area == NULL) {
68  cerr << "Can not allocate memory of size " << stopo.total*dtopo.total*sizeof(unsigned) << endl;
69  abort();
70  }
71 
72  for(unsigned i=0; i<stopo.total; i++)
73  {
74  comm_matrix[i] = &comm_area[i*dtopo.total];
75  }
76 
77  // Allocating & initializing info matrix : 1 => number of argument
78  void *** info_matrix = new void **[stopo.total];
79  void ** info_area = (void**) calloc(stopo.total*dtopo.total*1, sizeof(void*)); // zeroed
80  if (info_area == NULL) {
81  cerr << "Can not allocate memory of size " << stopo.total*dtopo.total*sizeof(unsigned) << endl;
82  abort();
83  }
84  for(unsigned i=0; i<stopo.total; i++)
85  {
86  info_matrix[i] = &info_area[i*dtopo.total*1];
87  }
88 
89  cerr<<endl<<"##############################"<<endl;
90 
91  for(unsigned i=0; i<stopo.total; i++) {
92 
93  cerr<<endl<<"###### Sender "<<i<<endl<<endl;
94 
95  sd[i].setSourceTopology(stopo);
96  sd[i].setDestTopology(dtopo);
97  sd[i].setNodeRank(i);
98  sd[i].setEltSize(sizeof(long));
99  sd[i].setTotalNbElt(glen);
100  sd[i].setBlocSize(bz);
101 
102  long* ptr = sdata[i] = (long*) malloc(glen);
103  sd[i].setDataPtr((void*) ptr);
104  for(unsigned j=0;j<glen;j++)
105  ptr[j] = i*0x1000+j;
106 
107  spiece[i]=sd[i].computePiecesToSend(ssize[i]);
108 
109  for ( unsigned j = 0; j < ssize[i]; j++)
110  {
111  PieceToSend& p = spiece[i][j];
112  long dest = p.destNode;
113  comm_matrix[i][dest] += p.size;
114  info_matrix[i][dest+0] = p.id;
115  cerr << "p.id: " << p.id<<endl;
116  }
117  }
118  cerr<<endl<<"##############################"<<endl;
119 
120  for(unsigned i=0; i<stopo.total; i++) {
121  cerr<<endl<<"###### Sender "<<i<<endl;
122  if (ssize[i] > dtopo.total) {
123  cerr << "*** case not yet supported (cf descr)\n";
124  abort();
125  }
126  for(unsigned j=0; j<ssize[i]; j++) {
127  cerr<<" Message "<<j;
128  fprintf(stderr," , %2d -> %2d : %4d octets (%p)\n",
129  spiece[i][j].sourceNode, spiece[i][j].destNode, spiece[i][j].size, spiece[i][j].id);
130  bool b=false;
131  long msz= spiece[i][j].size;
132  while(!b) {
133  long mlen;
134  void* ptr = sd[i].getClientData(spiece[i][j].id, i, msz, mlen, b);
135  fprintf(stderr," #element: %2u ptr:%p -- ", mlen, ptr);
136  for(int k=0; k<mlen; k++)
137  fprintf(stderr," %d", ((int*)ptr)[k]);
138  fprintf(stderr,"\n");
139  }
140  if (msz) {
141  cerr << "BIIIGGGG TROUBLE: msz is not 0: " <<msz<<endl;
142  exit(-1);
143  }
144  vdescr[i*dtopo.total+j] = sd[i].getDescr();
145  cerr<<endl;
146  //cerr << " descr: "<<sd[i].getDescr()<<endl;
147  }
148  }
149 
150  cerr<<endl<<"##############################"<<endl;
151 
152 #ifdef LIBGRAPH
153 
154  //build our graph
155  bigraph g;
156 
157  //add nodes
158  for(unsigned int i = 0 ; i < stopo.total ; i++)
159  g.add_node(true);
160  for(unsigned int i = 0 ; i < dtopo.total ; i++)
161  g.add_node(false);
162 
163  // 2. fill the bigraph
164  for (unsigned i = 0; i < (unsigned) stopo.total; i++)
165  {
166  for (unsigned j = 0; j < dtopo.total; j++)
167  {
168  edge*e = g.add_edge(g.get_node(i, true),
169  g.get_node(j, false),
170  comm_matrix[i][j],
171  info_matrix[i][j]);
172  cerr << "id: " << info_matrix[i][j]<<" "<<e->getDecoration()<<endl;
173  }
174  }
175  g.remove_empty_nodes();
176  g.set_beta(10);
177  g.set_k(100);
178 
179  kbps_approximation* _schedule_info = new kbps_approximation(&g);
180  _schedule_info->compute_poly();
181  _schedule_info->serialize();
182 
183  _schedule_info->serial_display();
184 
185  // Display result
186  unsigned int phases = _schedule_info->infophases[0];
187  unsigned int k=0;
188  for(unsigned int i = 0; i < phases; i++)
189  {
190  for(unsigned int j = 0 ; j < _schedule_info->infophases[i+1] ; j++)
191  {
192  kbps_approximation::_comm_t& s= _schedule_info->comms[k];
193  fprintf(stderr," %d -> %d : %d %p\n", s.src, s.dst, s.weight, s.info);
194  k++;
195  }
196  }
197 
198 #endif
199 
200  // Init receiver
201 
202  for(unsigned i=0; i<dtopo.total; i++) {
203 
204  cerr<<endl<<"##############################"<<endl;
205  cerr<<"###### Receiver "<<i<<endl<<endl;
206 
207  dd[i].setSourceTopology(stopo);
208  dd[i].setDestTopology(dtopo);
209  dd[i].setNodeRank(i);
210  dd[i].setEltSize(sizeof(long));
211  dd[i].setBlocSize(bz);
212 
213  // Receive data
214 
215  }
216 
217 
218 
219 }
vector< BasicBC > sd
Definition: debug.cc:14
void emuleSrc(int id)
Definition: debug.cc:25
vector< void * > vdescr
Definition: debug.cc:20
unsigned long total
Definition: PaCO++.idl:35
vector< long * > sdata
Definition: debug.cc:17
vector< unsigned > ssize
Definition: debug.cc:23
int main(int argc, char *argv[])
Definition: debug.cc:28
vector< PieceToSend * > spiece
Definition: debug.cc:22
vector< long * > ddata
Definition: debug.cc:18
vector< BasicBC > dd
Definition: debug.cc:15