Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

MPI_Channel.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.1.1.1 $
00022 // $Date: 2000/09/15 08:23:16 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/actor/channel/MPI_Channel.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/actor/channel/MPI_Channel.C
00027 //
00028 // Written: fmk 11/95
00029 // Revised:
00030 //
00031 // Purpose: This file contains the implementation of the methods needed
00032 // to define the MPI_Channel class interface.
00033 
00034 #include <MPI_Channel.h>
00035 #include <Matrix.h>
00036 #include <ID.h>
00037 #include <Vector.h>
00038 #include <Message.h>
00039 #include <MPI_ChannelAddress.h>
00040 #include <MovableObject.h>
00041 
00042 // MPI_Channel(unsigned int other_Port, char *other_InetAddr): 
00043 //  constructor to open a socket with my inet_addr and with a port number 
00044 // given by the OS. 
00045 
00046 MPI_Channel::MPI_Channel(int other)
00047  :otherTag(other), otherComm(MPI_COMM_WORLD)
00048 {
00049   
00050 }    
00051 
00052 // ~MPI_Channel():
00053 // destructor
00054 
00055 MPI_Channel::~MPI_Channel()
00056 {
00057 
00058 }
00059 
00060 
00061 int 
00062 MPI_Channel::setUpActor(void) 
00063 {
00064   return 0;    
00065 }
00066 
00067 
00068 int 
00069 MPI_Channel::setUpShadow(void) 
00070 {
00071     return 0;
00072 }    
00073 
00074 ChannelAddress *
00075 MPI_Channel::getLastSendersAddress(void) 
00076 {
00077     cerr << "MPI_Channel::getLastSendersAddress(void) - ";
00078     cerr << " this should not be called - need MPI-2.0 to use\n";
00079 
00080     return 0;
00081 }    
00082 
00083 
00084 int
00085 MPI_Channel::setNextAddress(const ChannelAddress &theAddress)
00086 { 
00087     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00088     if (theAddress.getType() == MPI_TYPE) {
00089       theMPI_ChannelAddress = (MPI_ChannelAddress *)(&theAddress);    
00090       otherTag = theMPI_ChannelAddress->otherTag;
00091       otherComm= theMPI_ChannelAddress->otherComm;
00092     }
00093     else {
00094  cerr << "MPI_Channel::setNextAddress() - an MPI_Channel ";
00095  cerr << "can only communicate with an MPI_Channel";
00096  cerr << " address given is not of type MPI_ChannelAddress\n"; 
00097  return -1;     
00098     }       
00099  
00100     return 0;
00101 }
00102 
00103 
00104 
00105 int 
00106 MPI_Channel::sendObj(int commitTag,
00107        MovableObject &theObject, 
00108       ChannelAddress *theAddress) 
00109 {
00110     // first check address is the only address a MPI_Channel can send to
00111     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00112     if (theAddress != 0) {
00113       if (theAddress->getType() == MPI_TYPE) {
00114  theMPI_ChannelAddress = (MPI_ChannelAddress *)theAddress;
00115  otherTag = theMPI_ChannelAddress->otherTag;
00116  otherComm= theMPI_ChannelAddress->otherComm;
00117       }
00118  else {
00119      cerr << "MPI_Channel::sendObj() - a MPI_Channel ";
00120      cerr << "can only communicate with a MPI_Channel";
00121      cerr << " address given is not of type MPI_ChannelAddress\n"; 
00122      return -1;     
00123  }      
00124     }    
00125     return theObject.sendSelf(commitTag, *this);
00126 }
00127 
00128 int 
00129 MPI_Channel::recvObj(int commitTag,
00130        MovableObject &theObject, 
00131        FEM_ObjectBroker &theBroker, 
00132        ChannelAddress *theAddress)
00133 {
00134     // first check address is the only address a MPI_Channel can send to
00135     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00136     if (theAddress != 0) {
00137       if (theAddress->getType() == MPI_TYPE) {
00138  theMPI_ChannelAddress = (MPI_ChannelAddress *)theAddress;
00139  otherTag = theMPI_ChannelAddress->otherTag;
00140  otherComm= theMPI_ChannelAddress->otherComm;
00141       } else {
00142  cerr << "MPI_Channel::recvObj() - a MPI_Channel ";
00143  cerr << "can only communicate with a MPI_Channel";
00144  cerr << " address given is not of type MPI_ChannelAddress\n"; 
00145  return -1;     
00146       }      
00147     }
00148     return theObject.recvSelf(commitTag, *this, theBroker);
00149 }
00150 
00151 
00152 // void Recv(Message &):
00153 //  Method to receive a message, also sets other_Addr to that of sender
00154 
00155 int 
00156 MPI_Channel::recvMsg(int dbTag, int commitTag, Message &msg, ChannelAddress *theAddress)
00157 { 
00158     // first check address is the only address a MPI_Channel can send to
00159     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00160     if (theAddress != 0) {
00161       if (theAddress->getType() == MPI_TYPE) {
00162  theMPI_ChannelAddress = (MPI_ChannelAddress *)theAddress;
00163  otherTag = theMPI_ChannelAddress->otherTag;
00164  otherComm= theMPI_ChannelAddress->otherComm;
00165       } else {
00166  cerr << "MPI_Channel::recvMesg() - a MPI_Channel ";
00167  cerr << "can only communicate with a MPI_Channel";
00168  cerr << " address given is not of type MPI_ChannelAddress\n"; 
00169  return -1;     
00170       }      
00171     }
00172 
00173     // if o.k. get a ponter to the data in the message and 
00174     // place the incoming data there
00175     int nleft,nread;
00176     char *gMsg;
00177     gMsg = msg.data;
00178     nleft = msg.length;
00179 
00180     MPI_Status status;
00181     MPI_Recv((void *)gMsg, nleft, MPI_CHAR, otherTag, 0, otherComm, &status);
00182     int count =0;
00183     MPI_Get_count(&status, MPI_CHAR, &count);
00184     if (count != nleft) {
00185       cerr << "MPI_Channel::recvMesg() -";
00186       cerr << " incorrect size of Message received ";
00187       return -1;
00188     }
00189     else
00190       return 0;
00191 }
00192 
00193 
00194 // void Send(Message &):
00195 //  Method to send a message to an address given by other_Addr.
00196 
00197 int 
00198 MPI_Channel::sendMsg(int dbTag, int commitTag, const Message &msg, ChannelAddress *theAddress)
00199 { 
00200     // first check address is the only address a MPI_Channel can send to
00201     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00202     if (theAddress != 0) {
00203       if (theAddress->getType() == MPI_TYPE) {
00204  theMPI_ChannelAddress = (MPI_ChannelAddress *)theAddress;
00205  otherTag = theMPI_ChannelAddress->otherTag;
00206  otherComm= theMPI_ChannelAddress->otherComm;
00207       } else {
00208  cerr << "MPI_Channel::sendMsg() - a MPI_Channel ";
00209  cerr << "can only communicate with a MPI_Channel";
00210  cerr << " address given is not of type MPI_ChannelAddress\n"; 
00211  return -1;     
00212       }      
00213     }
00214 
00215     // if o.k. get a ponter to the data in the message and 
00216     // place the incoming data there
00217     int nwrite, nleft;    
00218     char *gMsg;
00219     gMsg = msg.data;
00220     nleft = msg.length;
00221 
00222     MPI_Send((void *)gMsg, nleft, MPI_CHAR, otherTag, 0, otherComm);
00223     return 0;
00224 }
00225 
00226 int 
00227 MPI_Channel::recvMatrix(int dbTag, int commitTag, Matrix &theMatrix, ChannelAddress *theAddress)
00228       
00229 { 
00230     // first check address is the only address a MPI_Channel can send to
00231     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00232     if (theAddress != 0) {
00233       if (theAddress->getType() == MPI_TYPE) {
00234  theMPI_ChannelAddress = (MPI_ChannelAddress *)theAddress;
00235  otherTag = theMPI_ChannelAddress->otherTag;
00236  otherComm= theMPI_ChannelAddress->otherComm;
00237       } else {
00238  cerr << "MPI_Channel::recvMatrix() - a MPI_Channel ";
00239  cerr << "can only communicate with a MPI_Channel";
00240  cerr << " address given is not of type MPI_ChannelAddress\n"; 
00241  return -1;     
00242       }      
00243     }
00244 
00245     // if o.k. get a ponter to the data in the Matrix and 
00246     // place the incoming data there
00247     int nleft,nread;
00248     double *data = theMatrix.data;
00249     char *gMsg = (char *)data;;
00250     nleft =  theMatrix.dataSize;
00251 
00252     MPI_Status status;
00253     MPI_Recv((void *)gMsg, nleft, MPI_DOUBLE, otherTag, 0, 
00254       otherComm, &status);
00255     int count = 0;
00256     MPI_Get_count(&status, MPI_DOUBLE, &count);
00257     if (count != nleft) {
00258       cerr << "MPI_Channel::recvMatrix() -";
00259       cerr << " incorrect number of entries for Matrix received ";
00260       return -1;
00261     }
00262     else
00263       return 0;
00264 }
00265 
00266 
00267 // void Send(Matrix &):
00268 //  Method to send a Matrix to an address given by other_Addr.
00269 
00270 int 
00271 MPI_Channel::sendMatrix(int dbTag, int commitTag, const Matrix &theMatrix, ChannelAddress *theAddress)
00272 { 
00273     // first check address is the only address a MPI_Channel can send to
00274     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00275     if (theAddress != 0) {
00276       if (theAddress->getType() == MPI_TYPE) {
00277  theMPI_ChannelAddress = (MPI_ChannelAddress *)theAddress;
00278  otherTag = theMPI_ChannelAddress->otherTag;
00279  otherComm= theMPI_ChannelAddress->otherComm;
00280       } else {
00281  cerr << "MPI_Channel::sendMatrix() - a MPI_Channel ";
00282  cerr << "can only communicate with a MPI_Channel";
00283  cerr << " address given is not of type MPI_ChannelAddress\n"; 
00284  return -1;     
00285       }      
00286     }
00287 
00288     // if o.k. get a ponter to the data in the Matrix and 
00289     // place the incoming data there
00290     int nwrite, nleft;    
00291     double *data = theMatrix.data;
00292     char *gMsg = (char *)data;
00293     nleft =  theMatrix.dataSize;
00294 
00295     MPI_Send((void *)gMsg, nleft, MPI_DOUBLE, otherTag, 0, otherComm);
00296 
00297     return 0;
00298 }
00299 
00300 
00301 
00302 
00303 
00304 
00305 
00306 
00307 int 
00308 MPI_Channel::recvVector(int dbTag, int commitTag, Vector &theVector, ChannelAddress *theAddress)
00309       
00310 { 
00311     // first check address is the only address a MPI_Channel can send to
00312     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00313     if (theAddress != 0) {
00314       if (theAddress->getType() == MPI_TYPE) {
00315  theMPI_ChannelAddress = (MPI_ChannelAddress *)theAddress;
00316  otherTag = theMPI_ChannelAddress->otherTag;
00317  otherComm= theMPI_ChannelAddress->otherComm;
00318       } else {
00319  cerr << "MPI_Channel::recvVector() - a MPI_Channel ";
00320  cerr << "can only communicate with a MPI_Channel";
00321  cerr << " address given is not of type MPI_ChannelAddress\n"; 
00322  return -1;     
00323       }      
00324     }
00325 
00326     // if o.k. get a ponter to the data in the Vector and 
00327     // place the incoming data there
00328     int nleft,nread;
00329     double *data = theVector.theData;
00330     char *gMsg = (char *)data;;
00331     nleft =  theVector.sz;
00332 
00333     MPI_Status status;
00334     MPI_Recv((void *)gMsg, nleft, MPI_DOUBLE, otherTag, 0, otherComm, &status);
00335     int count =0;
00336     MPI_Get_count(&status, MPI_DOUBLE, &count);
00337     if (count != nleft) {
00338       cerr << "MPI_Channel::recvVector() -";
00339       cerr << " incorrect number of entries for Vector received ";
00340       return -1;
00341     }
00342     else
00343       return 0;
00344 }
00345 
00346 
00347 // void Send(Vector &):
00348 //  Method to send a Vector to an address given by other_Addr.
00349 
00350 int 
00351 MPI_Channel::sendVector(int dbTag, int commitTag, const Vector &theVector, ChannelAddress *theAddress)
00352 { 
00353     // first check address is the only address a MPI_Channel can send to
00354     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00355     if (theAddress != 0) {
00356       if (theAddress->getType() == MPI_TYPE) {
00357  theMPI_ChannelAddress = (MPI_ChannelAddress *)theAddress;
00358  otherTag = theMPI_ChannelAddress->otherTag;
00359  otherComm= theMPI_ChannelAddress->otherComm;
00360       } else {
00361  cerr << "MPI_Channel::sendVector() - a MPI_Channel ";
00362  cerr << "can only communicate with a MPI_Channel";
00363  cerr << " address given is not of type MPI_ChannelAddress\n"; 
00364  return -1;     
00365       }      
00366     }
00367 
00368     // if o.k. get a ponter to the data in the Vector and 
00369     // place the incoming data there
00370     int nwrite, nleft;    
00371     double *data = theVector.theData;
00372     char *gMsg = (char *)data;
00373     nleft =  theVector.sz;
00374 
00375     MPI_Send((void *)gMsg, nleft, MPI_DOUBLE, otherTag, 0, otherComm);
00376     
00377     return 0;
00378 }
00379 
00380 
00381 
00382 
00383 int 
00384 MPI_Channel::recvID(int dbTag, int commitTag, ID &theID, ChannelAddress *theAddress)
00385 { 
00386     // first check address is the only address a MPI_Channel can send to
00387     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00388     if (theAddress != 0) {
00389       if (theAddress->getType() == MPI_TYPE) {
00390  theMPI_ChannelAddress = (MPI_ChannelAddress *)theAddress;
00391  otherTag = theMPI_ChannelAddress->otherTag;
00392  otherComm= theMPI_ChannelAddress->otherComm;
00393       } else {
00394  cerr << "MPI_Channel::recvID() - a MPI_Channel ";
00395  cerr << "can only communicate with a MPI_Channel";
00396  cerr << " address given is not of type MPI_ChannelAddress\n"; 
00397  return -1;     
00398       }      
00399     }
00400 
00401     // if o.k. get a ponter to the data in the ID and 
00402     // place the incoming data there
00403     int nleft,nread;
00404     int *data = theID.data;
00405     char *gMsg = (char *)data;;
00406     nleft =  theID.sz;
00407 
00408     MPI_Status status;
00409     MPI_Recv((void *)gMsg, nleft, MPI_INT, otherTag, 0, otherComm, &status);
00410     int count =0;
00411     MPI_Get_count(&status, MPI_INT, &count);
00412     if (count != nleft) {
00413       cerr << "MPI_Channel::recvID() -";
00414       cerr << " incorrect number of entries for ID received ";
00415       return -1;
00416     }
00417     else
00418       return 0;
00419 }
00420 
00421 
00422 // void Send(ID &):
00423 //  Method to send a ID to an address given by other_Addr.
00424 
00425 int 
00426 MPI_Channel::sendID(int dbTag, int commitTag, const ID &theID, ChannelAddress *theAddress)
00427 { 
00428     // first check address is the only address a MPI_Channel can send to
00429     MPI_ChannelAddress *theMPI_ChannelAddress = 0;
00430     if (theAddress != 0) {
00431       if (theAddress->getType() == MPI_TYPE) {
00432  theMPI_ChannelAddress = (MPI_ChannelAddress *)theAddress;
00433  otherTag = theMPI_ChannelAddress->otherTag;
00434  otherComm= theMPI_ChannelAddress->otherComm;
00435       } else {
00436  cerr << "MPI_Channel::sendID() - a MPI_Channel ";
00437  cerr << "can only communicate with a MPI_Channel";
00438  cerr << " address given is not of type MPI_ChannelAddress\n"; 
00439  return -1;     
00440       }      
00441     }
00442 
00443     // if o.k. get a ponter to the data in the ID and 
00444     // place the incoming data there
00445     int nwrite, nleft;    
00446     int *data = theID.data;
00447     char *gMsg = (char *)data;
00448     nleft =  theID.sz;
00449 
00450     MPI_Send((void *)gMsg, nleft, MPI_INT, otherTag, 0, otherComm);
00451     
00452     return 0;
00453 }
00454 
00455 
00456 /*
00457 int 
00458 MPI_Channel::getPortNumber(void) const
00459 {
00460     return otherTag;
00461 }
00462 */
00463 
00464 char *
00465 MPI_Channel::addToProgram(void)
00466 {
00467     cerr << "MPI_Channel::addToProgram(void) - ";
00468     cerr << " this should not be called - need MPI-2.0\n";
00469     char *newStuff =(char *)malloc(10*sizeof(char));
00470     for (int i=0; i<10; i++) 
00471  newStuff[i] = ' ';
00472 
00473     return newStuff;
00474 }
00475 
00476 
Copyright Contact Us