[1381] | 1 | #include "ep_lib.hpp" |
---|
| 2 | #include <mpi.h> |
---|
| 3 | #include "ep_declaration.hpp" |
---|
| 4 | #include "ep_mpi.hpp" |
---|
| 5 | |
---|
| 6 | namespace ep_lib |
---|
| 7 | { |
---|
| 8 | |
---|
| 9 | int MPI_Iprobe(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *status) |
---|
| 10 | { |
---|
| 11 | *flag = false; |
---|
| 12 | |
---|
| 13 | if(!comm.is_ep) |
---|
| 14 | { |
---|
| 15 | ::MPI_Status *mpi_status = static_cast< ::MPI_Status* >(status->mpi_status); |
---|
| 16 | ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), flag, mpi_status); |
---|
| 17 | |
---|
| 18 | status->mpi_status = mpi_status; |
---|
| 19 | status->ep_src = src; |
---|
| 20 | status->ep_tag = tag; |
---|
| 21 | return 0; |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | Debug("calling MPI_Iprobe EP\n"); |
---|
| 25 | |
---|
| 26 | Message_Check(comm); |
---|
| 27 | |
---|
| 28 | #pragma omp flush |
---|
| 29 | |
---|
| 30 | #pragma omp critical (_query) |
---|
| 31 | if(!comm.ep_comm_ptr->message_queue->empty()) |
---|
| 32 | { |
---|
| 33 | for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it) |
---|
| 34 | { |
---|
| 35 | bool src_matched = src<0? true: it->ep_src == src; |
---|
| 36 | bool tag_matched = tag<0? true: it->ep_tag == tag; |
---|
| 37 | |
---|
| 38 | if(src_matched && tag_matched) |
---|
| 39 | { |
---|
| 40 | Debug("find message\n"); |
---|
| 41 | *flag = true; |
---|
| 42 | |
---|
| 43 | ::MPI_Status mpi_status = *(static_cast< ::MPI_Status *>(it->mpi_status)); |
---|
| 44 | |
---|
| 45 | status->mpi_status = new ::MPI_Status(mpi_status); |
---|
| 46 | status->ep_src = it->ep_src; |
---|
| 47 | status->ep_tag = it->ep_tag; |
---|
| 48 | |
---|
| 49 | break; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | return 0; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | int MPI_Improbe(int src, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status) |
---|
| 61 | { |
---|
| 62 | *flag = false; |
---|
| 63 | if(!comm.is_ep) |
---|
| 64 | { |
---|
| 65 | Debug("calling MPI_Improbe MPI\n"); |
---|
| 66 | |
---|
| 67 | ::MPI_Status mpi_status; |
---|
| 68 | ::MPI_Message mpi_message; |
---|
| 69 | |
---|
| 70 | #ifdef _openmpi |
---|
| 71 | #pragma omp critical (_mpi_call) |
---|
| 72 | { |
---|
| 73 | ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), flag, &mpi_status); |
---|
| 74 | if(*flag) |
---|
| 75 | { |
---|
| 76 | ::MPI_Mprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), &mpi_message, &mpi_status); |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | #elif _intelmpi |
---|
| 80 | ::MPI_Improbe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), flag, &mpi_message, &mpi_status); |
---|
| 81 | #endif |
---|
| 82 | |
---|
| 83 | status->mpi_status = new ::MPI_Status(mpi_status); |
---|
| 84 | status->ep_src = src; |
---|
| 85 | status->ep_tag = tag; |
---|
| 86 | |
---|
| 87 | message->mpi_message = new ::MPI_Message; |
---|
| 88 | *(static_cast< ::MPI_Message*>(message->mpi_message)) = mpi_message; |
---|
| 89 | message->ep_src = src; |
---|
| 90 | message->ep_tag = tag; |
---|
| 91 | return 0; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | //Message_Check(comm); |
---|
| 96 | |
---|
| 97 | #pragma omp flush |
---|
| 98 | |
---|
| 99 | #pragma omp critical (_query) |
---|
| 100 | if(! comm.ep_comm_ptr->message_queue->empty()) |
---|
| 101 | { |
---|
| 102 | for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it) |
---|
| 103 | { |
---|
| 104 | bool src_matched = src<0? true: it->ep_src == src; |
---|
| 105 | bool tag_matched = tag<0? true: it->ep_tag == tag; |
---|
| 106 | |
---|
| 107 | if(src_matched && tag_matched) |
---|
| 108 | { |
---|
| 109 | *flag = true; |
---|
| 110 | |
---|
| 111 | ::MPI_Status mpi_status; |
---|
| 112 | mpi_status = *(static_cast< ::MPI_Status *>(it->mpi_status)); |
---|
| 113 | |
---|
| 114 | status->mpi_status = new ::MPI_Status(mpi_status); |
---|
| 115 | status->ep_src = it->ep_src; |
---|
| 116 | status->ep_tag = it->ep_tag; |
---|
| 117 | |
---|
| 118 | message->mpi_message = it->mpi_message; |
---|
| 119 | message->ep_tag = it->ep_tag; |
---|
| 120 | message->ep_src = it->ep_src; |
---|
| 121 | |
---|
| 122 | #pragma omp critical (_query2) |
---|
| 123 | { |
---|
| 124 | delete it->mpi_status; |
---|
| 125 | comm.ep_comm_ptr->message_queue->erase(it); |
---|
| 126 | #pragma omp flush |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | break; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | } |
---|
| 137 | |
---|