libMesh::Parallel::Request Class Reference

#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_post_wait_work (PostWaitWork *work)
 

Private Attributes

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

Detailed Description

Encapsulates the MPI_Request

Definition at line 395 of file parallel.h.

Constructor & Destructor Documentation

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

Definition at line 626 of file parallel_implementation.h.

626  :
627 #ifdef LIBMESH_HAVE_MPI
628  _request(MPI_REQUEST_NULL),
629 #else
630  _request(),
631 #endif
632  post_wait_work(NULL)
633 {}
libMesh::Parallel::Request::Request ( const request r)
inline

Definition at line 635 of file parallel_implementation.h.

635  :
636  _request(r),
637  post_wait_work(NULL)
638 {}
libMesh::Parallel::Request::Request ( const Request other)
inline

Definition at line 640 of file parallel_implementation.h.

References post_wait_work.

640  :
641  _request(other._request),
642  post_wait_work(other.post_wait_work)
643 {
644  // operator= should behave like a shared pointer
645  if (post_wait_work)
646  post_wait_work->second++;
647 }
libMesh::Parallel::Request::~Request ( )
inline

Definition at line 693 of file parallel_implementation.h.

References cleanup().

693  {
694  this->cleanup();
695 }

Member Function Documentation

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

Definition at line 760 of file parallel_implementation.h.

References post_wait_work.

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

761 {
762  if (!post_wait_work)
763  post_wait_work = new
764  std::pair<std::vector <PostWaitWork* >, unsigned int>
765  (std::vector <PostWaitWork* >(), 1);
766  post_wait_work->first.push_back(work);
767 }
void libMesh::Parallel::Request::cleanup ( )
inline

Definition at line 649 of file parallel_implementation.h.

References libMesh::libmesh_assert(), and post_wait_work.

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

650 {
651  if (post_wait_work)
652  {
653  // Decrement the use count
654  post_wait_work->second--;
655 
656  if (!post_wait_work->second)
657  {
658 #ifdef DEBUG
659  // If we're done using this request, then we'd better have
660  // done the work we waited for
661  for (std::vector<PostWaitWork*>::iterator i =
662  post_wait_work->first.begin();
663  i != post_wait_work->first.end(); ++i)
664  libmesh_assert(!(*i));
665 #endif
666  delete post_wait_work;
667  post_wait_work = NULL;
668  }
669  }
670 }
request* libMesh::Parallel::Request::get ( )
inline

Definition at line 412 of file parallel.h.

References _request.

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

412 { return &_request; }
const request* libMesh::Parallel::Request::get ( ) const
inline

Definition at line 414 of file parallel.h.

References _request.

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

Definition at line 672 of file parallel_implementation.h.

References _request, cleanup(), and post_wait_work.

673 {
674  this->cleanup();
675  _request = other._request;
676  post_wait_work = other.post_wait_work;
677 
678  // operator= should behave like a shared pointer
679  if (post_wait_work)
680  post_wait_work->second++;
681 
682  return *this;
683 }
Request & libMesh::Parallel::Request::operator= ( const request r)
inline

Definition at line 685 of file parallel_implementation.h.

References _request, cleanup(), and post_wait_work.

686 {
687  this->cleanup();
688  _request = r;
689  post_wait_work = NULL;
690  return *this;
691 }
bool libMesh::Parallel::Request::test ( )
inline

Definition at line 722 of file parallel_implementation.h.

References _request, and libMesh::libmesh_assert().

723 {
724 #ifdef LIBMESH_HAVE_MPI
725  int val=0;
726 
727  MPI_Test (&_request,
728  &val,
729  MPI_STATUS_IGNORE);
730  if (val)
731  {
732  libmesh_assert (_request == MPI_REQUEST_NULL);
733  libmesh_assert_equal_to (val, 1);
734  }
735 
736  return val;
737 #else
738  return true;
739 #endif
740 }
bool libMesh::Parallel::Request::test ( status status)
inline

Definition at line 743 of file parallel_implementation.h.

References _request.

744 {
745  int val=0;
746 
747  MPI_Test (&_request,
748  &val,
749  &stat);
750 
751  return val;
752 }
Status libMesh::Parallel::Request::wait ( )
inline

Definition at line 697 of file parallel_implementation.h.

References _request, libMesh::Parallel::Status::get(), libMesh::libmesh_assert(), post_wait_work, libMesh::START_LOG(), and libMesh::STOP_LOG().

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

698 {
699  START_LOG("wait()", "Parallel::Request");
700 
701  Status stat;
702 #ifdef LIBMESH_HAVE_MPI
703  MPI_Wait (&_request, stat.get());
704 #endif
705  if (post_wait_work)
706  for (std::vector<PostWaitWork*>::iterator i =
707  post_wait_work->first.begin();
708  i != post_wait_work->first.end(); ++i)
709  {
710  // The user should never try to give us NULL work or try
711  // to wait() twice.
712  libmesh_assert (*i);
713  (*i)->run();
714  delete (*i);
715  *i = NULL;
716  }
717 
718  STOP_LOG("wait()", "Parallel::Request");
719  return stat;
720 }

Member Data Documentation

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

Definition at line 425 of file parallel.h.

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

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

Definition at line 431 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:

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:33 UTC

Hosted By:
SourceForge.net Logo