libMesh
Public Member Functions | Private Attributes | List of all members
libMesh::Parallel::Request Class Reference

Encapsulates the MPI_Request. More...

#include <parallel.h>

Public Member Functions

 Request ()
 
 Request (const request &r)
 
 Request (const Request &other)
 
void cleanup ()
 
Requestoperator= (const Request &other)
 
Requestoperator= (const request &r)
 
 ~Request ()
 
requestget ()
 
const requestget () const
 
Status wait ()
 
bool test ()
 
bool test (status &status)
 
void add_prior_request (const Request &req)
 
void add_post_wait_work (PostWaitWork *work)
 

Private Attributes

request _request
 
UniquePtr< Request_prior_request
 
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
 

Detailed Description

Encapsulates the MPI_Request.

Definition at line 517 of file parallel.h.

Constructor & Destructor Documentation

libMesh::Parallel::Request::Request ( )

Definition at line 826 of file parallel_implementation.h.

Referenced by add_prior_request(), operator=(), and Request().

826  :
827 #ifdef LIBMESH_HAVE_MPI
828  _request(MPI_REQUEST_NULL),
829 #else
830  _request(),
831 #endif
833 {}
const class libmesh_nullptr_t libmesh_nullptr
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
Definition: parallel.h:559
libMesh::Parallel::Request::Request ( const request r)

Definition at line 835 of file parallel_implementation.h.

835  :
836  _request(r),
838 {}
const class libmesh_nullptr_t libmesh_nullptr
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
Definition: parallel.h:559
libMesh::Parallel::Request::Request ( const Request other)

Definition at line 840 of file parallel_implementation.h.

References _prior_request, post_wait_work, and Request().

840  :
841  _request(other._request),
842  post_wait_work(other.post_wait_work)
843 {
844  if (other._prior_request.get())
845  _prior_request = UniquePtr<Request>
846  (new Request(*other._prior_request.get()));
847 
848  // operator= should behave like a shared pointer
849  if (post_wait_work)
850  post_wait_work->second++;
851 }
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
Definition: parallel.h:559
UniquePtr< Request > _prior_request
Definition: parallel.h:553
libMesh::Parallel::Request::~Request ( )

Definition at line 901 of file parallel_implementation.h.

References cleanup().

901  {
902  this->cleanup();
903 }

Member Function Documentation

void libMesh::Parallel::Request::add_post_wait_work ( PostWaitWork work)

Definition at line 993 of file parallel_implementation.h.

References post_wait_work.

Referenced by libMesh::Parallel::Communicator::nonblocking_receive_packed_range(), libMesh::Parallel::Communicator::nonblocking_send_packed_range(), libMesh::Parallel::Communicator::receive(), libMesh::Parallel::Communicator::send(), and libMesh::Parallel::Communicator::send_packed_range().

994 {
995  if (!post_wait_work)
996  post_wait_work = new
997  std::pair<std::vector <PostWaitWork * >, unsigned int>
998  (std::vector <PostWaitWork * >(), 1);
999  post_wait_work->first.push_back(work);
1000 }
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
Definition: parallel.h:559
void libMesh::Parallel::Request::add_prior_request ( const Request req)

Definition at line 979 of file parallel_implementation.h.

References _prior_request, libMesh::libmesh_assert(), and Request().

Referenced by libMesh::Parallel::Communicator::send_packed_range().

980 {
981  // We're making a chain of prior requests, not a tree
982  libmesh_assert(!req._prior_request.get());
983 
984  Request * new_prior_req = new Request(req);
985 
986  // new_prior_req takes ownership of our existing _prior_request
987  new_prior_req->_prior_request.reset(this->_prior_request.release());
988 
989  // Our _prior_request now manages the new resource we just set up
990  this->_prior_request.reset(new_prior_req);
991 }
libmesh_assert(j)
UniquePtr< Request > _prior_request
Definition: parallel.h:553
void libMesh::Parallel::Request::cleanup ( )

Definition at line 853 of file parallel_implementation.h.

References libMesh::libmesh_assert(), libmesh_nullptr, and post_wait_work.

Referenced by operator=(), and ~Request().

854 {
855  if (post_wait_work)
856  {
857  // Decrement the use count
858  post_wait_work->second--;
859 
860  if (!post_wait_work->second)
861  {
862 #ifdef DEBUG
863  // If we're done using this request, then we'd better have
864  // done the work we waited for
865  for (std::vector<PostWaitWork *>::iterator i =
866  post_wait_work->first.begin();
867  i != post_wait_work->first.end(); ++i)
868  libmesh_assert(!(*i));
869 #endif
870  delete post_wait_work;
872  }
873  }
874 }
const class libmesh_nullptr_t libmesh_nullptr
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
Definition: parallel.h:559
libmesh_assert(j)
request* libMesh::Parallel::Request::get ( )
const request* libMesh::Parallel::Request::get ( ) const

