BIE |
/home/weinberg/src/BIE/include/NormEvaluationRequest.h00001 #ifndef NormEvaluationRequest_h 00002 #define NormEvaluationRequest_h 00003 00004 #include "EvaluationRequest.h" 00005 #include <BIEMutex.h> 00006 #include <iostream> 00007 using namespace std; 00008 00009 #undef NORM_EVALUATION_FINE_TRACE 00010 00011 namespace BIE{ 00012 00014 class NormEvaluationRequest : public EvaluationRequest { 00015 public: 00016 NormEvaluationRequest(int tileId, double x, double y, Semaphore& finished, double& result) 00017 { 00018 // load up array that will be used as a buffer to MPI_send 00019 args[0] = tileId; 00020 args[1] = x; 00021 args[2] = y; 00022 00023 this->finished = &finished; 00024 this->result = &result; 00025 00026 // ++MPIMutex; 00027 // MPI_Comm_rank(MPI_COMM_WORLD, &myId); //save id for debugging 00028 // --MPIMutex; 00029 this->myId = myid; // GLOBAL from BIEmpi.cc 00030 00031 } 00032 00033 virtual ~NormEvaluationRequest(){}; 00034 00035 virtual void Send(int destination, vector<MPI_Comm>*comms) 00036 { 00037 if (sent){ 00038 cout << "NormEvaluationRequest.Send: ERROR. Attempt to send message twice from a Norm request.\n"; 00039 exit(1); 00040 } 00041 00042 // first do a send to to the server to get its attention. Rethink This. 00043 int command = 3; 00044 LogIt("Norm just before Sends"); 00045 LogInt("Destination = ", destination); 00046 00047 sendMutexWaitTime.start(); 00048 ++MPIMutex; 00049 sendMutexWaitTime.stop(); 00050 00051 sendCmdTime.start(); 00052 MPI_Send(&command, 1, MPI_INT, destination, 11, MPI_COMM_WORLD); // send command id 00053 // MPI_Send(&command, 1, MPI_INT, 0, 11, (*comms)[destination]); // send command id 00054 sendCmdTime.stop(); 00055 00056 // Next send the actual message 00057 sendEvalTime.start(); 00058 MPI_Send(args, sizeof(args)/sizeof(double), MPI_DOUBLE, destination, 20, MPI_COMM_WORLD); 00059 // MPI_Send(args, sizeof(args)/sizeof(double), MPI_DOUBLE, 0, 20, (*comms)[destination]); 00060 sendEvalTime.stop(); 00061 00062 --MPIMutex; 00063 LogIt("Norm finished sends"); 00064 00065 sent = true; 00066 00067 #ifdef NORM_EVALUATION_FINE_TRACE 00068 cout << "NormEvaluationRequest.Send: Sent norm eval request from " << myId << " to " << destination << "\n"; 00069 #endif 00070 00071 } 00072 00073 virtual void Recv(MPI_Status *probeStatus) 00074 { 00075 int tag = probeStatus->MPI_TAG; 00076 int sender = probeStatus->MPI_SOURCE; 00077 00078 MPI_Status status; 00079 int returnSize; 00080 double z; 00081 00082 if (tag !=21){ 00083 cerr << "NormEvaluationRequest.Recv: Tag mismatch in MPI probe. Expected 21 recieved " << tag << "\n"; 00084 cerr << "Process: "<< myId << " Sender = " << sender << "\n"; 00085 exit(1); 00086 } 00087 00088 if (received){ 00089 cerr << "NormEvaluationRequest.Recv: ERROR. Attempt to receive two results from a request.\n"; 00090 cerr << "Process: "<< myId << " Sender = " << sender << "\n"; 00091 exit(1); 00092 } 00093 00094 ++MPIMutex; 00095 MPI_Get_count(probeStatus, MPI_DOUBLE, &returnSize); 00096 --MPIMutex; 00097 00098 if (returnSize != 1){ 00099 cout << "NormEvaluationRequest.Recv Error - returned value wrong size from normEvaluation. Expecting " << 00100 " 1 got " << returnSize << "\n"; 00101 cerr << "Process: "<< myId << " Sender = " << sender << "\n"; 00102 exit(1); 00103 } 00104 00105 00106 ++MPIMutex; 00107 MPI_Recv(&z, 1, MPI_DOUBLE, sender, 21, MPI_COMM_WORLD, &status); //shouldn't block 00108 --MPIMutex; 00109 00110 //TODO Check Status! 00111 received = true; 00112 00113 // copy return value back to caller 00114 *result = z; 00115 00116 // notify the user's thread that requested the evaluation 00117 finished->post(); 00118 00119 } 00120 00121 double args[3]; 00122 double *result; 00123 00124 private: 00125 int myId; // for debugging 00126 }; 00127 } 00128 #endif // NormEvaluationRequest_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
|