[591] | 1 | #include "xios_spl.hpp" |
---|
[300] | 2 | #include "exception.hpp" |
---|
[380] | 3 | #include "log.hpp" |
---|
[300] | 4 | #include "buffer_out.hpp" |
---|
| 5 | #include "buffer_client.hpp" |
---|
[317] | 6 | #include "cxios.hpp" |
---|
[382] | 7 | #include "mpi.hpp" |
---|
[347] | 8 | #include "tracer.hpp" |
---|
[300] | 9 | |
---|
[1328] | 10 | |
---|
| 11 | using namespace ep_lib; |
---|
| 12 | |
---|
[335] | 13 | namespace xios |
---|
[300] | 14 | { |
---|
[732] | 15 | size_t CClientBuffer::maxRequestSize = 0; |
---|
[509] | 16 | |
---|
[1520] | 17 | CClientBuffer::CClientBuffer(MPI_Comm interComm, int serverRank, StdSize bufferSize, StdSize estimatedMaxEventSize, StdSize maxBufferedEvents): |
---|
| 18 | interComm(interComm) |
---|
| 19 | , serverRank(serverRank) |
---|
[917] | 20 | , bufferSize(bufferSize) |
---|
[1205] | 21 | , estimatedMaxEventSize(estimatedMaxEventSize) |
---|
| 22 | , maxEventSize(0) |
---|
[917] | 23 | , current(0) |
---|
| 24 | , count(0) |
---|
| 25 | , bufferedEvents(0) |
---|
| 26 | , maxBufferedEvents(maxBufferedEvents) |
---|
| 27 | , pending(false) |
---|
[300] | 28 | { |
---|
[732] | 29 | buffer[0] = new char[bufferSize]; // transform it with MPI_ALLOC_MEM later |
---|
| 30 | buffer[1] = new char[bufferSize]; |
---|
| 31 | retBuffer = new CBufferOut(buffer[current], bufferSize); |
---|
[1342] | 32 | #pragma omp critical (_output) |
---|
| 33 | info(10) << "CClientBuffer: allocated 2 x " << bufferSize << " bytes for server " << serverRank << " with a maximum of " << maxBufferedEvents << " buffered events" << endl; |
---|
[300] | 34 | } |
---|
[509] | 35 | |
---|
[300] | 36 | CClientBuffer::~CClientBuffer() |
---|
| 37 | { |
---|
[732] | 38 | delete [] buffer[0]; |
---|
| 39 | delete [] buffer[1]; |
---|
| 40 | delete retBuffer; |
---|
[300] | 41 | } |
---|
[509] | 42 | |
---|
[1460] | 43 | StdSize CClientBuffer::remain(void) |
---|
[300] | 44 | { |
---|
[732] | 45 | return bufferSize - count; |
---|
[300] | 46 | } |
---|
[509] | 47 | |
---|
[1460] | 48 | bool CClientBuffer::isBufferFree(StdSize size) |
---|
[300] | 49 | { |
---|
[732] | 50 | if (size > bufferSize) |
---|
[1460] | 51 | ERROR("bool CClientBuffer::isBufferFree(StdSize size)", |
---|
[732] | 52 | << "The requested size (" << size << " bytes) is too big to fit the buffer (" << bufferSize << " bytes), please increase the client buffer size." << endl); |
---|
[509] | 53 | |
---|
[1205] | 54 | if (size > maxEventSize) |
---|
| 55 | { |
---|
| 56 | maxEventSize = size; |
---|
| 57 | |
---|
| 58 | if (size > estimatedMaxEventSize) |
---|
| 59 | error(0) << "WARNING: Unexpected event of size " << size << " for server " << serverRank |
---|
| 60 | << " (estimated max event size = " << estimatedMaxEventSize << ")" << std::endl; |
---|
| 61 | |
---|
| 62 | if (size > maxRequestSize) maxRequestSize = size; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
[917] | 66 | return (size <= remain() && bufferedEvents < maxBufferedEvents); |
---|
[300] | 67 | } |
---|
[509] | 68 | |
---|
| 69 | |
---|
[1460] | 70 | CBufferOut* CClientBuffer::getBuffer(StdSize size) |
---|
[300] | 71 | { |
---|
[732] | 72 | if (size <= remain()) |
---|
[300] | 73 | { |
---|
[732] | 74 | retBuffer->realloc(buffer[current] + count, size); |
---|
| 75 | count += size; |
---|
[917] | 76 | bufferedEvents++; |
---|
[732] | 77 | return retBuffer; |
---|
[300] | 78 | } |
---|
| 79 | else |
---|
| 80 | { |
---|
[1460] | 81 | ERROR("CBufferOut* CClientBuffer::getBuffer(StdSize size)", |
---|
[732] | 82 | << "Not enough space in buffer, this should not have happened..."); |
---|
| 83 | return NULL; |
---|
[300] | 84 | } |
---|
[509] | 85 | } |
---|
| 86 | |
---|
[300] | 87 | bool CClientBuffer::checkBuffer(void) |
---|
| 88 | { |
---|
[732] | 89 | MPI_Status status; |
---|
| 90 | int flag; |
---|
[509] | 91 | |
---|
[300] | 92 | if (pending) |
---|
| 93 | { |
---|
[732] | 94 | traceOff(); |
---|
| 95 | MPI_Test(&request, &flag, &status); |
---|
| 96 | traceOn(); |
---|
| 97 | if (flag == true) pending = false; |
---|
[300] | 98 | } |
---|
| 99 | |
---|
| 100 | if (!pending) |
---|
| 101 | { |
---|
[732] | 102 | if (count > 0) |
---|
[300] | 103 | { |
---|
[732] | 104 | MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request); |
---|
| 105 | pending = true; |
---|
| 106 | if (current == 1) current = 0; |
---|
| 107 | else current = 1; |
---|
| 108 | count = 0; |
---|
[917] | 109 | bufferedEvents = 0; |
---|
[300] | 110 | } |
---|
| 111 | } |
---|
[732] | 112 | |
---|
| 113 | return pending; |
---|
[300] | 114 | } |
---|
[509] | 115 | |
---|
[300] | 116 | bool CClientBuffer::hasPendingRequest(void) |
---|
| 117 | { |
---|
[732] | 118 | return (pending || count > 0); |
---|
[300] | 119 | } |
---|
[509] | 120 | } |
---|