PaCO++
0.05
|
00001 #include "Identity.h" 00002 #include <iostream> 00003 00004 #define SRC_TOPOLOGY 1 00005 #define DST_TOPOLOGY 2 00006 #define ELEMENT_SIZE 4 00007 #define LOCAL_SIZE 8 00008 00009 #define CORRECT_CONFIG 15 00010 00011 #undef DEBUG_INTERNAL 00012 #undef DEBUG_INTERNAL2 00013 00017 00018 Identity::Identity() 00019 { 00020 // Common 00021 _config = 0; 00022 00023 // By default 1->1 :) 00024 _sTopo.total=1; 00025 _dTopo.total=1; 00026 _nodeRank=0; 00027 00028 // Client side 00029 _clientBuffer=NULL; 00030 00031 // Server side 00032 _serverDescr=NULL; 00033 _serverBuffer=NULL; 00034 } 00035 00036 Identity::~Identity() 00037 { 00038 } 00039 00040 void 00041 Identity::setSourceTopology(PaCO::PacoTopology_t topo) 00042 { 00043 #ifdef DEBUG_INTERNAL 00044 std::cerr << "-- setSourceTopology: " << topo.total << std::endl; 00045 #endif 00046 _config |= SRC_TOPOLOGY; 00047 _sTopo = topo; 00048 } 00049 00050 PaCO::PacoTopology_t 00051 Identity::getSourceTopology() 00052 { 00053 std::cerr << "****** Why is the method " << __FUNCTION__ << "called?\n"; 00054 abort(); 00055 return _sTopo; 00056 } 00057 00058 void 00059 Identity::setDestTopology(PaCO::PacoTopology_t topo) 00060 { 00061 #ifdef DEBUG_INTERNAL 00062 std::cerr << "-- setDestTopology: " << topo.total << std::endl; 00063 #endif 00064 _config |= DST_TOPOLOGY; 00065 _dTopo = topo; 00066 00067 } 00068 00069 PaCO::PacoTopology_t 00070 Identity::getDestTopology() 00071 { 00072 std::cerr << "****** Why is the method " << __FUNCTION__ << "called?\n"; 00073 abort(); 00074 return _dTopo; 00075 } 00076 00077 void 00078 Identity::setNodeRank(long Rank) 00079 { 00080 #ifdef DEBUG_INTERNAL 00081 std::cerr << "-- setNodeRank: " << Rank << std::endl; 00082 #endif 00083 _nodeRank = Rank; 00084 } 00085 00086 long 00087 Identity::getNodeRank() 00088 { 00089 return _nodeRank; 00090 } 00091 00092 void 00093 Identity::setEltSize(unsigned long size) 00094 { 00095 #ifdef DEBUG_INTERNAL 00096 std::cerr << "-- setEltSize: " << size << std::endl; 00097 #endif 00098 _config |= ELEMENT_SIZE; 00099 _unitsize = size; 00100 } 00101 00102 void 00103 Identity::setLocalNbElt(unsigned long elt_nb) 00104 { 00105 #ifdef DEBUG_INTERNAL 00106 std::cerr << "-- setLocalNbElt: " << elt_nb << std::endl; 00107 #endif 00108 _config |= LOCAL_SIZE; 00109 _clientDescr.llen = _llen = elt_nb; 00110 } 00111 00112 00113 PieceToSend* 00114 Identity::computePiecesToSend(unsigned& size_out) 00115 { 00116 00117 PieceToSend * sched; 00118 00119 #ifdef DEBUG_INTERNAL 00120 std::cerr << "computePiecesToSend-------------------- in\n"; 00121 std::cerr << __FUNCTION__ << ": config = "<<_config<<endl; 00122 #endif 00123 00124 if (_config != CORRECT_CONFIG) { 00125 std::cerr << "Identity: incorrect configuration state "<< _config<<"/"<<CORRECT_CONFIG<<endl; 00126 abort(); 00127 } 00128 00129 sched = new PieceToSend[1]; 00130 size_out = 1; 00131 00132 sched[0].sourceNode = _nodeRank; // my self :) 00133 sched[0].destNode = _nodeRank; // the corresponding node 00134 sched[0].size = _llen; // msg size 00135 sched[0].id = (void*) -1; /* not used */ 00136 00137 00138 #ifdef DEBUG_INTERNAL 00139 std::cerr << "computePiecesToSend-------------------- done\n"; 00140 #endif 00141 00142 return sched; 00143 } 00144 00145 void 00146 Identity::setDataPtr(void* dataPtr) 00147 { 00148 _clientBuffer = (char *) dataPtr; 00149 #ifdef DEBUG_INTERNAL 00150 cerr << "-- _clientBuffer set to "<<dataPtr<<endl; 00151 #endif 00152 } 00153 00154 void * 00155 Identity::getClientData(void *pid, int dnode, long & remaining_size_octet, long & returned_length_element, bool & end) 00156 { 00157 if (remaining_size_octet < _llen) { 00158 std::cerr << "Identity: not yet implemented !\n"; 00159 abort(); 00160 } 00161 00162 #ifdef DEBUG_INTERNAL 00163 std::cerr << __FUNCTION__ << ": getClientData returns #elt: "<<_llen<<endl; 00164 #endif 00165 00166 remaining_size_octet-= _llen; 00167 returned_length_element= _llen; 00168 end=true; 00169 00170 return _clientBuffer; 00171 } 00172 00173 void 00174 Identity::clientFree() // always called at the end of an invocation (reset some variables) 00175 { 00176 00177 #ifdef DEBUG_INTERNAL 00178 std::cerr << "-- clientFree\n"; 00179 #endif 00180 } 00181 00182 void * 00183 Identity::getDescr() 00184 { 00185 #ifdef DEBUG_INTERNAL 00186 std::cerr << "-- descr:llen: "<<_clientDescr.llen<<std::endl; 00187 #endif 00188 return &_clientDescr; 00189 } 00190 00191 bool 00192 Identity::insertData(void* rcptBuf, unsigned long element_nb) 00193 { 00194 // cp from recpBuf to _serverBuffer 00195 #ifdef DEBUG_INTERNAL 00196 std::cerr << "-- insertData "<<endl; 00197 #endif 00198 00199 if (element_nb != _llen) { 00200 std::cerr << "Identity: not yet implemented !\n"; 00201 abort(); 00202 } 00203 00204 unsigned long llen = element_nb*_unitsize; 00205 memcpy(_serverBuffer, rcptBuf, llen); 00206 00207 return true; 00208 } 00209 00210 void * 00211 Identity::getServerData(long & length) // in element ! 00212 { 00213 length= _llen; 00214 #ifdef DEBUG_INTERNAL 00215 std::cerr << "-- getServerData: ptr : "<<(void*)_serverBuffer<<" #element:"<<length<<std::endl; 00216 #endif 00217 return (void*) _serverBuffer; 00218 } 00219 00220 void 00221 Identity::setDescr(void * descr) 00222 { 00223 std::cerr << "-- insertData "<<endl; 00224 00225 _serverDescr = (IdentityLib::IdentityDescr*) descr; 00226 00227 // Descr already received 00228 00229 if ( _serverBuffer == NULL) 00230 { 00231 // 1st time -> allocate memory & init 00232 //this->setEltSize(_descr->usz); BUG: usz can be different in client and server (32bit vs 64bit) 00233 unsigned long len = _serverDescr->llen*_unitsize; 00234 this->setLocalNbElt(_serverDescr->llen); 00235 00236 #ifdef DEBUG_INTERNAL 00237 fprintf(stderr, "-- setDescr: stopo: %ld\tdtopo: %ld\n",_sTopo.total, _dTopo.total); 00238 fprintf(stderr, " setDescr: local len: %ld", _serverDescr->llen); 00239 #endif 00240 _serverBuffer = (char*) malloc(len); 00241 #ifdef DEBUG_INTERNAL 00242 std::cerr << "-- serverMalloc: "<<(void*)_serverBuffer<<" - "<<_llen<<endl; 00243 #endif 00244 _serverToReceived = len; 00245 } 00246 } 00247 00248 void 00249 Identity::serverFree() 00250 { 00251 #ifdef DEBUG_INTERNAL 00252 std::cerr << "-- serverFree: "<<(void*)_serverBuffer<<endl; 00253 #endif 00254 free(_serverBuffer); 00255 _serverBuffer=NULL; // the orb (or the user) need to free the memory! 00256 } 00257