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
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
00043
00044
00045
00046 MPI_Channel::MPI_Channel(int other)
00047 :otherTag(other), otherComm(MPI_COMM_WORLD)
00048 {
00049
00050 }
00051
00052
00053
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
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
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
00153
00154
00155 int
00156 MPI_Channel::recvMsg(int dbTag, int commitTag, Message &msg, ChannelAddress *theAddress)
00157 {
00158
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
00174
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
00195
00196
00197 int
00198 MPI_Channel::sendMsg(int dbTag, int commitTag, const Message &msg, ChannelAddress *theAddress)
00199 {
00200
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
00216
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
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
00246
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
00268
00269
00270 int
00271 MPI_Channel::sendMatrix(int dbTag, int commitTag, const Matrix &theMatrix, ChannelAddress *theAddress)
00272 {
00273
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
00289
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
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
00327
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
00348
00349
00350 int
00351 MPI_Channel::sendVector(int dbTag, int commitTag, const Vector &theVector, ChannelAddress *theAddress)
00352 {
00353
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
00369
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
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
00402
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
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 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
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 return 0;
00453 }
00454
00455
00456
00457
00458
00459
00460
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