PaCO++  0.05
ClientSide.cc
Go to the documentation of this file.
1 /* Padico Advanced Examples
2  * author: Christian Pérez
3  */
4 
5 #include <stdio.h>
6 #include <mpi.h>
7 
8 #include "Schedule.h"
9 #include "DistributionBloc.h"
10 #include "Internal.h"
11 
12 #include <vector>
13 #include <iostream>
14 
15 using namespace std;
16 
17 //#define NO_COM
18 
19 #undef STANDALONE_FILE
20 
21 #undef DEBUG_INTERNAL
22 #undef DEBUG_COMM
23 
27 
28 // Compute client-side redistribution on the client
29 void computeSendDataBlock1DClient(const GlobalData_t& gd, const LocalData_t &sd, const ParisBlock_param_t* param,
30  const Topology_t &stopo, const Topology_t &dtopo,
31  vAbstrait& vdarray, vector<unsigned>& destid, void* comm)
32 {
33 
34 #ifdef DEBUG_INTERNAL
35  cerr << "In computeSendDataBlock1DClient...\n";
36 #endif
37 
38  vector<LocalData_t> sched_send;
39  vector<LocalData_t> sched_recv;
40 
41  sched_send.clear();
42  sched_recv.clear();
43 
47  // Compute what to send
49 #ifdef DEBUG_INTERNAL
50  cerr << "In computeSendDataBlock1DClient...computing what to send\n";
51 #endif
52  computeSendBlock1D(gd, sd, stopo, dtopo, param, sched_send);
53 
57  // Compute what to receive
59 #ifdef DEBUG_INTERNAL
60  cerr << "In computeSendDataBlock1DClient...computing what to receive\n";
61 #endif
62 
63  // compute how many dest local data this node has to handle
64  unsigned int nvdarray = dtopo.total/stopo.total;
65  unsigned int remaining = (nvdarray*stopo.total + sd.rank < dtopo.total)?1:0;
66  nvdarray += remaining;
67 
68  // Preparing also CORBA stuff
69  vdarray.clear();
70  vdarray.resize(nvdarray);
71  destid.clear();
72  destid.resize(nvdarray);
73 
74  // so, we simulate node from rank, rank+stopo.total ,... only if nvdarray>0
75  unsigned dlbsz = blockSize(gd.len, dtopo.total, param); // blocsize on dest nodes
76  // useless unsigned dtbsz = NumberOfBlockProc(gd.len, dtopo.total , dlbsz, dtopo.total-1); // step on dest nodes
77 
78  // cerr << "DBSZ: " << dbsz << endl;
79  for (unsigned it=0; it<nvdarray; it++) {
80 
81 #ifdef DEBUG_INTERNAL
82  cerr << "computeSendDataBlock1DClient: it = " << it << endl;
83 #endif
84 
85  Abstrait* out = vdarray[it];
86 
87  out->topo().total = dtopo.total;
88  out->gd() = gd; // copy all global data struct
89 
90  // add for mode informations
91  out->mode() = PaCO::ClientSide;
92 
93  out->dist().length(1);
94  out->setSeqLength(1);
95 
96  PaCO::PacoLocalData_t& pld = out->dist()[0];
97  LocalData_t dd;
98  pld.rank = dd.rank = sd.rank + it * stopo.total;
99  pld.start = dd.start = computeBlockBoundInf(dlbsz, dd.rank, dtopo.total, 0);
100  pld.len = dd.len = TotalNumberOfElementProc(gd.len, dd.rank, dtopo.total, dlbsz);
101 
102 #ifdef DEBUG_INTERNAL
103  fprintf(stderr, "dd loop %d: r:%d gl:%ld ll:%d start:%d dt:%ld\n", it,
104  dd.rank, gd.len, dd.len, dd.start, dtopo.total);
105 #endif
106 
107  destid[it] = dd.rank;
108 
111  // Allocating memory
112 
113 #ifdef DEBUG_INTERNAL
114  cerr << "Allocating a sequence of length " << pld.len << endl;
115 #endif
116  out->setDataLength(0, pld.len);
117  if (pld.len > 0 )
118  dd.base = out->getDataBuffer(0, false);
119  else
120  dd.base = (char*) 1; /* hum, ... debug ;( */
121 
122  if (dd.base==0) {
123  cerr << "Cannot allocate memory for #elements" << pld.len << endl;
124  } else {
125 #ifdef DEBUG_INTERNAL
126  fprintf(stderr, "dd.base = %p\n", dd.base);
127 #endif
128  }
129 
130  computeReceiveBlock1D(gd, dd, stopo, dtopo, param, sched_recv);
131  }
132 
136  // Doing local communication
138  //fprintf(stderr, "In computeSendDataBlock1DClient...Doing local communications with ctopo: %ld\n", dtopo.total);
139  doSchedule(gd, sd, stopo, sched_send, sched_recv, comm);
140 
141 #ifdef DEBUG_INTERNAL
142  cerr << "In computeSendDataBlock1DClient...ok\n";
143 #endif
144 }
145 
149 
150 // Compute server-side redistribution on the client -> almost nothing to do
151 
152 // simply send data from source i to dest i % dtopo.total
153 // if less sources than destination: dest j < source j % stopo.total
154 
155 // Client Side function
156 void computeSendDataBlock1DServer(const GlobalData_t& gd, const LocalData_t &sd,
157  const Topology_t &stopo, const Topology_t &dtopo,
158  vAbstrait& vdarray, vector<unsigned>& destid)
159 {
160 
161 
162  // Easy: node i send data to node i%dtopo.total
163  // It has to send an empty message to nodes i+stopo.total, i+2*stopo.total ... < dtopo.total
164 
165  // How messages to send ?
166  unsigned int nvdarray = dtopo.total/stopo.total;
167  unsigned int remaining = (nvdarray*stopo.total + sd.rank < dtopo.total)?1:0;
168  nvdarray += remaining;
169 
170  // alwaays something to send
171  if ( nvdarray == 0 ) nvdarray=1;
172 
173  // Preparing CORBA stuff
174  vdarray.clear();
175  vdarray.resize(nvdarray);
176  destid.clear();
177  destid.resize(nvdarray);
178 
179  for (unsigned it=0; it<nvdarray; it++) {
180 
181  Abstrait* out = vdarray[it];
182 
183  out->topo().total = stopo.total;
184  out->gd() = gd;
185 
186  // add for mode information
187  out->mode() = PaCO::ServerSide;
188 
189  if ( it == 0 ) { // always data to send
190  out->dist().length(1);
191  out->setSeqLength(1);
192 
193  out->dist()[0].rank = sd.rank;
194  out->dist()[0].start = sd.start;
195  out->dist()[0].len = sd.len;
196  out->DataReplace(0, sd.len, sd.base, false);
197  } else { // always nothing to send
198  out->dist().length(0);
199  out->setSeqLength(0);
200  }
201  destid[it] = ( sd.rank + it * stopo.total ) % dtopo.total;
202  }
203 }
204 
207 
209 }
210 
213 
214 // vOut represents what localData/stopo have to send to nodes of dtopo (vOut[].rank is in dtopo space)
215 void computeSendDataBlock1D(const GlobalData_t& gd, const LocalData_t &sd,
216  const Topology_t &stopo, const Topology_t &dtopo, const ParisBlock_param_t* param,
217  vAbstrait& vdarray, vector<unsigned>& destid,
218  const PaCO::distLoc_t& mode, void* comm) {
219 
220  switch(mode) {
221  case PaCO::none: cerr << "INTERNAL ERROR: " << __FILE__ << " " << __FUNCTION__ << endl;
222  case PaCO::ClientSide: computeSendDataBlock1DClient(gd, sd, param, stopo, dtopo, vdarray, destid, comm); break;
223  case PaCO::ServerSide: computeSendDataBlock1DServer(gd, sd, stopo, dtopo, vdarray, destid); break;
225  }
226 
227 }
228 
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
void computeSendDataBlock1DComm()
Definition: ClientSide.cc:208
void computeSendDataBlock1DClient(const GlobalData_t &gd, const LocalData_t &sd, const ParisBlock_param_t *param, const Topology_t &stopo, const Topology_t &dtopo, vAbstrait &vdarray, vector< unsigned > &destid, void *comm)
Definition: ClientSide.cc:29
static unsigned computeBlockBoundInf(const unsigned bsz, const unsigned rank, const unsigned nbprocs, const unsigned pos)
distLoc_t
Definition: PaCO++.idl:12
void computeSendDataBlock1DServer(const GlobalData_t &gd, const LocalData_t &sd, const Topology_t &stopo, const Topology_t &dtopo, vAbstrait &vdarray, vector< unsigned > &destid)
Definition: ClientSide.cc:156
void computeSendDataBlock1D(const GlobalData_t &gd, const LocalData_t &sd, const Topology_t &stopo, const Topology_t &dtopo, const ParisBlock_param_t *param, vAbstrait &vdarray, vector< unsigned > &destid, const PaCO::distLoc_t &mode, void *comm)
Definition: ClientSide.cc:215
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)
vector< BasicBC > dd
Definition: debug.cc:15
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