00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00041
00042
00043
00044 MPI_Channel::MPI_Channel(int other)
00045 :otherTag(other), otherComm(MPI_COMM_WORLD)
00046 {
00047
00048 }
00049
00050
00051
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
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
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
00145
00146
00147 int
00148 MPI_Channel::recvMsg(int dbTag, int commitTag, Message &msg, ChannelAddress *theAddress)
00149 {
00150
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
00166
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
00187
00188
00189 int
00190 MPI_Channel::sendMsg(int dbTag, int commitTag, const Message &msg, ChannelAddress *theAddress)
00191 {
00192
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
00208
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
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
00238
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
00260
00261
00262 int
00263 MPI_Channel::sendMatrix(int dbTag, int commitTag, const Matrix &theMatrix, ChannelAddress *theAddress)
00264 {
00265
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
00281
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
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
00319
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
00342
00343
00344 int
00345 MPI_Channel::sendVector(int dbTag, int commitTag, const Vector &theVector, ChannelAddress *theAddress)
00346 {
00347
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
00363
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
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
00397
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
00409
00410
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
00423
00424
00425 int
00426 MPI_Channel::sendID(int dbTag, int commitTag, const ID &theID, ChannelAddress *theAddress)
00427 {
00428
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
00444
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
00453
00454
00455
00456 return 0;
00457 }
00458
00459
00460
00461
00462
00463
00464
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