PaCO++  0.05
ServerSide.cc
Go to the documentation of this file.
00001 /* Padico Advanced Examples
00002  * author: Christian Pérez
00003  */
00004 
00005 #include <stdio.h>
00006 
00007 #include "Schedule.h"
00008 #include "DistributionBloc.h"
00009 #include "Internal.h"
00010 
00011 #undef DEBUG_INTERNAL
00012 
00013 /************************************************************/
00014 /************************************************************/
00015 /************************************************************/
00016 
00017 // Compute a server-side redistribution on the server
00018 // varray must contain the rank of the caller
00019 void computeReceiveDataBlock1DServer(vAbstrait* vdarray, const Topology_t &dtopo, const ParisBlock_param_t* param,
00020                  Abstrait* varray, void* comm)
00021 {
00022 
00023 #ifdef DEBUG_INTERNAL
00024   cerr << "In computeReceiveDataBlock1DServer...\n";
00025 #endif
00026 
00027   vector<LocalData_t> sched_send;
00028   vector<LocalData_t> sched_recv;
00029 
00030   sched_send.clear();
00031   sched_recv.clear();
00032 
00033   // Init data from 1st: all entries are assumed to be identical !
00034   GlobalData_t& gd = (*vdarray)[0]->gd();
00035   Topology_t& stopo= (*vdarray)[0]->topo();
00036 
00040   // Compute what to send
00042 
00043 #ifdef DEBUG_INTERNAL
00044   cerr << "In computeReceiveDataBlock1DServer...computing what to send\n";
00045 #endif
00046 
00047   for (unsigned it=0; it<vdarray->size(); it++) { 
00048     if ((*vdarray)[it]->dist().length()==0) {
00049 #ifdef DEBUG_INTERNAL
00050       cerr << "Dist data empty: nothing to send\n";
00051 #endif
00052     } else {
00053 #ifdef DEBUG_INTERNAL
00054       cerr << "it = " << it << endl;
00055 #endif
00056       PaCO::PacoLocalData_t psd = (*vdarray)[it]->dist()[0];
00057       LocalData_t  sd;
00058       sd.rank  = psd.rank;
00059       sd.start = psd.start;
00060       sd.len   = psd.len;
00061       sd.base  = (*vdarray)[it]->getDataBuffer(0, false);
00062       computeSendBlock1D(gd, sd, stopo, dtopo, param, sched_send);
00063     }
00064   }
00065 
00069   // Compute what to receive
00071 #ifdef DEBUG_INTERNAL
00072   cerr << "In computeReceiveDataBlock1DServer...computing what to receive\n";
00073 #endif  
00074 
00075 
00076   // Allocating memory
00077 
00078   unsigned dlbsz = blockSize(gd.len, dtopo.total, param);
00079   LocalData_t vd;
00080   vd.rank  = varray->dist()[0].rank;
00081   vd.start = vd.rank * dlbsz;
00082   vd.len   = TotalNumberOfElementProc(gd.len, vd.rank, dtopo.total, dlbsz);
00083 
00084 #ifdef DEBUG_INTERNAL
00085   cerr << "Allocating a sequence of length " << vd.len << endl;
00086 #endif
00087   varray->setSeqLength(1);
00088   varray->setDataLength(0, vd.len);
00089   if (vd.len > 0 )
00090     vd.base = varray->getDataBuffer(0, false);
00091   else
00092     vd.base = (char*) 1;
00093   
00094   if (vd.base==0) {
00095     cerr << "Cannot allocate memory for #elements" << vd.len  << endl;
00096   } else {
00097 #ifdef DEBUG_INTERNAL
00098     fprintf(stderr, "dd.base = %p\n", vd.base);
00099 #endif
00100   }
00101   
00102   computeReceiveBlock1D(gd, vd, stopo, dtopo, param, sched_recv);
00103 
00107   // Doing local communication
00109   //fprintf(stderr, "In computeReceiveDataBlock1DServer...Doing local communications with ctopo: %ld\n", dtopo.total);
00110   doSchedule(gd, vd, dtopo, sched_send, sched_recv, comm); 
00111 
00112   cerr << "In computeReceiveDataBlock1DServer...ok\n";
00113 }
00114 
00117 
00118 
00119 // Compute the number of CORBA messages that are going to be receive by drank
00120 unsigned nbofPart(const PaCO::distLoc_t& mode, const unsigned stotal, const unsigned dtotal, const unsigned drank)  {
00121   switch(mode) {
00122   case PaCO::none: cerr << "INTERNAL ERROR: " << __FILE__ << " " << __FUNCTION__ << endl; return 0;
00123   case PaCO::ClientSide: return 1; 
00124   case PaCO::ServerSide:
00125     {
00126       unsigned int nvdarray  = stotal/dtotal;
00127       unsigned int remaining = (nvdarray*dtotal + drank < stotal)?1:0;
00128       nvdarray += remaining;
00129       if ( nvdarray == 0 ) return 1; // alway at least one
00130       return nvdarray;
00131     }
00132   case PaCO::CommSide: cerr << "INTERNAL ERROR: not yet implemented in " << __FILE__ << " " << __FUNCTION__ << endl; return 0;
00133   }
00134   return 0;
00135 }
00136 
00137 // compute the rank of the messages sent by srank 
00138 unsigned posofPart(const PaCO::distLoc_t& mode, const unsigned dtotal, const unsigned srank)  {
00139   switch(mode) {
00140   case PaCO::none: cerr << "INTERNAL ERROR: " << __FILE__ << " " << __FUNCTION__ << endl; return 0;
00141   case PaCO::ClientSide: return 0; 
00142   case PaCO::ServerSide: return srank / dtotal;
00143   case PaCO::CommSide: cerr << "INTERNAL ERROR: not yet implemented in " << __FILE__ << " " << __FUNCTION__ << endl; return 0;
00144   }
00145   return 0;
00146 }
00147 
00150 
00151 bool computeReceiveDataBlock1D(vAbstrait* vdarray, const PaCO::distLoc_t& mode,
00152                 const unsigned dtotal, const unsigned drank, const ParisBlock_param_t* param,
00153                 /*out*/ Abstrait* varray, void* comm) {
00154 
00155 #ifdef DEBUG_INTERNAL
00156   cerr << "In computeReceiveDataBlock1D...\n";
00157 #endif  
00158   switch(mode) {
00159   case PaCO::none:
00160     cerr << "INTERNAL ERROR: " << __FILE__ << " " << __FUNCTION__ << endl;
00161     break;
00162   case PaCO::ClientSide:
00163 #ifdef DEBUG_INTERNAL
00164     cerr << "Client Side case" <<endl;
00165 #endif
00166     varray->CopyAndGetSequenceOwner((*vdarray)[0]);
00167 #ifdef DEBUG_INTERNAL
00168     cerr << "Return true" << endl;
00169 #endif
00170     return true;
00171     break; 
00172     
00173   case PaCO::ServerSide: {
00174     // data has been sent from source i to dest i % dtopo.total
00175     // so dest j has : j, j + dtopo.total, j+2*dtopo.total
00176     // so it may be 1 (at least activation) or more
00177     cerr << " vdaray size: " << vdarray->size() << endl;
00178 
00179 //      unsigned stotal = (*vdarray)[0]->topo().total;
00180 //      unsigned int nvdarray  = stotal/dtotal;
00181 //      unsigned int remaining = (nvdarray*dtotal + drank < stotal)?1:0;
00182 //      nvdarray += remaining;
00183 //      if ( nvdarray == 0 ) nvdarray=1; // alway at least one
00184 
00185 //      fprintf(stderr, "computeReceiveDataBlock1D: Node %d : got %d of %d data\n", drank, vdarray->size(), nvdarray);
00186     
00187 //      if (vdarray->size() == nvdarray) {
00188 
00189 #ifdef DEBUG_INTERNAL
00190     cerr << "DOING  LOCAL REDISTRIBUTION width drank: "<< drank << endl;
00191 #endif
00192     Topology_t dtopo;
00193     dtopo.total   = dtotal;
00194 
00195     varray->topo() = (*vdarray)[0]->topo();
00196     varray->gd()   = (*vdarray)[0]->gd();
00197     varray->dist().length(1);
00198     varray->dist()[0].rank  = drank;
00199 
00200     computeReceiveDataBlock1DServer(vdarray, dtopo, param, varray, comm);
00201 
00202     return true;
00203     break;
00204   }
00205   case PaCO::CommSide:
00206     break;
00207   }
00208   return false;
00209 }
00210 
00214