OPwrite.C
Go to the documentation of this file.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 #include "mpi.h"
00031
00032 #include "OPstream.H"
00033
00034
00035
00036
00038 Foam::DynamicList<MPI_Request> OPstream_outstandingRequests_;
00040
00041
00042
00043 Foam::OPstream::~OPstream()
00044 {
00045 if
00046 (
00047 !write
00048 (
00049 commsType_,
00050 toProcNo_,
00051 buf_.begin(),
00052 bufPosition_
00053 )
00054 )
00055 {
00056 FatalErrorIn("OPstream::~OPstream()")
00057 << "MPI_Bsend cannot send outgoing message"
00058 << Foam::abort(FatalError);
00059 }
00060 }
00061
00062
00063
00064
00065 bool Foam::OPstream::write
00066 (
00067 const commsTypes commsType,
00068 const int toProcNo,
00069 const char* buf,
00070 const std::streamsize bufSize
00071 )
00072 {
00073 bool transferFailed = true;
00074
00075 if (commsType == blocking)
00076 {
00077 transferFailed = MPI_Bsend
00078 (
00079 const_cast<char*>(buf),
00080 bufSize,
00081 MPI_PACKED,
00082 procID(toProcNo),
00083 msgType(),
00084 MPI_COMM_WORLD
00085 );
00086 }
00087 else if (commsType == scheduled)
00088 {
00089 transferFailed = MPI_Send
00090 (
00091 const_cast<char*>(buf),
00092 bufSize,
00093 MPI_PACKED,
00094 procID(toProcNo),
00095 msgType(),
00096 MPI_COMM_WORLD
00097 );
00098 }
00099 else if (commsType == nonBlocking)
00100 {
00101 MPI_Request request;
00102
00103 transferFailed = MPI_Isend
00104 (
00105 const_cast<char*>(buf),
00106 bufSize,
00107 MPI_PACKED,
00108 procID(toProcNo),
00109 msgType(),
00110 MPI_COMM_WORLD,
00111 &request
00112 );
00113
00114 OPstream_outstandingRequests_.append(request);
00115 }
00116 else
00117 {
00118 FatalErrorIn
00119 (
00120 "OPstream::write"
00121 "(const int fromProcNo, char* buf, std::streamsize bufSize)"
00122 ) << "Unsupported communications type " << commsType
00123 << Foam::abort(FatalError);
00124 }
00125
00126 return !transferFailed;
00127 }
00128
00129
00130 void Foam::OPstream::waitRequests()
00131 {
00132 if (OPstream_outstandingRequests_.size())
00133 {
00134 if
00135 (
00136 MPI_Waitall
00137 (
00138 OPstream_outstandingRequests_.size(),
00139 OPstream_outstandingRequests_.begin(),
00140 MPI_STATUSES_IGNORE
00141 )
00142 )
00143 {
00144 FatalErrorIn
00145 (
00146 "OPstream::waitRequests()"
00147 ) << "MPI_Waitall returned with error" << Foam::endl;
00148 }
00149
00150 OPstream_outstandingRequests_.clear();
00151 }
00152 }
00153
00154
00155 bool Foam::OPstream::finishedRequest(const label i)
00156 {
00157 if (i >= OPstream_outstandingRequests_.size())
00158 {
00159 FatalErrorIn
00160 (
00161 "OPstream::finishedRequest(const label)"
00162 ) << "There are " << OPstream_outstandingRequests_.size()
00163 << " outstanding send requests and you are asking for i=" << i
00164 << nl
00165 << "Maybe you are mixing blocking/non-blocking comms?"
00166 << Foam::abort(FatalError);
00167 }
00168
00169 int flag;
00170 MPI_Test(&OPstream_outstandingRequests_[i], &flag, MPI_STATUS_IGNORE);
00171
00172 return flag != 0;
00173 }
00174
00175
00176
00177
00178
Copyright © 2000-2009 OpenCFD Ltd