PaCO++  0.05
ServerSide.cc
Go to the documentation of this file.
1 /* Padico Advanced Examples
2  * author: Christian Pérez
3  */
4 
5 #include <stdio.h>
6 
7 #include "Schedule.h"
8 #include "DistributionBloc.h"
9 #include "Internal.h"
10 
11 #undef DEBUG_INTERNAL
12 
13 /************************************************************/
14 /************************************************************/
15 /************************************************************/
16 
17 // Compute a server-side redistribution on the server
18 // varray must contain the rank of the caller
19 void computeReceiveDataBlock1DServer(vAbstrait* vdarray, const Topology_t &dtopo, const ParisBlock_param_t* param,
20  Abstrait* varray, void* comm)
21 {
22 
23 #ifdef DEBUG_INTERNAL
24  cerr << "In computeReceiveDataBlock1DServer...\n";
25 #endif
26 
27  vector<LocalData_t> sched_send;
28  vector<LocalData_t> sched_recv;
29 
30  sched_send.clear();
31  sched_recv.clear();
32 
33  // Init data from 1st: all entries are assumed to be identical !
34  GlobalData_t& gd = (*vdarray)[0]->gd();
35  Topology_t& stopo= (*vdarray)[0]->topo();
36 
40  // Compute what to send
42 
43 #ifdef DEBUG_INTERNAL
44  cerr << "In computeReceiveDataBlock1DServer...computing what to send\n";
45 #endif
46 
47  for (unsigned it=0; it<vdarray->size(); it++) {
48  if ((*vdarray)[it]->dist().length()==0) {
49 #ifdef DEBUG_INTERNAL
50  cerr << "Dist data empty: nothing to send\n";
51 #endif
52  } else {
53 #ifdef DEBUG_INTERNAL
54  cerr << "it = " << it << endl;
55 #endif
56  PaCO::PacoLocalData_t psd = (*vdarray)[it]->dist()[0];
57  LocalData_t sd;
58  sd.rank = psd.rank;
59  sd.start = psd.start;
60  sd.len = psd.len;
61  sd.base = (*vdarray)[it]->getDataBuffer(0, false);
62  computeSendBlock1D(gd, sd, stopo, dtopo, param, sched_send);
63  }
64  }
65 
69  // Compute what to receive
71 #ifdef DEBUG_INTERNAL
72  cerr << "In computeReceiveDataBlock1DServer...computing what to receive\n";
73 #endif
74  // Allocating memory
77 
78  unsigned dlbsz = blockSize(gd.len, dtopo.total, param);
79  LocalData_t vd;
80  vd.rank = varray->dist()[0].rank;
81  vd.start = vd.rank * dlbsz;
82  vd.len = TotalNumberOfElementProc(gd.len, vd.rank, dtopo.total, dlbsz);
83 
84 #ifdef DEBUG_INTERNAL
85  cerr << "Allocating a sequence of length " << vd.len << endl;
86 #endif
87  varray->setSeqLength(1);
88  varray->setDataLength(0, vd.len);
89  if (vd.len > 0 )
90  vd.base = varray->getDataBuffer(0, false);
91  else
92  vd.base = (char*) 1;
93 
94  if (vd.base==0) {
95  cerr << "Cannot allocate memory for #elements" << vd.len << endl;
96  } else {
97 #ifdef DEBUG_INTERNAL
98  fprintf(stderr, "dd.base = %p\n", vd.base);
99 #endif
100  }
101 
102  computeReceiveBlock1D(gd, vd, stopo, dtopo, param, sched_recv);
103 
107  // Doing local communication
109  //fprintf(stderr, "In computeReceiveDataBlock1DServer...Doing local communications with ctopo: %ld\n", dtopo.total);
110  doSchedule(gd, vd, dtopo, sched_send, sched_recv, comm);
111 
112  cerr << "In computeReceiveDataBlock1DServer...ok\n";
113 }
114 
117 
118 
119 // Compute the number of CORBA messages that are going to be receive by drank
120 unsigned nbofPart(const PaCO::distLoc_t& mode, const unsigned stotal, const unsigned dtotal, const unsigned drank) {
121  switch(mode) {
122  case PaCO::none: cerr << "INTERNAL ERROR: " << __FILE__ << " " << __FUNCTION__ << endl; return 0;
123  case PaCO::ClientSide: return 1;
124  case PaCO::ServerSide:
125  {
126  unsigned int nvdarray = stotal/dtotal;
127  unsigned int remaining = (nvdarray*dtotal + drank < stotal)?1:0;
128  nvdarray += remaining;
129  if ( nvdarray == 0 ) return 1; // alway at least one
130  return nvdarray;
131  }
132  case PaCO::CommSide: cerr << "INTERNAL ERROR: not yet implemented in " << __FILE__ << " " << __FUNCTION__ << endl; return 0;
133  }
134  return 0;
135 }
136 
137 // compute the rank of the messages sent by srank
138 unsigned posofPart(const PaCO::distLoc_t& mode, const unsigned dtotal, const unsigned srank) {
139  switch(mode) {
140  case PaCO::none: cerr << "INTERNAL ERROR: " << __FILE__ << " " << __FUNCTION__ << endl; return 0;
141  case PaCO::ClientSide: return 0;
142  case PaCO::ServerSide: return srank / dtotal;
143  case PaCO::CommSide: cerr << "INTERNAL ERROR: not yet implemented in " << __FILE__ << " " << __FUNCTION__ << endl; return 0;
144  }
145  return 0;
146 }
147 
150 
151 bool computeReceiveDataBlock1D(vAbstrait* vdarray, const PaCO::distLoc_t& mode,
152  const unsigned dtotal, const unsigned drank, const ParisBlock_param_t* param,
153  /*out*/ Abstrait* varray, void* comm) {
154 
155 #ifdef DEBUG_INTERNAL
156  cerr << "In computeReceiveDataBlock1D...\n";
157 #endif
158  switch(mode) {
159  case PaCO::none:
160  cerr << "INTERNAL ERROR: " << __FILE__ << " " << __FUNCTION__ << endl;
161  break;
162  case PaCO::ClientSide:
163 #ifdef DEBUG_INTERNAL
164  cerr << "Client Side case" <<endl;
165 #endif
166  varray->CopyAndGetSequenceOwner((*vdarray)[0]);
167 #ifdef DEBUG_INTERNAL
168  cerr << "Return true" << endl;
169 #endif
170  return true;
171  break;
172 
173  case PaCO::ServerSide: {
174  // data has been sent from source i to dest i % dtopo.total
175  // so dest j has : j, j + dtopo.total, j+2*dtopo.total
176  // so it may be 1 (at least activation) or more
177  cerr << " vdaray size: " << vdarray->size() << endl;
178 
179 // unsigned stotal = (*vdarray)[0]->topo().total;
180 // unsigned int nvdarray = stotal/dtotal;
181 // unsigned int remaining = (nvdarray*dtotal + drank < stotal)?1:0;
182 // nvdarray += remaining;
183 // if ( nvdarray == 0 ) nvdarray=1; // alway at least one
184 
185 // fprintf(stderr, "computeReceiveDataBlock1D: Node %d : got %d of %d data\n", drank, vdarray->size(), nvdarray);
186 
187 // if (vdarray->size() == nvdarray) {
188 
189 #ifdef DEBUG_INTERNAL
190  cerr << "DOING LOCAL REDISTRIBUTION width drank: "<< drank << endl;
191 #endif
192  Topology_t dtopo;
193  dtopo.total = dtotal;
194 
195  varray->topo() = (*vdarray)[0]->topo();
196  varray->gd() = (*vdarray)[0]->gd();
197  varray->dist().length(1);
198  varray->dist()[0].rank = drank;
199 
200  computeReceiveDataBlock1DServer(vdarray, dtopo, param, varray, comm);
201 
202  return true;
203  break;
204  }
205  case PaCO::CommSide:
206  break;
207  }
208  return false;
209 }
210 
214 
bool computeReceiveDataBlock1D(vAbstrait *vdarray, const PaCO::distLoc_t &mode, const unsigned dtotal, const unsigned drank, const ParisBlock_param_t *param, Abstrait *varray, void *comm)
Definition: ServerSide.cc:151
static unsigned TotalNumberOfElementProc(const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz)
Definition: BasicBC.cc:82
vector< BasicBC > sd
Definition: debug.cc:14
void computeSendBlock1D(const GlobalData_t &gd, const LocalData_t &sd, const Topology_t &stopo, const Topology_t &dtopo, const ParisBlock_param_t *param, vector< LocalData_t > &vOut)
Definition: Schedule.cc:38
distLoc_t
Definition: PaCO++.idl:12
void computeReceiveDataBlock1DServer(vAbstrait *vdarray, const Topology_t &dtopo, const ParisBlock_param_t *param, Abstrait *varray, void *comm)
Definition: ServerSide.cc:19
unsigned long start
Definition: PaCO++.idl:27
void doSchedule(const GlobalData_t &gd, const LocalData_t &ld, const Topology_t &ctopo, vector< LocalData_t > &sched_send, vector< LocalData_t > &sched_recv, void *comm)
Definition: Schedule.cc:227
unsigned long rank
Definition: PaCO++.idl:26
static unsigned blockSize(const unsigned glen, const unsigned nbprocs, const ParisBlock_param_t *param)
unsigned posofPart(const PaCO::distLoc_t &mode, const unsigned dtotal, const unsigned srank)
Definition: ServerSide.cc:138
unsigned nbofPart(const PaCO::distLoc_t &mode, const unsigned stotal, const unsigned dtotal, const unsigned drank)
Definition: ServerSide.cc:120
void computeReceiveBlock1D(const GlobalData_t &gd, const LocalData_t &dd, const Topology_t &stopo, const Topology_t &dtopo, const ParisBlock_param_t *param, vector< LocalData_t > &vOut)
Definition: Schedule.cc:135
unsigned long len
Definition: PaCO++.idl:28