4 #define TAILLE_SPLIT 100000
7 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
8 CorbaNCNoCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::CorbaNCNoCopyReceiver(CorbaSender mySender):_mySender(mySender){
11 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
12 CorbaNCNoCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::~CorbaNCNoCopyReceiver(){
14 CORBA::release(_mySender);
17 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
18 void *CorbaNCNoCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::getDistValue(long &size)
20 TSeqCorba seq=_mySender->send();
22 return seq->get_buffer(1);
25 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
26 void *CorbaNCNoCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::getValue(long &size)
28 return Receiver::getValue(size,_mySender);
31 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
32 CorbaNCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::CorbaNCWithCopyReceiver(CorbaSender mySender):_mySender(mySender){
35 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
36 CorbaNCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::~CorbaNCWithCopyReceiver(){
38 CORBA::release(_mySender);
41 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
42 void *CorbaNCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::getDistValue(long &size){
43 size=_mySender->getSize();
47 for(long i=0;i<size;i+=TAILLE_SPLIT)
49 if(size-i>TAILLE_SPLIT)
53 TSeqCorba seq=_mySender->sendPart(i,n);
54 T *seqd=(T *)seq->get_buffer(0);
61 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
62 void *CorbaNCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::getValue(long &size)
64 return Receiver::getValue(size,_mySender);
67 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
68 CorbaWCNoCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::CorbaWCNoCopyReceiver(CorbaSender mySender):_mySender(mySender){
71 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
72 CorbaWCNoCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::~CorbaWCNoCopyReceiver(){
74 CORBA::release(_mySender);
77 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
78 void *CorbaWCNoCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::getDistValue(long &size){
79 size=_mySender->getSize();
83 for(long i=0;i<size;i+=TAILLE_SPLIT)
85 if(size-i>TAILLE_SPLIT)
89 TSeqCorba seq=_mySender->sendPart(i,n);
90 TCorba *seqd=seq->get_buffer(0);
97 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
98 void *CorbaWCNoCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::getValue(long &size)
100 return Receiver::getValue(size,_mySender);
103 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
104 CorbaWCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::CorbaWCWithCopyReceiver(CorbaSender mySender):_mySender(mySender){
107 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
108 CorbaWCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::~CorbaWCWithCopyReceiver(){
109 _mySender->release();
110 CORBA::release(_mySender);
113 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
114 void *CorbaWCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::getDistValue(long &size){
115 size=_mySender->getSize();
119 for(long i=0;i<size;i+=TAILLE_SPLIT)
121 if(size-i>TAILLE_SPLIT)
125 TSeqCorba seq=_mySender->sendPart(i,n);
126 TCorba *seqd=seq->get_buffer(0);
127 for(long j=0;j<n;j++)
133 template<class T,class TCorba,class TSeqCorba,class CorbaSender>
134 void *CorbaWCWithCopyReceiver<T,TCorba,TSeqCorba,CorbaSender>::getValue(long &size)
136 return Receiver::getValue(size,_mySender);
141 template<class T,MPI_Datatype T2>
142 MPIReceiver<T,T2>::MPIReceiver(SALOME::MPISender_ptr mySender):_mySender(mySender){
145 template<class T,MPI_Datatype T2>
146 MPIReceiver<T,T2>::~MPIReceiver(){
147 _mySender->release();
148 CORBA::release(_mySender);
151 template<class T,MPI_Datatype T2>
152 void *MPIReceiver<T,T2>::getDistValue(long &size){
158 char port_name_clt [MPI_MAX_PORT_NAME];
159 float telps, tuser, tsys, tcpu;
165 MPI_Comm_rank(MPI_COMM_WORLD, &myproc);
166 SALOME::MPISender::param_var p =_mySender->getParam();
169 MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
170 while ( i != TIMEOUT && MPI_Lookup_name((char*)p->service,MPI_INFO_NULL,port_name_clt) != MPI_SUCCESS) {
173 MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL);
174 if ( i == TIMEOUT ) {
179 // Connect to service, get the inter-communicator server
180 // Attention MPI_Comm_connect est un appel collectif :
181 // - Si lancement mpirun -c n -----> uniquement MPI_COMM_SELF fonctionne
182 // - Si lancement client_server&client_server ----> MPI_COMM_WORLD fonctionne
184 // TIMEOUT is inefficient since MPI_Comm_Connect doesn't return if we asked for
185 // a service that has been unpublished !
186 MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
188 while ( i != TIMEOUT && MPI_Comm_connect(port_name_clt, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &com)!=MPI_SUCCESS ) {
191 MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL);
192 if ( i == TIMEOUT ) {
197 MPI_Recv( &_n, 1, MPI_LONG, sproc,p->tag1,com,&status);
199 MPI_Recv( _v, _n, T2, sproc,p->tag2,com,&status);
201 MPI_Comm_disconnect( &com );
206 template<class T,MPI_Datatype T2>
207 void *MPIReceiver<T,T2>::getValue(long &size)
209 return Receiver::getValue(size,_mySender);
215 #include <sys/types.h>
216 #include <sys/socket.h>
217 #include <netinet/in.h>
218 #include <arpa/inet.h>
223 template<class T,int (*myFunc)(XDR*,T*)>
224 SocketReceiver<T,myFunc>::SocketReceiver(SALOME::SocketSender_ptr mySender) : _mySender(mySender)
230 template<class T,int (*myFunc)(XDR*,T*)>
231 SocketReceiver<T,myFunc>::~SocketReceiver()
235 _mySender->release();
236 CORBA::release(_mySender);
240 template<class T,int (*myFunc)(XDR*,T*)>
241 void *SocketReceiver<T,myFunc>::getValue(long &size)
243 return Receiver::getValue(size,_mySender);
246 template<class T,int (*myFunc)(XDR*,T*)>
247 void* SocketReceiver<T,myFunc>::getDistValue(long &size)
251 XDR xp; /* pointeur sur le decodeur XDR */
256 SALOME::SocketSender::param_var p = _mySender->getParam();
258 size = p->lend - p->lstart + 1;
261 connectCom(p->internet_address, p->myport);
265 xdrmem_create(&xp,(char*)v,size*sizeof(T),XDR_DECODE );
266 while( n < size*sizeof(T) ){
267 m = read(_clientSockfd, (char*)v+n, size*sizeof(T)-n);
271 SALOME::ExceptionStruct es;
272 es.type = SALOME::COMM;
273 es.text = "error read Socket exception";
274 throw SALOME::SALOME_Exception(es);
278 xdr_vector( &xp, (char*)v, size, sizeof(T), (xdrproc_t)myFunc);
281 _mySender->endOfCom();
284 catch(SALOME::SALOME_Exception &ex){
285 if( ex.details.type == SALOME::COMM )
287 _senderDestruc=false;
288 cout << ex.details.text << endl;
289 throw MultiCommException("Unknown sender protocol");
298 template<class T,int (*myFunc)(XDR*,T*)>
299 void SocketReceiver<T,myFunc>::initCom()
302 _mySender->initCom();
304 /* Ouverture de la socket */
305 _clientSockfd = socket(AF_INET, SOCK_STREAM, 0);
306 if (_clientSockfd < 0) {
308 SALOME::ExceptionStruct es;
309 es.type = SALOME::COMM;
310 es.text = "error Socket exception";
311 throw SALOME::SALOME_Exception(es);
314 catch(SALOME::SALOME_Exception &ex){
315 if( ex.details.type == SALOME::COMM )
317 _senderDestruc=false;
318 cout << ex.details.text << endl;
319 throw MultiCommException("Unknown sender protocol");
327 template<class T,int (*myFunc)(XDR*,T*)>
328 void SocketReceiver<T,myFunc>::connectCom(const char *dest_address, int port)
330 struct sockaddr_in serv_addr;
331 struct hostent * server;
332 SALOME::ExceptionStruct es;
335 /* reception of the host structure on the remote process */
336 server = gethostbyname(dest_address);
337 if( server == NULL ) {
339 es.type = SALOME::COMM;
340 es.text = "error unknown host Socket exception";
341 _senderDestruc=false;
342 throw SALOME::SALOME_Exception(es);
345 /* Initialisation of the socket structure */
346 bzero((char*)&serv_addr,sizeof(serv_addr));
347 serv_addr.sin_family = AF_INET;
348 serv_addr.sin_addr.s_addr = INADDR_ANY;
349 bcopy((char *)server->h_addr,
350 (char *)&serv_addr.sin_addr.s_addr,
352 serv_addr.sin_port = htons(port);
354 if( connect(_clientSockfd, (struct sockaddr *) & serv_addr, sizeof(struct sockaddr)) < 0 ){
356 es.type = SALOME::COMM;
357 es.text = "error connect Socket exception";
358 _senderDestruc=false;
359 throw SALOME::SALOME_Exception(es);
362 _mySender->acceptCom();
365 catch(SALOME::SALOME_Exception &ex){
366 if( ex.details.type == SALOME::COMM )
368 _senderDestruc=false;
369 cout << ex.details.text << endl;
370 throw MultiCommException("Unknown sender protocol");
379 template<class T,int (*myFunc)(XDR*,T*)>
380 void SocketReceiver<T,myFunc>::closeCom()
382 _mySender->closeCom();
383 if( _clientSockfd >= 0 ){
384 close(_clientSockfd);