Definition at line 536 of file parallel.h.

References libMesh::Parallel::wait().

536 { return &_request; }
Request & libMesh::Parallel::Request::operator= ( const Request other)

Definition at line 876 of file parallel_implementation.h.

References _prior_request, _request, cleanup(), post_wait_work, and Request().

877 {
878  this->cleanup();
879  _request = other._request;
880  post_wait_work = other.post_wait_work;
881 
882  if (other._prior_request.get())
883  _prior_request = UniquePtr<Request>
884  (new Request(*other._prior_request.get()));
885 
886  // operator= should behave like a shared pointer
887  if (post_wait_work)
888  post_wait_work->second++;
889 
890  return *this;
891 }
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
Definition: parallel.h:559
UniquePtr< Request > _prior_request
Definition: parallel.h:553
Request & libMesh::Parallel::Request::operator= ( const request r)

Definition at line 893 of file parallel_implementation.h.

References _request, cleanup(), libmesh_nullptr, and post_wait_work.

894 {
895  this->cleanup();
896  _request = r;
898  return *this;
899 }
const class libmesh_nullptr_t libmesh_nullptr
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
Definition: parallel.h:559
bool libMesh::Parallel::Request::test ( )

Definition at line 933 of file parallel_implementation.h.

References _request, and libMesh::libmesh_assert().

Referenced by test().

934 {
935 #ifdef LIBMESH_HAVE_MPI
936  int val=0;
937 
938  // MPI_STATUS_IGNORE is from MPI-2; using it with some versions of
939  // MPICH may cause a crash:
940  // https://bugzilla.mcs.anl.gov/globus/show_bug.cgi?id=1798
941 #if MPI_VERSION > 1
942  libmesh_call_mpi
943  (MPI_Test (&_request, &val, MPI_STATUS_IGNORE));
944 #else
945  MPI_Status stat;
946  libmesh_call_mpi
947  (MPI_Test (&_request, &val, &stat));
948 #endif
949 
950  if (val)
951  {
952  libmesh_assert (_request == MPI_REQUEST_NULL);
953  libmesh_assert_equal_to (val, 1);
954  }
955 
956  return val;
957 #else
958  return true;
959 #endif
960 }
libmesh_assert(j)
bool libMesh::Parallel::Request::test ( status status)

Definition at line 963 of file parallel_implementation.h.

References _request, and test().

964 {
965  int val=0;
966 
967  libmesh_call_mpi
968  (MPI_Test (&_request, &val, &stat));
969 
970  return val;
971 }
Status libMesh::Parallel::Request::wait ( )

Definition at line 905 of file parallel_implementation.h.

References _prior_request, _request, libMesh::Parallel::Status::get(), libMesh::libmesh_assert(), libmesh_nullptr, and post_wait_work.

Referenced by libMesh::Parallel::Communicator::send_receive(), libMesh::Parallel::Communicator::send_receive_packed_range(), and libMesh::Parallel::wait().

906 {
907  LOG_SCOPE("wait()", "Parallel::Request");
908 
909  if (_prior_request.get())
910  _prior_request->wait();
911 
912  Status stat;
913 #ifdef LIBMESH_HAVE_MPI
914  libmesh_call_mpi
915  (MPI_Wait (&_request, stat.get()));
916 #endif
917  if (post_wait_work)
918  for (std::vector<PostWaitWork *>::iterator i =
919  post_wait_work->first.begin();
920  i != post_wait_work->first.end(); ++i)
921  {
922  // The user should never try to give us NULL work or try
923  // to wait() twice.
924  libmesh_assert (*i);
925  (*i)->run();
926  delete (*i);
927  *i = libmesh_nullptr;
928  }
929 
930  return stat;
931 }
const class libmesh_nullptr_t libmesh_nullptr
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
Definition: parallel.h:559
libmesh_assert(j)
UniquePtr< Request > _prior_request
Definition: parallel.h:553

Member Data Documentation

UniquePtr<Request> libMesh::Parallel::Request::_prior_request
private

Definition at line 553 of file parallel.h.

Referenced by add_prior_request(), operator=(), Request(), and wait().

request libMesh::Parallel::Request::_request
private

Definition at line 549 of file parallel.h.

Referenced by operator=(), test(), and wait().

std::pair<std::vector <PostWaitWork * >, unsigned int>* libMesh::Parallel::Request::post_wait_work
private

Definition at line 559 of file parallel.h.

Referenced by add_post_wait_work(), cleanup(), operator=(), Request(), and wait().


The documentation for this class was generated from the following files: