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

Generated on Mon Oct 23 15:04:56 2006 for OpenSees by doxygen 1.5.0