BIE |
/home/weinberg/src/BIE/include/InitEvaluationRequest.h00001 #ifndef InitEvaluationRequest_h 00002 #define InitEvaluationRequest_h 00003 00004 #include "EvaluationRequest.h" 00005 00006 #include <BIEMutex.h> 00007 #include <cc++/thread.h> 00008 00009 using namespace ost; 00010 00011 #undef INIT_EVALUATION_REQUEST_FINE_TRACE 00012 00013 namespace BIE{ 00014 00015 // The first "request" for processing sent from the tile master to 00016 // each tile worker. The requests are not queued on the tile master; 00017 // rather they are explicitly sent by the handler thread and jammed into 00018 // the pendingrequests queue. Forcing an initial synchronization like 00019 // this lets us know that the workers are alive and well and waiting 00020 // for requests; also the pendingrequest array is initialized. 00021 00022 00024 class InitEvaluationRequest : public EvaluationRequest { 00025 public: 00026 InitEvaluationRequest(Semaphore *numberSlavesReady) 00027 { 00028 this->numberSlavesReady = numberSlavesReady; 00029 00030 //aah todo Pass id in so we don't have to get it from MPI. 00031 // ++MPIMutex; 00032 // MPI_Comm_rank(MPI_COMM_WORLD, &myId); //save id for debugging 00033 // --MPIMutex; 00034 this->myId = myid; //GLOBAL FROM BIEmpi.cc 00035 } 00036 00037 virtual ~InitEvaluationRequest(){}; 00038 00039 virtual void Send(int destination, vector<MPI_Comm>*comms){}; 00040 00041 00042 virtual void Recv(MPI_Status *probeStatus) 00043 { 00044 int tag = probeStatus->MPI_TAG; 00045 int sender = probeStatus->MPI_SOURCE; 00046 MPI_Status status; 00047 int returnSize; 00048 double z; 00049 00050 if (tag !=19){ 00051 cerr << "InitEvaluationRequst.Recv Tag mismatch in MPI probe. Expected 19 recieved " << tag << "\n"; 00052 cerr << "Process: "<< myId << " Sender = " << sender << "\n"; 00053 exit(1); 00054 } 00055 00056 if (received){ 00057 cerr << "InitEvaluationRequest.Recv ERROR. Attempt to receive two results associated with the samerequest.\n"; 00058 cerr << "Process: "<< myId << " Sender = " << sender << "\n"; 00059 00060 exit(1); 00061 } 00062 00063 ++MPIMutex; 00064 MPI_Get_count(probeStatus, MPI_INT, &returnSize); 00065 --MPIMutex; 00066 00067 if (returnSize != 1){ 00068 cerr << "InitEvaluationRequest.Recv Error - returned value wrong size from modelEvaluation. Expecting " << 00069 " 1 got " << returnSize << "\n"; 00070 cerr << "Process: "<< myId << " Sender = " << sender << "\n"; 00071 00072 exit(1); 00073 } 00074 00075 00076 ++MPIMutex; 00077 MPI_Recv(&z, 1, MPI_INT, sender, 19, MPI_COMM_WORLD, &status); //shouldn't block 00078 --MPIMutex; 00079 00080 #ifdef INIT_EVALUATION_REQUEST_FINE_TRACE 00081 cout << "InitEvaluationRequest.Received "; 00082 cout << "Process: "<< myId << " Sender = " << sender << "\n"; 00083 #endif 00084 00085 Process(); 00086 } 00087 00088 void Process() 00089 { 00090 // mark message as received, and sender as available 00091 received = true; 00092 // cast away volatility so we can call non-volatile methods 00093 const_cast<Semaphore*>(numberSlavesReady)->post(); 00094 } 00095 00096 private: 00097 int myId; // for debugging 00098 volatile Semaphore *numberSlavesReady; 00099 }; 00100 } 00101 #endif // InitEvaluationRequest_h Send suggestions, questions, and feedback to WEINBERG at ASTRO dot UMASS dot EDU. Documentation generated at Fri Mar 26 00:35:10 2010 by
|